Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  clearModel and getValue error

    Posted 07/27/14 01:11 PM

    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


  • 2.  Re: clearModel and getValue error

    Posted 07/28/14 04:11 AM

    Originally posted by: PhilippeLaborie


    Hello Sergey,

    I don't think clearModel() is a documented method of IloCP in Java. I think the best is to use an instance of IloCP per model as you mention (you would have anyway to redefine a new model even if you would keep the same instance of IloCP). Did you notice that the creation/deletion of the IloCP instances take long compared with the model definition + resolution?

    Philippe

     


    #CPOptimizer
    #DecisionOptimization


  • 3.  Re: clearModel and getValue error

    Posted 07/28/14 04:32 AM

    Originally posted by: SergeyPolyakovskiy


    Hello Philippe,

    You are right. It is not documented. But I expected that it works like in CPLEX. Indeed, there was a story for cplex 12.2 when they had a memory leakage due to some internal math library. Now I have version 12.6 but still have a leakage when run great number of cplex routines in a row. One of solutions was not to create environment objects many times but use one and simply clear it. Now I have a kind of leakage in CP. Thus I decided to try it like I do for CPLEX.

    Sure, normally there should not be any problems with creating and releasing objects many times. But we had (and at least I still have them) for cplex. I will study the question regarding memory leakage further. But it seems like these two functions clearModel and getValue are in a conflict.

     

    Sergey


    #CPOptimizer
    #DecisionOptimization