Decision Optimization

Decision Optimization

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

 View Only
  • 1.  Elapsed time + Cost bound Question

    Posted Mon May 21, 2018 09:19 PM

    Originally posted by: stef44


    Hi there,

    I have two (sort of unrelated) questions :

     

    1.) How can you print the time elapsed whenever a feasible solution is found in the loop "while(cp.next())" ? I struggled to find an answer in the manual.

    2.) What is the best approach on adding a bound (upper bound for example) on the cost in CP Optimizer version 12.6.3? I am aware there are bounds in 12.8. but how can it be done in earlier versions? Any suggestion for a short cut is appreciated.

     

    Thanks


    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: Elapsed time + Cost bound Question

    Posted Tue May 22, 2018 03:02 AM

    Hi,

    1)

    have you tried

    cp.info.SolveTime

    ?

    Let me give you an example with 8 queens

     

        using CP;

        int Dim=8;
        dvar int queen[1..Dim] in 1..Dim;
        dvar int d1[1..Dim];
        dvar int d2[1..Dim];

        constraints {
        forall(ind in 1..Dim) {
        d1[ind] == queen[ind]+ind;
        d2[ind] == queen[ind]-ind;
        };

        allDifferent(queen);
        allDifferent(d1);
        allDifferent(d2);
        };

        main {
        thisOplModel.generate();
        cp.startNewSearch();
        cp.param.workers=1;
        cp.param.searchType = "depthFirst";
        var n=0;
        while (cp.next()) {
        n = n+1;
        write("Solution -> ");
        writeln(n);
        writeln("time : ",cp.info.SolveTime);

        }
        cp.endSearch();
        }

     

    2) Why don t you move to CPLEX 12.8 ?

    regards

    https://www.linkedin.com/pulse/puzzles-having-fun-useful-mathematics-alex-fleischer/


    #CPOptimizer
    #DecisionOptimization


  • 3.  Re: Elapsed time + Cost bound Question

    Posted Tue May 22, 2018 05:17 AM

    Originally posted by: Philippe_Refalo


    Hi stef44,

    You can simply add an upper bound on an objective by adding a constraint on the objective expression. For instance if you have the objective function min(x + y + z) you can add x + y + z <= UB. However you must be aware that adding such a bound on the objective can make the solution search les efficient because some indicators that guide the search become less precise in this case. You need to test. 

    Concerning 12.8 we have introduced the display of the lower bound found by CP Optimizer (assuming minimizaton) but it does not make the setup of an upper bound different.

    Regards,

    Philippe 

     


    #CPOptimizer
    #DecisionOptimization


  • 4.  Re: Elapsed time + Cost bound Question

    Posted Wed May 23, 2018 12:36 AM

    Originally posted by: stef44


    Hi Philippe,

     

    Thanks for your answer! Just a small follow-up question below:

    Can I add the bound on the constraint as a variable (and how) ? I would again like to see the changes of its LB and UB during while(cp.next()) by getting the max and min of the variable.

     

    Again, due to certain limit I'm working with 12.6 as I said.

    Any answer is appreciated, thanks!!


    #CPOptimizer
    #DecisionOptimization


  • 5.  Re: Elapsed time + Cost bound Question

    Posted Wed May 23, 2018 05:25 AM

    Originally posted by: Philippe_Refalo


    You can introduce a variable for the objective function by replacing minimize(x + y + z) by minimize (objVar) and objVar = x + y + z and add bounds to objVar in the model. You will not be able to add bounds to that variable during search unless you use your own search goal. 

    However, using CP Optimizer default search,  when cp.next() returns the objective variable will be fixed to the current objective value. Therefore you should use cp.getObjBound() for accessing the lower bound. Note also that the lower bound is displayed in the log as soon as it changes ( + New bound is XXXXX ).

    Philippe


    #CPOptimizer
    #DecisionOptimization


  • 6.  Re: Elapsed time + Cost bound Question

    Posted Wed May 23, 2018 03:56 PM

    Originally posted by: stef44


    Hi Philippe,

     

    Can you show me a small example?

    I am not using cp.getObjBound since as I mentioned I am working in version 12.6.

     

    Thanks again


    #CPOptimizer
    #DecisionOptimization


  • 7.  Re: Elapsed time + Cost bound Question

    Posted Fri May 25, 2018 02:57 AM

    Originally posted by: Philippe_Refalo


    You cannot have access to the objective bound in releases preceding 12.8. This is why we made it accessible with the functions I mentionned. So I don't see what example you would like to get. 

    Philippe


    #CPOptimizer
    #DecisionOptimization