Commit 26d59b7a authored by Gianluca Frison's avatar Gianluca Frison

added soltution to ex07

parent 4648a50a
|------------------|
| Solution of ex07 |
|------------------|
---
7.2
---
See tsp1.mod
reset;
set S ordered;
param n := card {S};
set SS := 1..(2^n - 2); # 1 to number of subtours
set POW {k in SS} := {i in S: (k div 2^(ord(i)-1)) mod 2 = 1}; # subtours
set LINKS := {i in S, j in S: ord(i) < ord(j)};
param cost {LINKS} >= 0;
var x {LINKS} binary;
minimize tot_cost: sum {(i,j) in LINKS} cost[i,j] * x[i,j];
s.t. tour: sum {(i,j) in LINKS} x[i,j] = n;
s.t. subtour_elim {k in SS : 3 <= card{POW[k]} <= n-1}:
sum {i in POW[k], j in POW[k]: (i,j) in LINKS} x[i,j] <= card{POW[k]}-1;
#data toy.dat;
#data 10city.dat;
#data 12city.dat;
#display SS;
#display POW;
#option solver cplex;
#solve;
#display x;
reset;
set S ordered;
param n := card {S};
set LINKS := {i in S, j in S: ord(i) < ord(j)};
param cost {LINKS} >= 0;
var x {LINKS} binary;
minimize tot_cost: sum {(i,j) in LINKS} cost[i,j] * x[i,j];
s.t. tour: sum {(i,j) in LINKS} x[i,j] = n;
s.t. max2 {i in S}:
sum {(i,j) in LINKS} x[i,j] + sum {(j,i) in LINKS} x[j,i] = 2;
# subtour elimination toy.dat
# subtour elimination 10city.dat
s.t. elim0: x['a','c'] + x['a','i'] + x['b','f'] + x['b','i'] + x['c','f'] <= 4;
s.t. elim1: x['a','b'] + x['a','i'] + x['b','f'] + x['c','f'] + x['c','i'] <= 4;
#data toy.dat;
data 10city.dat;
option solver cplex;
solve;
display x;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment