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

list n = []

gams_options

checkpoint

dictionary graph = {}

not_visited = list(n)

i = not_visited[0]

list sub_tour = [i]

value

end

## ◆ get_model_text()

 def tsp.get_model_text ( )

Definition at line 18 of file tsp.py.

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

## ◆ acut

Definition at line 93 of file tsp.py.

## ◆ cc

Definition at line 92 of file tsp.py.

## ◆ checkpoint

 tsp.checkpoint

Definition at line 113 of file tsp.py.

## ◆ cmax

 int tsp.cmax = 0

Definition at line 88 of file tsp.py.

## ◆ cp

Definition at line 107 of file tsp.py.

## ◆ curcut

 int tsp.curcut = 0

Definition at line 86 of file tsp.py.

## ◆ cut_data

Definition at line 91 of file tsp.py.

## ◆ cuts_per_round

 int tsp.cuts_per_round = 10

Definition at line 84 of file tsp.py.

## ◆ end

 tsp.end

Definition at line 161 of file tsp.py.

## ◆ gams_options

 tsp.gams_options

Definition at line 113 of file tsp.py.

## ◆ graph

 dictionary tsp.graph = {}

Definition at line 132 of file tsp.py.

## ◆ i

 dictionary tsp.i = not_visited[0]

Definition at line 140 of file tsp.py.

## ◆ mi

Definition at line 121 of file tsp.py.

## ◆ mi_acut

Definition at line 122 of file tsp.py.

## ◆ mi_rhscut

Definition at line 123 of file tsp.py.

## ◆ n

 list tsp.n = []

Definition at line 96 of file tsp.py.

## ◆ not_visited

 tsp.not_visited = list(n)

Definition at line 133 of file tsp.py.

## ◆ opt

Definition at line 108 of file tsp.py.

## ◆ rhscut

Definition at line 94 of file tsp.py.

## ◆ sub_tour

 list tsp.sub_tour = [i]

Definition at line 141 of file tsp.py.

## ◆ tsp_job

Definition at line 106 of file tsp.py.

## ◆ value

 tsp.value

Definition at line 149 of file tsp.py.

## ◆ ws

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

Definition at line 79 of file tsp.py.

def get_model_text()
Definition: warehouse.py:16
GAMS Development Corp.
GAMS Software GmbH

General Information and Sales
U.S. (+1) 202 342-0180
Europe: (+49) 221 949-9170