您好我正在进行整数编程。
我的作品现在直到:
Decision Variable:
Yi = 1 if the ambulances located in region i,
Yi = 0 otherwises
Objective: maximize the no. of resident that can be reached within 5
mins, Z =
Y1(43+45)+Y2(52+58)+Y3(45+58)+.......+Y8(52+45+58+58)
43 + 45是,没有。如果救护车位于Y1,则可在5分钟内到达Y1和Y5的居民。
Constraints: Y1+Y2+Y3+...+Y8 = 2 (only two locations)
然后,我不知道应该在约束中添加什么,目标似乎是错误的......
有人能帮帮我吗?谢谢你!
答案 0 :(得分:1)
如果你对普通编程没问题,这里有一个Python实现。
Y = [{}]*100
Y[1]={1:43, 5:45}
Y[2]={2:52, 8:58}
Y[3]={3:45, 6:58}
Y[4]={4:40, 5:45}
Y[5]={1:43, 5:45, 4:40, 8:58}
Y[6]={3:45, 6:58, 7:44, 8:58}
Y[7]={6:58, 7:44}
Y[8]={2:52, 5:45, 6:58, 8:58}
result = {'loc1':0, 'loc2': 0, 'total':0}
for i in range(1, 9):
for j in range (i + 1, 9):
Y[i * 10 + j] = Y[i].copy()
Y[i * 10 + j].update(Y[j])
total = 0
for key in Y[i * 10 + j]:
total += Y[i * 10 + j][key]
if total > result['total']:
result['loc1'] = i
result['loc2'] = j
result['total'] = total
print i, " ", j, " ", total
print result