Originally posted by: MJCplex
Hi everyone,
I have been using the forum for quite a while and found many great solutions to minor problems I have had - thanks for that already!
But right now I got stuck on a problem that I can't find a solution to - so maybe you can help me with my first post:
I have created a program with flow control using a main.mod and an additional loop.mod.
Each iteration the loop.mod is solved and the found solution is added to a set of penalized solutions for the next iteration (so that the solution is more unlikely to be found again in the next iteration).
Once a solution has been found a second time the program stops.
Everything is running as expected as long as I only try to read from the excel-file for the initial parameters.
Any attempts to write the found solutions to excel failed so far - the corresponding line in the .dat file is completly skipped.
I also added .postProcess() after each .generate() in the loop, but the SheetWrite-command is still ignored.
It does not even cause an error when I have the excel-file open while executing the program (which usually leads to the 'file is read-only' error).
As the model itself got quite big by now I try to bring it down to the essential part :
main.mod:
//---------- Solving the base model without penalties ----------------------
//Creating the model
var defBase = thisOplModel.modelDefinition;
var cplexBase = cplex;
var oplBase = new IloOplModel(defBase,cplexBase);
//Adding the data
var dataBase = thisOplModel.dataElements;
oplBase.addDataSource(dataBase);
//Generating the model
oplBase.generate();
if (cplexBase.solve())
{
oplBase.postProcess();
}
else
{
writeln("No Solution");
}
....
....
....
....
while(loopCondition == 0)
{
ObjValueStorage[loop] = cplexLoop.getObjValue();
simulationObjective[loop] = ObjValueStorage[loop]*(0.4*(Opl.rand(101)/100));
//add penalty from last iteration to new candidate solution
dataLoop.P.add(loop, simulationObjective[loop]);
//add new candidate solution from last iteration
for(var sNode = 1; sNode <= oplBase.maxNodes; sNode++)
{
for(var tNode = 1; tNode <= oplBase.maxNodes; tNode++)
{
dataLoop.H.add(loop, sNode, tNode, oplLoop.x[sNode][tNode].solutionValue);
}
}
dataLoop.r = loop;
oplLoop = new IloOplModel(defLoop,cplexLoop);
oplLoop.addDataSource(dataLoop);
oplLoop.generate();
if (cplexLoop.solve())
{
oplLoop.postProcess();
}
else
{
writeln("No Solution");
}
for(var iteration = 1; iteration <= loop; iteration++)
{
loopCondition = loopCondition + oplLoop.U[iteration].solutionValue;
}
}
.data:
SheetConnection Import("Import.xlsx");
SheetConnection Export("Export.xlsx");
//Sets / ranges
maxNodes from SheetRead(Import,"number_of_nodes");
//Parameters
w from SheetRead(Import,"Scaled_Flow"); //Flow originated at node i in N that is destined to node j in N.
f from SheetRead(Import,"Fixed_Costs"); //Fixed setup cost for location a hub at node k in N.
g from SheetRead(Import,"Link_Costs"); //Fixed cost for operating a hub link between hubs k in N and l in N.
c from SheetRead(Import,"Costs");
alpha from SheetRead(Import,"alpha"); //Economies of Scale discount factor for the flow transferred between hubs.
O from SheetRead(Import,"Origin");
D from SheetRead(Import,"Destination");
//--------------------------- exporting data
x to SheetWrite(Export,"SolutionValue");
Any ideas?
Thanks!
Best greetings,
MJ
#DecisionOptimization#OPLusingCPLEXOptimizer