Originally posted by: mrmag
Hello!
How ist it possible to pass an objective expression IloNumExpr into IlcConstraintI? The following code throght an exception in the the wrapper ILOCPCONSTRAINTWRAPPER2(MyConstraint):
Concert exception caught: IloExtractable 618 IloNumDivI has not been extracted by IloAlgorithm 00C4D
728
The code:
class MyConstraintI : public IlcConstraintI {
protected:
IlcInt _n;
IlcIntVar * _w;
IlcFloatExp * _obj;
public:
MyConstraintI(IloCP cp, IlcInt n, IlcIntVar * aa, IlcFloatExp * obj
) : IlcConstraintI(cp), _n(n), _w(aa), _obj(obj)
{
}
~MyConstraintI() {}
virtual void post();
virtual void propagate();
void varDemon();
};
void MyConstraintI::propagate () {
obj->setMax(...); // set bounds on the objective expressions
}
IlcConstraint MyConstraint(
IloCP cp, IlcInt n, IlcIntVar *a, IlcFloatExp * b
) {
return new (cp.getHeap()) MyConstraintI(cp, n, a, b);
}
ILOCPCONSTRAINTWRAPPER2(MyConstraint, cp,
IloIntVarArray, a,
IloNumExpr, obj
) {
for (IlcInt i = 0; i < a.getSize(); i++)
use(cp, a[i]);
//use(cp, obj);
IlcInt dim2 = a.getSize();
IlcIntVar * sa = new (cp.getHeap()) IlcIntVar [dim2];
for (IlcInt j = 0; j < dim2; j++)
sa[j] = cp.getIntVar(a[j]);
IlcFloatExp * _obj = new (cp.getHeap()) IlcFloatExp;
*_obj = cp.getFloatExp(obj);
return MyConstraint(cp, a.getSize(), sa, _obj);
}
int main() {
// initialize
IloNumExpr obj = ...;
model.add(IloMaximize(env, obj));
model.add(MyConstraint(env, ivar, obj));
// start solution
}
#CPOptimizer#DecisionOptimization