Originally posted by: salais
Hello everyone,
I am completely new to OPL and am having a little trouble implementing a TSPTW model according to the paper "An exact constraint logic programming algorithm for the traveling salesman problem with time windows" (Pesant et al.)
However I am getting an error in the model and I don't really know why. I have a strong background in programming but I can't seem to figure this out. Note that this is a work in progress. Any suggestions will be greatly appreciated.
The model:
code /*********************************************
* OPL 12.4 Model
* Author:
* Creation Date: 11.10.2012 at 10.35.01
*********************************************/
using CP;
// TSP Formulation alá Pesant et al.
int N = ...;
range Nodes = 1..N;
tuple edge {int i; int j;}
setof(edge) Edges = {<i,j> | i,j in Nodes};
int dist
Edges = ...;
range V = 2..N;
range Vo = 1..N;
range Vd = 2..(N+1);
range Vod = 1..(N+1);
// Dvar = list of successors
dvar int S
Nodes;
// MODEL (src: An exact constraint logic programming algorithm for the traveling salesman problem with time windows)
minimize sum (i in Vo) dist[<i, S
i]>;
// The above statement yields an error message of "cannot extract expression: dist[<i, S
i]>"
subject to
{
// (2)
forall (i,j in Vo : i != j)
S[i] != S[j];
// (3)
forall (i in Vo)
S[i] != i;
// (5)
forall (i in Vo)
1 <= S[i] <= (N+1);
};
execute
{
writeln("PostProc.");
writeln("Distances:");
for (var i in dist)
{
write(i);
write(": ");
writeln(dist[i]);
}
writeln("");
writeln("Successors:");
for (var j in S)
write(S[j]);
}
main
{
var opl = thisOplModel
var mod = opl.modelDefinition;
var dat = opl.dataElements;
var cp1 = new IloCP();
opl = new IloOplModel(mod,cp1);
opl.addDataSource(dat);
opl.generate();
// Solve problem with current constraints
if (!cp1.solve())
{
writeln("ERROR: could not solve");
status = 1;
opl.end();
}
opl.postProcess();
opl.end();
cp1.end();
}
[/code]
My data:
code /*********************************************
* OPL 12.4 Data
* Author:
* Creation Date: 11.10.2012 at 10.35.08
*********************************************/
N = 4;
dist = [
0, 1, 3, 2,
1, 0, 1, 2,
3, 1, 0, 1,
2, 2, 1, 0];
[/code]
#DecisionOptimization#OPLusingCPOptimizer