Originally posted by: Sr38
Hello, I am currently finding a way to solve this problem: Initially, the data we have is all possible routes in tuple form <A,B,C,D,cost> represent the characteristic of the route. ex. <1,1,0,0,4000> mean that node A, B are visited and cost of this route is 4000. After that we must select routes which minimize cost and each node should visited only one time. Currently, I cant find a way to write the 'visit each node only one time' constraint because ones need to screen through tuples route and find out which node has value =1. This is my current code (which has an error), I try to separate the loop but it some how show that it cant extract expression. Any suggestion will be very pleasant, thanks.
tuple route {
float A;
float B;
float C;
float D;
float cost;
}
{route} routes = {<1,0,0,0,106>,<0,1,0,0,68>,<0,0,1,0,34>,<0,0,0,1,50>,<1,1,0,0,116>,<1,1,0,0,116>,<1,0,1,0,116>,<1,0,1,0,116>,
<1,0,0,1,107>,<0,1,1,0,86>,<0,1,1,0,86>,<0,1,0,1,96>,<0,0,1,1,70>,<0,0,1,1,70>};
//decision variables
dvar boolean x[routes];
dvar boolean del[N][routes];
//Objective function
minimize sum(r in routes) x[r] * r.cost;
//constraints
subject to {
select_only_one_A:sum(r in routes: r.A == 1) x[r]*del[1][r] == 1;
select_only_one_B:sum(r in routes: r.B == 1) x[r]*del[2][r] == 1;
select_only_one_C:sum(r in routes: r.C == 1) x[r]*del[3][r] == 1;
select_only_one_D:sum(r in routes: r.D == 1) x[r]*del[4][r] == 1;
}
#CPLEXOptimizers#DecisionOptimization