tsp Namespace Reference

Functions

def get_model_text ()
 

Variables

 ws = GamsWorkspace(system_directory = sys.argv[1])
 
int cuts_per_round = 10
 
int curcut = 0
 
int cmax = 0
 
 cut_data = ws.add_database()
 
 cc = cut_data.add_set("cc", 1, "")
 
 acut = cut_data.add_parameter("acut", 3, "")
 
 rhscut = cut_data.add_parameter("rhscut", 1, "")
 
list n = []
 
 tsp_job = ws.add_job_from_string(get_model_text())
 
 cp = ws.add_checkpoint()
 
 opt = ws.add_options()
 
 gams_options
 
 checkpoint
 
 mi = cp.add_modelinstance()
 
 mi_acut = mi.sync_db.add_parameter("acut", 3, "")
 
 mi_rhscut = mi.sync_db.add_parameter("rhscut", 1, "")
 
dictionary graph = {}
 
 not_visited = list(n)
 
 i = not_visited[0]
 
list sub_tour = [i]
 
 value
 
 end
 

Function Documentation

◆ get_model_text()

def tsp.get_model_text ( )

Definition at line 20 of file tsp.py.

20def get_model_text():
21 return '''
22$Title Traveling Salesman Problem Instance with Python
23
24$Ontext
25
26The sub_tour elimination constraints are generated by a Python
27script. The MIP is solved over and over, but GAMS have to
28generate the model only after n cuts have been added.
29
30$Offtext
31
32$if not set tspdata $abort 'tspdata not set'
33
34set ii cities
35 i(ii) subset of cities
36alias (ii,jj),(i,j,k);
37
38parameter c(ii,jj) distance matrix;
39
40$gdxin %tspdata%
41$load ii c
42
43$if not set nrCities $set nrCities 20
44i(ii)$(ord(ii) < %nrCities%) = yes;
45
46variables x(ii,jj) decision variables - leg of trip
47 z objective variable;
48binary variable x; x.fx(ii,ii) = 0;
49
50equations objective total cost
51 rowsum(ii) leave each city only once
52 colsum(jj) arrive at each city only once;
53
54* the assignment problem is a relaxation of the TSP
55objective.. z =e= sum((i,j), c(i,j)*x(i,j));
56rowsum(i).. sum(j, x(i,j)) =e= 1;
57colsum(j).. sum(i, x(i,j)) =e= 1;
58
59$if not set cmax $set cmax 2
60set cut /c0*c%cmax%/;
61parameter
62 acut(cut,ii,jj) cut constraint matrix
63 rhscut(cut) cut constraint rhs;
64
65equation sscut(cut) sub_tour elimination cut;
66sscut(cut).. sum((i,j), Acut(cut,i,j)*x(i,j)) =l= RHScut(cut);
67
68set cc(cut) previous cuts; cc(cut) = no;
69$if set cutdata execute_load '%cutdata%', cc, Acut, RHScut;
70
71Acut(cut,i,j)$(not cc(cut)) = eps;
72RHScut(cut)$(not cc(cut)) = card(ii);
73
74model assign /all/;
75
76option optcr=0; '''
77
78
def get_model_text()
Definition: warehouse.py:18

Variable Documentation

◆ acut

tsp.acut = cut_data.add_parameter("acut", 3, "")

Definition at line 95 of file tsp.py.

◆ cc

tsp.cc = cut_data.add_set("cc", 1, "")

Definition at line 94 of file tsp.py.

◆ checkpoint

tsp.checkpoint

Definition at line 115 of file tsp.py.

◆ cmax

int tsp.cmax = 0

Definition at line 90 of file tsp.py.

◆ cp

tsp.cp = ws.add_checkpoint()

Definition at line 109 of file tsp.py.

◆ curcut

int tsp.curcut = 0

Definition at line 88 of file tsp.py.

◆ cut_data

tsp.cut_data = ws.add_database()

Definition at line 93 of file tsp.py.

◆ cuts_per_round

int tsp.cuts_per_round = 10

Definition at line 86 of file tsp.py.

◆ end

tsp.end

Definition at line 163 of file tsp.py.

◆ gams_options

tsp.gams_options

Definition at line 115 of file tsp.py.

◆ graph

dictionary tsp.graph = {}

Definition at line 134 of file tsp.py.

◆ i

dictionary tsp.i = not_visited[0]

Definition at line 142 of file tsp.py.

◆ mi

tsp.mi = cp.add_modelinstance()

Definition at line 123 of file tsp.py.

◆ mi_acut

tsp.mi_acut = mi.sync_db.add_parameter("acut", 3, "")

Definition at line 124 of file tsp.py.

◆ mi_rhscut

tsp.mi_rhscut = mi.sync_db.add_parameter("rhscut", 1, "")

Definition at line 125 of file tsp.py.

◆ n

list tsp.n = []

Definition at line 98 of file tsp.py.

◆ not_visited

tsp.not_visited = list(n)

Definition at line 135 of file tsp.py.

◆ opt

tsp.opt = ws.add_options()

Definition at line 110 of file tsp.py.

◆ rhscut

tsp.rhscut = cut_data.add_parameter("rhscut", 1, "")

Definition at line 96 of file tsp.py.

◆ sub_tour

list tsp.sub_tour = [i]

Definition at line 143 of file tsp.py.

◆ tsp_job

tsp.tsp_job = ws.add_job_from_string(get_model_text())

Definition at line 108 of file tsp.py.

◆ value

tsp.value

Definition at line 151 of file tsp.py.

◆ ws

tsp.ws = GamsWorkspace(system_directory = sys.argv[1])

Definition at line 81 of file tsp.py.