Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Why is the constructor being called three times?

    Posted 03/17/14 12:20 PM

    Originally posted by: Trust20092009_01


    I just want to better understand how does ILOCPCONSTRAINTWRAPPER work so I built this small example and I really do not understand why  the constructor being called three times?

    #include<ilcp/cpext.h>

    class IlcAloneI : public IlcConstraintI {
      public:
        IlcAloneI(IloCP cp, IlcIntVar x);
        virtual void propagate ();
        virtual void post();

    };
    IlcAloneI::IlcAloneI(IloCP cp,IlcIntVar x) : IlcConstraintI(cp){  std::cout << " ** THE CONSTRUCTOR IS CALLED ** " << std::endl;}

    void IlcAloneI::propagate () {}
    void IlcAloneI::post(){}

    IlcConstraint IlcAlone(IlcIntExp x){
      IloCP cp = x.getCP();
        return new (cp.getHeap()) IlcAloneI(cp, x);
    }

    ILOCPCONSTRAINTWRAPPER1(IloAlone, cp , IloIntVar, x)
    {
    use(cp,x);
    return IlcAlone(cp.getIntVar(x));
    }

    int main(int , const char * []){
      IloEnv env;
      try {
        IloModel model(env);
        IloIntVar x(env,0,1);
        model.add(IloAlone(env,x));
        IloCP cp(model);
        cp.setIntParameter(IloCP::Workers, 1);
        cp.solve();

      }
      catch (IloException& ex) {
        env.out() << "Error: " << ex << std::endl;
      }
      env.end();
      return 0;
    }

    -------------------------------

     ** THE CONSTRUCTOR IS CALLED **
     ** THE CONSTRUCTOR IS CALLED **
     ** THE CONSTRUCTOR IS CALLED **
     ! ----------------------------------------------------------------------------
     ! Satisfiability problem - 1 variable, 1 constraint
     ! Workers              = 1
     ! Initial process time : 0.00s (0.00s extraction + 0.00s propagation)
     !  . Log search space  : 1.0 (before), 1.0 (after)
     !  . Memory usage      : 467.8 kB (before), 467.8 kB (after)
     ! Using sequential search.
     ! ----------------------------------------------------------------------------
     !               Branches  Non-fixed            Branch decision
     *                      1 0.00s                   0  = _int0
     ! ----------------------------------------------------------------------------
     ! Search terminated normally, 1 solution found.
     ! Number of branches     : 1
     ! Number of fails        : 0
     ! Total memory usage     : 570.8 kB (531.8 kB CP Optimizer + 39.0 kB Concert)
     ! Time spent in solve    : 0.00s (0.00s engine + 0.00s extraction)
     ! Search speed (br. / s) : 100.0
     ! ----------------------------------------------------------------------------
     

    Best,

    S.S
     


    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: Why is the constructor being called three times?

    Posted 03/25/14 04:43 AM

    Originally posted by: Philippe_Refalo


    The wrapping code as well as the constructor of the IlcConstraitn can be called up to three times. This is normal. This is necessary to see the variables that are involved in a constraint in order to presolve or to compute conflict sets.  But you will not end up having 3 instances of the constraint, just one will be created for the search. 

    As a consequence of these multiple calls, the wrapping of constraints should be limited to usage variable declarations and to the construction of the IlcConstraint. 

    Regards 

    Philippe


    #CPOptimizer
    #DecisionOptimization


  • 3.  Re: Why is the constructor being called three times?

    Posted 03/25/14 07:40 AM

    Originally posted by: Trust20092009_01


    Thank you very much Philippe for your clear explanation.

    Best,

    S.S


    #CPOptimizer
    #DecisionOptimization