-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexercise4.gms
62 lines (49 loc) · 1.77 KB
/
exercise4.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
$onText
Laboratorio 2 - MOS
Ejercicio 4
Realizado por:
Juan Andrés Romero C - 202013449
Juan Sebastián Alegría - 202011282
$offText
Sets i 'Graph nodes' /i1*i7/
coords 'Coordinate dimensions' /coordX, coordY/
alias(j,i);
Table positions(i,coords)
coordX coordY
i1 20 6
i2 22 1
i3 9 2
i4 3 25
i5 21 10
i6 29 2
i7 14 12;
Parameters distance(i,j) 'Distances between nodes'
graph(i,j) 'Resulting graph of connections between the node set';
loop((i,j),
distance(i,j) = sqrt(sqr(positions(i,'coordX')-positions(j,'coordX')) + sqr(positions(i,'coordY')-positions(j,'coordY')));
if ((distance(i,j) <= 20 and distance(i,j) > 0),
graph(i,j) = distance(i,j);
else
graph(i,j) = 999;
);
);
Scalar sourceNode /4/;
Scalar destinationNode /6/;
Variables x(i,j) 'Indicates if the link i-j is selected or not'
z 'Objective function';
Binary Variable x;
Equations
targetFunc 'target function'
sourceNodeRestriction(i) 'source node'
destinationNodeRestriction(j) 'destination node'
intermediateNodeRestriction 'intermediate node';
targetFunc.. z =e= sum((i,j), graph(i,j)*x(i,j));
sourceNodeRestriction(i)$(ord(i) = sourceNode).. sum((j), x(i,j)) =e= 1;
destinationNodeRestriction(j)$(ord(j) = destinationNode).. sum((i), x(i,j)) =e= 1;
intermediateNodeRestriction(i)$(ord(i) <> sourceNode and ord(i) <> destinationNode).. sum((j), x(i,j)) - sum((j), x(j,i)) =e= 0;
Model Exercise4 /all/ ;
option mip=cplex
Solve Exercise4 using mip minimizing z;
Display graph;
Display x.l;
Display z.l;