Originally posted by: SergeyPolyakovskiy
Hi!
I have to run many small CP programs. Therefore, I would rather like to use clearModel function for a single created static IloCP object than create and delete many copies of it during computations. I call clearModel before creating and running my model. Then, I get the error message when accessing the decision variables via getValue().
ilog.concert.IloException: The referenced IloExtractable has not been extracted by the IloAlgorithm
at ilog.cp.cppimpl.cp_wrapJNI.IloCP_getValue__SWIG_2(Native Method)
at ilog.cp.cppimpl.IloCP.getValue(IloCP.java:261)
at ilog.cp.IloCP.getValue(IloCP.java:5992)
at ilog.cp.IloCP.getValue(IloCP.java:5975)
at Problem.FindPacking(Problem.java:468)
Indeed, CP Optimizer reports me about one found solution which I somehow cannot read. The error disappears once I remove clearModel and create new object every time to run the model. Moreover, the model works without this error even if I simply bring clearModel to comments.
cp.clearModel();
for (int i=0; i<itemSet.size(); i++) itemSet.get(i).SetVariable(cp,H,W);
for (int i=0; i<itemSet.size(); i++)
{
cp.add(cp.le(itemSet.get(i).x,W));
cp.add(cp.le(itemSet.get(i).y,H));
for (int j=0; j<itemSet.size(); j++)
{
if (i==j) continue;
IloConstraint[] overlapping = new IloConstraint[4];
overlapping[0]=cp.le(cp.sum(itemSet.get(i).x,itemSet.get(i).w), itemSet.get(j).x);
overlapping[1]=cp.le(cp.sum(itemSet.get(j).x,itemSet.get(j).w), itemSet.get(i).x);
overlapping[2]=cp.le(cp.sum(itemSet.get(i).y,itemSet.get(i).h), itemSet.get(j).y);
overlapping[3]=cp.le(cp.sum(itemSet.get(j).y,itemSet.get(j).h), itemSet.get(i).y);
cp.add(cp.or(overlapping));
}
}
if (cp.solve())
{
System.out.println("********");
for (int i=0; i<itemSet.size(); i++)
System.out.println("item "+itemSet.get(i).name+":\t(x,y)=("+
(int)cp.getValue(itemSet.get(i).x)+","+(int)cp.getValue(itemSet.get(i).y)+")"+":\t(w,h)=("+
itemSet.get(i).w+","+itemSet.get(i).h+")");
return true;
}
else
{
System.out.println("???????????/ Infeasible");
return false;
}
Does someone have any clue?
Sergey.
#CPOptimizer#DecisionOptimization