2015-05-04 71 views
-1

你好,我正在這個整數編程。如何解決這個整數編程?

我現在的工作,直到有:

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) 

然後,我不知道應該怎樣加入約束,目標似乎是錯誤的...

可能有人幫助我嗎?謝謝!

enter image description here

+1

你的問題對我來說很不清楚。 – moffeltje

+0

你打算只使用Excel還是一般編程? –

+0

@moffeltje請問爲什麼有這樣的說法? –

回答

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