Originally posted by: sds_rohit
Hi,
I am trying to execute the manual example on "Complex Custom Constraint".
I am getting an error while running the code, which I have attached with this message,
however I am not getting any compilation error.
Please suggest what I am doing wrong. How to correct it.
Thanks,
#include <ilcp/cp.h>
#include <vector>
#include <ilcp/cpext.h>
using std::vector;
class DiffConstraintI : public IlcConstraintI {
IlcIntVar _x, _y;
public:
DiffConstraintI(IloCP cp, IlcIntVar x, IlcIntVar y);
~DiffConstraintI(){}; // empty destructor
virtual void propagate ();
virtual void post();
};
DiffConstraintI::DiffConstraintI(IloCP cp,
IlcIntVar x,
IlcIntVar y)
: IlcConstraintI(cp), _x(x), _y(y) {}
void DiffConstraintI::propagate () {
if (_x.isFixed()) _y.removeValue(_x.getValue());
if (_y.isFixed()) _x.removeValue(_y.getValue());
}
void DiffConstraintI::post(){
_x.whenValue(this);
_y.whenValue(this);
}
IlcConstraint DiffConstraint(IlcIntExp x, IlcIntExp y){
IloCP cp = x.getCP();
return new (cp.getHeap()) DiffConstraintI(cp, x, y);
}
int main(int , const char * []){
IloEnv env;
try
{
IloIntVar x(env, 0, 10);
IloIntVar y(env, 0, 50,"y");
IloModel model(env);
model.add(x == y + 2);
IloCP cp(env);
cp.extract(model);
IlcIntVar cpx = cp.getIntVar(x);
IlcIntVar cpy = cp.getIntVar(y);
cp.add(DiffConstraint(cpx, cpy));
cp.out() << "The engine variable of " << x << " is " << cp.getIntVar(x) << std::endl;
cp.out() << "The engine variable of " << y << " is " << cp.getIntVar(y) << std::endl;
cp.end();
}
catch (IloException & ex)
{
env.out() << "Caught " << ex << std::endl;
}
env.end();
return 0;
}
#CPOptimizer#DecisionOptimization