Originally posted by: C.Magno
Hi everyone!
I'm coding a heuristic with exact local search.
In my main block script code I'm trying to access the value of a decision variable.
My model is in a separated file "LP-CA.mod".
This is the important segments of the code in this file:
...
dvar boolean ypc[P][C]; //decision variable that i'm trying access
...
minimize sum (d in Demands) xd[d]*d.bandwidth;
subject to{
//ypc is used in the constraints
forall(d in Demands)
sum(p in pat[d])
sum (c in channels[d])
ypc[p][c] + xd[d] == 1;
forall(e in Links)
forall(s in Slots)
sum (d in Demands)
sum(p in pat[d]: deltape[p][e] == 1 )
sum (c in channels[d]: gamacs[c][s] == 1)
deltape[p][e]*ypc[p][c]*gamacs[c][s] <= 1;
forall(d in Demands: selected[d] == 1)
xd[d] == 1;
}
As we can see. The ypc[ ][ ] is used in the constraints. In my main script block I'm checking the cplex status before access the ypc[ ][ ] variable. Like this:
main{
... //load model and data files...
function runHeuristic(opl){ //opl is an instance of IloOplModel
...
if(cplex.solve()){
if(cplex.status == 1) //Optimal solution is available.
writeln(opl.ypc); //Not returning a string like [[0,0,0,0,][0,0,1,0][1,0,0,0]]
objAux = cplex.getObjValue();
writeln("Obj. Value: " + objAux);
if(pertubationIdx >= 0){
localSearchCounter++;
}
}
...
}
...
}
But i'm getting as result just a string whit the name of the variable: "ypc".
Someone can help me with this issue?
Thanks in advanced.
Update 1:
When I try access element by element like this:
for(var p in opl2.P)
for(var c in opl2.C)
writeln(opl2.ypc[p][c]);
I get this string "[a IloNumVar]".
Update 2:
Since I'm using the ILOG IDE version 12.5, I must access the decision variable value like this:
opl2.ypc[p][c].solutionValue
But now, I'm getting a new problem.
I'm getting a error message saying that "has no available solution" and it's "impossible to process".
But how is it possible if the cplex status says "1" that means "Optimal solution is available"?
#DecisionOptimization#OPLusingCPLEXOptimizer