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