GUSEK中的TSP时间窗口

时间:2015-03-21 19:00:09

标签: ampl glpk

我正在尝试一个程序,我有9个地方可以访问,每个程序都有一个访问的时间窗口,[a,b]在程序中。每个城市的时间都是p,我有一个存款,我开始只有一辆车,我也需要完成存款。我不需要在同一天访问所有城市。 当这是我的时候,但程序sais“p”没有被定义。也许你可以帮助我并告诉我一些关于如何做的提示。

param n, integer, >= 3;
/* number of nodes */

param MAX_TIME := 600;
param MAX_X :=20;
param maxspeed;

set CITIES := 1..n;
/* set of nodes */


set ARCS, within CITIES cross CITIES;
/* set of arcs */

param DIST{(i,j) in ARCS};
/* distance from node i to node j */
param NEXTC, integer, >= 0;
/* Next city after i in the solution */
var x{(i,j) in ARCS}, binary;
/* x[i,j] = 1 means that the salesman goes from node i to node j */


param bigM := 5000;
var tar{CITIES};         /*arrival */
var tlv{CITIES};         /* departure */
var tea{CITIES} >= 0;    /* early arrival (arrival before the designated   time window) */
var tla{CITIES} >= 0;    /* late arrival (arrival after the designated time window) */
var ted{CITIES} >= 0;    /* early departure (departure before the designated time window) */
var tld{CITIES} >= 0;    /* late departure (departure after the designated time window) */

s.t. t1 {i in CITIES} : tlv[i] >= tar[i]; 
s.t. t2 {i in CITIES, j in CITIES} : tar[j] >= tlv[i] + p[i] +   DIST[i,j]/maxspeed - bigM*(1-x[i,j]);
s.t. t3 {i in CITIES} : tea[i] >= a[i] - tar[i];   /* early arrival */
s.t. t4 {i in CITIES} : tla[i] >= tar[i] - b[i];   /* late arrival */
s.t. t5 {i in CITIES} : ted[i] >= a[i] - tlv[i];   /* early departure */
s.t. t6 {i in CITIES} : tld[i] >= tlv[i] - b[i];   /* late departure */

set days := 1..5;
param root := 1;



var y{(i,j) in ARCS}, >= 0;
/* y[i,j] is a flow through arc (i,j) */


minimize total: sum{(i,j) in ARCS} DIST[i,j] * x[i,j];


solve;

printf "Optimal tour has length %d\n",
sum{(i,j) in ARCS} DIST[i,j] * x[i,j];
printf("From node   To node   Distance\n");
printf{(i,j) in ARCS: x[i,j]} "      %3d       %3d   %8g\n",
i, j, DIST[i,j];
data;

param n := 9;

param : ARCS : DIST :=
1  2   21
1  3   8
1  4   6
1  5   10
1  6   2
1  7   4
1  8   5
1  9   5
2  1   21
2  3   18
2  4   21
2  5   23
2  6   22
2  7   20
2  8   22
2  9   25
3  1   7
3  2   16
3  4   3
3  5   9
3  6   8
3  7   4
3  8   7
3  9   9
4  1   8
4  2   18
4  3   3
4  5   10
4  6   9
4  7   6
4  8   9
4  9   11
5  1   9
5  2   25
5  3   11
5  4   9
5  6   11
5  7   8
5  8   11
5  9   13
6  1   4
6  2   23
6  3   8
6  4   7
6  5   11
6  7   5
6  8   7
6  9   8
7  1   3
7  2   20
7  3   6
7  4   5
7  5   8
7  6   4
7  8   3
7  9   8
8  1   3
8  2   20
8  3   5
8  4   4
8  5   8
8  6   5
8  7   4
8  9   7
9  1   7
9  2   24
9  3   10
9  4   8
9  5   13
9  6   7
9  7   7
9  8   6;

param : a :=
  1  705
  2  420
  3  420
  4  420
  5  420
  6  420
  7  420
  8  420
  9  420;

param : b :=
  1  785
  2  795
  3  725
  4  500
  5  785
  6  785
  7  430
  8  785
  9  785;

param : p :=
  1  65
  2  55
  3  125
  4  65
  5  65
  6  65
  7  65
  8  65
  9  65;

end;

谢谢。

1 个答案:

答案 0 :(得分:0)

在约束t2中,您使用p[i]

tar[j] >= tlv[i] + p[i] + DIST[i,j]/maxspeed - bigM*(1-x[i,j]);

但未声明p。您应该声明它是一个参数或变量,具体取决于它是输入数据还是需要在优化过程中确定的内容。例如:

param p{CITIES};