Topic
2 replies Latest Post - ‏2013-06-13T13:04:46Z by mrmag
mrmag
mrmag
28 Posts
ACCEPTED ANSWER

Pinned topic IloNumExpr into IlcConstraintI

‏2013-06-12T11:04:22Z |
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
 
}
 
 
  • Philippe_Refalo
    Philippe_Refalo
    48 Posts
    ACCEPTED ANSWER

    Re: IloNumExpr into IlcConstraintI

    ‏2013-06-13T09:15:19Z  in response to mrmag

    The solution to this problem is the same as the one proposed in this post, that is to add a new variable for the objective function. In the latest release of CP Optimizer we have introduced presolve and there is no longer a one-to-one correspondance between Concert and engine objects

    Regards,

    Philippe