Originally posted by: SystemAdmin
[NDHU said:]
Hello everybody,
I have a problem with OPL script.
My model tries to average the daily workload and caculates the Vehicle Routing Problem based on the name list each day in a period wjich contains 30 days.
So I have 30 VRP calculation.
It solved correctly, but to the 30th day.
On the 30th day, it looks like can not terminated automatically until the system out of memory.
My code is the following:
main {
//solve the master model
thisOplModel.generate();
writeln("Solve the master.");
if(cplex.solve()){
writeln("obj = ",cplex.getObjValue());
thisOplModel.postProcess();
}
else{
writeln("failed");
}
Opl = thisOplModel;
//Prepare the submodel
var subSource = new IloOplModelSource("PeriodicVRP-sub.mod");
var subCplex = new IloCplex();
var subDef = new IloOplModelDefinition(subSource);
var subOpl = new IloOplModel(subDef, subCplex);
var subData = new IloOplDataSource("PeriodicVRP-sub.dat");
subOpl.addDataSource(subData);
//subOpl.generate();
//Prepare to translate
for(var t = 1; t <= thisOplModel.d; t++)<br /> {
subCplex.clearModel();
var subData0 = subOpl.dataElements;
writeln("\nStart Solving The ",t,"th ","Multi-Trip VRP ");
for( var i=1;i<=thisOplModel.nofcus;i++){<br /> subData0.as[i]=thisOplModel.v[i][t]
}
writeln("The ",t,"th costomer lists",subData0.as);
//count the amount of customers in specific day
var count=0;
for(i=1;i<=thisOplModel.nofcus;i++){<br /> if(subData0.as[i]>0)
count++
}
writeln("The number of customers = ",count-1,"\n");
//get the distance
//get the distance
for( i=1;i<=thisOplModel.nofn;i++){<br /> for( var j=1;j<=thisOplModel.nofcus;j++){<br /> if(subData0.as[i]==1&&subData0.as[j]!=1){
if(i==1){subData0.dis[i][j]=0;}
if(i!=1){subData0.dis[i][j]=thisOplModel.Dis[i][1];}
}
if(subData0.as[j]==1&&subData0.as[i]!=1){
if(j==1){subData0.dis[i][1]=0;}
if(j!=1){subData0.dis[i][j]=thisOplModel.Dis[1][j];}
}
if(subData0.as[i]==1&&subData0.as[j]==1){
subData0.dis[i][j]=thisOplModel.Dis[i][j];}
if(subData0.as[i]!=1&&subData0.as[j]!=1&&i>1){
if(i==j){subData0.dis[i][j]=thisOplModel.Dis[i][j]}
if(i!=j){subData0.dis[i][j]=0;}
}
}
}
writeln("The ",t,"th distance matrix =\n",subData0.dis)
//based on the as[i] to traslate the remainder nodes's demand equal to 0
for(i=1;i<=thisOplModel.nofcus;i++){<br /> if(subData0.as[i]==1){
subData0.demand[i]= thisOplModel.demand[i];
}
else
subData0.demand[i]=0;
}
writeln("The ",t,"th demand list=\n",subData0.demand);
//treat time
for(i=1;i<=thisOplModel.nofcus;i++){<br /> if(subData0.as[i]==1){
subData0.t[i]= thisOplModel.t[i];
}
else
subData0.t[i]=0;
}
writeln("The treatment time list on The ",t,"th Day\n" ,subData0.t);
//travel time
for( i=1;i<=thisOplModel.nofcus;i++){<br /> for( j=1;j<=thisOplModel.nofcus;j++){<br /> if(subData0.as[i]==1&&subData0.as[j]== 1){
subData0.travts[i][j]=thisOplModel.travtm[i][j];
}
else{
{subData0.travts[i][j]=0;}
}
}
}
writeln("The travel time on ",t,"th Day\n",subData0.travts)
subOpl.generate();
var subOpl0 = new IloOplModel(subDef, subCplex);
subOpl0.addDataSource(subData0);
var numofvehicle = subData0.nv;
var best = 9999999.0;
var curr = Infinity;
while(1)
{
var subOpl1 = new IloOplModel(subDef, subCplex);
var ofile = new IloOplOutputFile("solution.txt");
subOpl1.addDataSource(subData0);
subOpl1.generate();
writeln("Solve with number of vehicles = ",numofvehicle);
if(subCplex.solve()){
curr = subCplex.getObjValue();
writeln();
writeln("Obj = ", curr);
writeln("the solution is ",subOpl1.x)
ofile.writeln("Objective with",t,"th day =", curr);
ofile.writeln("x with",t,"th day =", subOpl1.x);
//ofile.close();
}
else{
writeln("No Solution");
}
if(curr-best<=0.0000001)break;<br /> if(curr == best )break;
if (curr != Infinity) {
best = curr;
break;
}
writeln("curr = ",curr);
writeln("best = ",best);
numofvehicle++;
subData0.nv = numofvehicle;
}
0;
writeln("subData0.nv = ",subData0.nv);
writeln("subData0.demand = ",subData0.demand);
could you help me or give me a hint?
Thanks a lot!
#DecisionOptimization#OPLusingCPLEXOptimizer