Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  call a simple function from an ILCGOAL()

    Posted 02/14/16 05:10 AM

    Originally posted by: valkiri


    Hello.

    I want to know if it's possible to call a simple function or recursive function from an ILCGOAL().

    I want to do something like this

     

    ILCGOAL0(StoreResult) {

    IlcInt n= function()
      return 0;
    }

     

    int function(){

    return 3;

    }

    Thanks.


    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: call a simple function from an ILCGOAL()

    Posted 02/15/16 06:06 AM

    Originally posted by: PhilippeLaborie


    Sure, you can call any function from inside a search goal.


    #CPOptimizer
    #DecisionOptimization


  • 3.  Re: call a simple function from an ILCGOAL()

    Posted 02/15/16 06:36 AM

    Originally posted by: valkiri


    Thank you for your reply.

    I want to ask another question about     cp.solve(IlcGoal,Ilctrue). When i use it  with optimization problem (with objective function) in an ILCGOALn() . it return only the first feasible solution. How to obtain the optimal solution in the case of optimization problem.

    Thanks.


    #CPOptimizer
    #DecisionOptimization


  • 4.  Re: call a simple function from an ILCGOAL()

    Posted 02/19/16 12:49 PM

    Originally posted by: ol


    Hello,

    function solve(g) called inside a goal will not optimize the objective function.

    What is your exact need?

    You may possibly use a non documented function (in 12.6.3):

                               IlcGoal IlcMinimizeGoal(IlcGoal g, IlcIntVar v, IlcInt s = 1)

    which minimizes a variable v given a goal g. Variable s is the step for increasing the bound.

    This function being non documented, it could be removed in a future release.

    A general solution, safer but heavier, is to create two IloCP, one for the internal optimizations, one for the global optimization.

    Regards,

    Olivier


    #CPOptimizer
    #DecisionOptimization


  • 5.  Re: call a simple function from an ILCGOAL()

    Posted 02/21/16 05:57 PM

    Originally posted by: valkiri


    Thanks ol for your reply.

    I need to achieve three things inside a goal.

    1-if i add a constraint with  cp.add(IlcConstraint), how can i remove it ?. Also internally i can use cp.startingPoint(IloSolution) , can i use it inside a goal ?.

    2-Instead to get the thirst solution with cp.solve(IlcGoal,IlcTrue), how can i optimize the objective function ?.

        You give an alternative withe IlcGoal IlcMinimizeGoal(IlcGoal g, IlcIntVar v, IlcInt s = 1).but i don't know how to use it .

    3-Can i control the search by making myself the backtracking after found a solution ?. I read that it's possible to use  "  IlcOr(goal1,goal2, label1) "    or     " cp.solve(IlcAnd(goal,IlcGoalFail(cp)) " to force a backtracking  but i don't know how to use them because the IBM users manual is not explicit. 

    My goal is to have most of control  on the search algorithm. 

    Thanks.

    Regards,

    Valkiri.


    #CPOptimizer
    #DecisionOptimization


  • 6.  Re: call a simple function from an ILCGOAL()

    Posted 02/22/16 06:08 AM

    Originally posted by: ol


    Hello,

    from what I understand, you want to implement your own search mechanism. You can do it by writing non determistic procedures, the way to do this in CP optimizer is to define "goals" IlcGoal. Goals can be combined with IlcAnd (left is executed first) and IlcOr (the non determinism primitive).

    your questions:

    > 1-if i add a constraint with  cp.add(IlcConstraint), how can i remove it ?.

    by backtracking

     

    > Also internally i can use cp.startingPoint(IloSolution) , can i use it inside a goal ?.

     cp.startingPoint(IloSolution) is a high level primitive to be used with the high level automatic search of CP Optimizer. You want to define your own search with low level primitives. You cannot merge different levels.

     

    > 2-Instead to get the thirst solution with cp.solve(IlcGoal,IlcTrue), how can i optimize the objective function ?.

    >    You give an alternative withe IlcGoal IlcMinimizeGoal(IlcGoal g, IlcIntVar v, IlcInt s = 1).but i don't know how to use it .

    it is a goal, You can just call it in a goal. It was not clear to me what you wanted. I think now that you only need to use IlcGoal. If this is not enough we may later return to this function, but probably it is better you focus first on how to express the search you have in mind in terms of and/or search.

    > 3-Can i control the search by making myself the backtracking after found a solution ?. I read that it's possible to use  "  IlcOr(goal1,goal2, label1) "    or     " cp.solve(IlcAnd(goal,IlcGoalFail(cp)) " to force a backtracking  but i don't know how to use them because the IBM users manual is not explicit. 

    Inside an IlcGoal, you can call

      void fail();

      void fail(IlcAny label);

    the first one forces the solver to backtrack to the most recent "open" IlcOr, the second one  forces  the solver to backtrack to the most recent "open" IlcOr with "label" as label (thus you can jump over open IlcOr)

    The goals and subgoals define the search tree the solver will explore. Basically you call cp.solve() only once with an IloGoal, this iloGoal is transformed into an IlcGoal (which involves IlcVariables instead of IloVariables). The IlcGoal combines subgoals with IlcAnd and IlcOr. You can always avoid calling internal cp.solve(IlcGoal) inside an IlcGoal, this may be convenient sometimes, but try to avoid it at first in order to fully understand the goal mechanism.  

     

    Regards,

    Olivier

     


    #CPOptimizer
    #DecisionOptimization


  • 7.  Re: call a simple function from an ILCGOAL()

    Posted 02/26/16 09:15 PM

    Originally posted by: valkiri


    Thanks ol.

    Can i have an example of use  of void fail() and void fail(IlcAny) to backtrack in order to remove a constraint added with cp.add(IlcConstraint)

    .

    Regards.


    #CPOptimizer
    #DecisionOptimization


  • 8.  Re: call a simple function from an ILCGOAL()

    Posted 02/29/16 06:11 AM

    Originally posted by: Petr Vilím


    Hello Valkiri,

    I think I partly answered in my response to your second question so please read it first.

    In a goal you can (1) return another goal to do next or (2) return NULL to indicate there's nothing more to do or (3) call fail.

    If you have a solution (all variables are assigned) then the right thing to do is (2). When the goal returns NULL then CP Optimizer first looks whether the goal isn't a part of some IloAnd, and if it is then it continues by the subsequent goal in the IloAnd. If it isn't then it means that a solution is found. CP Optimizer will automatically store the solution and add a constraint saying that we are now looking only for a better solution(s) (if there is some objective criteria). And then CP Optimizer calls fail in order to continue exploring the tree.

    To get to your question, if you do (3) and call fail then it is a signal for CP Optimizer that there is no way to extend this node to a solution. This node will never be explored again. CP Optimizer backtracks and tries to find a solution somewhere else. So you should normally not call fail in a search. It is a task of constraints to propagate and detect infeasibility (and therefore call fail). If you're doing infeasibility detection in the goal then you should probably move it into a constraint. There are some trickery cases when it makes sense to call fail from a goal. But considering your second question, I think you're asking about fail() in goal only because you think it will solve a very different problem.

    Petr


    #CPOptimizer
    #DecisionOptimization