Originally posted by: CynthiaLi
Hi, I'm a beginner. I was trying to solve a problem similar to column generating problem in OPL, then I found one of my model is not solved. There is no error, but the results are definitely wrong (0). I ran the models separately, then the results are correct.
Below is part of the code.
I checked the data assignment before FesiOpl.generate();, the data which the model should read is correct. But after the FesiCplex.solve(), all the results are wrong.
Could anyone tell me why? Thanks.
main {
var status = 0;
thisOplModel.generate();
// Retrieving model definition, engine and data elements from this OPL model
// to reuse them later
var FirstDef = thisOplModel.modelDefinition;
var FirstCplex = cplex;
var FirstData = thisOplModel.dataElements;
// Creating the first-stage problem
var FirstOpl = new IloOplModel(FirstDef, FirstCplex);
FirstOpl.addDataSource(FirstData);
FirstOpl.generate();
// Preparing feasibility-model source, definition and engine
var FesiSource = new IloOplModelSource("LShapedFeasibility.mod");
var FesiDef = new IloOplModelDefinition(FesiSource);
var FesiCplex = new IloCplex();
;
var best=-1000000;
var curr = 1000000;
var fBest=1;
while ( best < curr ) {
//step 1 and step 2
while( fBest> 0)
{ //step 1
writeln("Solve First Stage Problem.");
if ( FirstCplex.solve() ) {
FirstOpl.postProcess();
best = FirstOpl.theta.solutionValue;
} else {
writeln("No solution to first problem!");
FirstOpl.end();
break;
}
//step2
var Small=0;
var caseiter=1;
for (caseiter=1;caseiter<=FirstOpl.NbCase;caseiter++)
{
// Ceating the feasibility problem model
var FesiOpl = new IloOplModel(FesiDef,FesiCplex);
// Using data elements from the first model.
var FesiData = new IloOplDataElements();
FesiData.NbX = FirstOpl.NbX;
FesiData.NbY = FirstOpl.NbY;
FesiData.NbDual = FirstOpl.NbDual;
FesiData.CostY = FirstOpl.CostY;
FesiData.CoeffY = FirstOpl.CoeffY;
FesiData.T = FirstOpl.T;
FesiData.h=FirstOpl.temp;
for(var t=1;t<=FesiData.NbDual;t++) {
FesiData.h[t] = FirstOpl.h
caseiter[t];
}
FesiData.x=FirstOpl.x.solutionValue;
FesiOpl.addDataSource(FesiData);
FesiOpl.generate(); if (*FesiCplex.solve()*){
FesiOpl.postProcess();
fBest=FesiCplex.getObjValue();
writeln("fbest: ", fBest);
writeln("v1: ",FesiOpl.v1.solutionValue);
writeln("v2: ",FesiOpl.v2.solutionValue);
writeln("caseiter: ", caseiter);
var duals=FesiData.h;
#DecisionOptimization#OPLusingCPLEXOptimizer