Menu

[r118]: / disaster.py  Maximize  Restore  History

Download this file

40 lines (30 with data), 967 Bytes

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
#parameters
n = 32 #number of cities
D = None #distance matrix
MD = None #max relief distance
R = None #typical relief demand
M = None #maximum relief ability
F = None #fixed cost
C = None #variable cost
#index sets
N = xrange(n) #city index
#no city can provide relief for itself
K = [(i,j) for i in N for j in N if i!=j]
from pymprog import *
#choose city i iff x[i]==1
x = var(N, 'x', bool)
#relief capacity
v = var(N, 'v')
#city i provides for j iff y[i,j] == 1
y = var(K, 'y', bool)
#total cost
minimize(sum( F[i]*x[i] + C[i]*v[i] for i in N), 'cost')
#a relief center must have enough capacity
#only one disaster at a time
st(v[i] >= R[j]*y[i,j] for i,j in K)
#can provide relief capacity only if chosen
st(M[i]*x[i] >= v[i] for i in N)
#a city has only one primary relief city
st(sum(y[i,j] for i in N if i!=j) == 1 for j in N)
#the primary relief city must lie within a certain distance
st(sum(y[i,j]*D[i,j] for i in N if i!=j) <= MD[j] for j in N)