-
Notifications
You must be signed in to change notification settings - Fork 0
/
Exercise2.gms
73 lines (56 loc) · 1.43 KB
/
Exercise2.gms
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
$onText
Laboratorio 3 - MOS
Ejercicio 2
Realizado por:
Juan Andrés Romero C - 202013449
Juan Sebastián Alegría - 202011282
$offText
Sets i 'Towns' /i1*i6/
alias(i,j);
Parameter distance(i,j) 'Distance between towns';
distance('i1', 'i2') = 10;
distance('i1', 'i3') = 20;
distance('i1', 'i4') = 30;
distance('i1', 'i5') = 30;
distance('i1', 'i6') = 20;
distance('i2', 'i3') = 25;
distance('i2', 'i4') = 35;
distance('i2', 'i5') = 20;
distance('i2', 'i6') = 10;
distance('i3', 'i4') = 15;
distance('i3', 'i5') = 30;
distance('i3', 'i6') = 20;
distance('i4', 'i5') = 15;
distance('i4', 'i6') = 25;
distance('i5', 'i6') = 14;
* Since it's an undirected graph there are bidirectional connections
loop((i,j),
if (distance(i,j) ne 0,
distance(j,i) = distance(i,j)
);
);
loop((i,j),
if ((distance(i,j) le 15 and distance(i,j) ge 1) or (distance(j,i) le 15 and distance(j,i) ge 1),
distance(i,j) = 1;
else
distance(i,j) = 0;
);
);
loop((i,j),
if (distance(i,j) ne 0,
distance(j,i) = distance(i,j)
);
);
Display distance;
Variables x(i) 'Node selected'
z 'Target function';
Binary Variable x;
Equations targetFunc 'Target Function'
minZones(i) 'Fire department coverage constraint';
targetFunc.. z =e= sum(i, x(i));
minZones(i).. sum(j, x(j)*distance(i,j)) =g= 1;
Model exercise2 /all/;
option mip=cplex
Solve exercise2 using mip minimizing z;
Display x.l;
Display z.l;