Topic
  • 24 replies
  • Latest Post - ‏2014-08-30T00:05:59Z by mremn
mrmag
mrmag
28 Posts

Pinned topic User defined bounds in CP

‏2013-06-06T15:34:38Z |
Dear all!
 
How can I realize user defined bounds within the CP Optimizer?
 
I developed an optimization model within the CP Optimizer. Now I consider the possibility to integrate my bounds (my model is a minimization problem, so I have lower bounds) into the optimization process of the CP. My first idea was to make a new constraint - an inheritaged instance of the class IlcConstraintI. Then I implemented the propagate() procedure where I can calculate the bounds and compare it with the value of the best found solution. My questions are:
 
1. How is it possible to find out the objective value of the best found solution at the current time in the IlcConstraintI::propagate () routine?
2. Are there any other possibilities to integrate user defined lower bounds into CP?
 
  • Philippe_Refalo
    Philippe_Refalo
    50 Posts

    Re: User defined bounds in CP

    ‏2013-06-07T07:18:27Z  
    You integrated your lower bound the right way : by creating a user defined constraint. To get the upper bound on the objective you need to use
    a loop for performing search:
     
    cp.startNewSearch();
    while(cp.next()){
      // Store incumbent value
    }
     
    and to store the objective value each time a solution is found. You cannot use the bounds you observe on the objective variable or expression during automatic search because it may be relaxed sometimes and it can be different from the one of the best incumbent. 
     
    Regards,
     
    Philippe
  • mrmag
    mrmag
    28 Posts

    Re: User defined bounds in CP

    ‏2013-06-07T12:19:49Z  
    You integrated your lower bound the right way : by creating a user defined constraint. To get the upper bound on the objective you need to use
    a loop for performing search:
     
    cp.startNewSearch();
    while(cp.next()){
      // Store incumbent value
    }
     
    and to store the objective value each time a solution is found. You cannot use the bounds you observe on the objective variable or expression during automatic search because it may be relaxed sometimes and it can be different from the one of the best incumbent. 
     
    Regards,
     
    Philippe

    Philippe, thank you!

  • mrmag
    mrmag
    28 Posts

    Re: User defined bounds in CP

    ‏2013-06-11T10:04:35Z  
    You integrated your lower bound the right way : by creating a user defined constraint. To get the upper bound on the objective you need to use
    a loop for performing search:
     
    cp.startNewSearch();
    while(cp.next()){
      // Store incumbent value
    }
     
    and to store the objective value each time a solution is found. You cannot use the bounds you observe on the objective variable or expression during automatic search because it may be relaxed sometimes and it can be different from the one of the best incumbent. 
     
    Regards,
     
    Philippe
    I have one clarifying question.
     
    What is the right way to stop processing of the current node? In the propagation() procedure of my constraint I calculate the lower bound for the current node. And then I compare it with the incumbent and if the lower bound is greater than the incumbent then I run fail() procedure:
     
    if (lower_bound >= incumbent)
        getCP().fail();
     
    Is that right? For some instances I get an internal error. Sometimes the program crashes. Sometimes it works.
     
    The version of CPLEX is 12.5 without fix. The program is written in C++ with VS9.0.
     
  • GGR
    GGR
    62 Posts

    Re: User defined bounds in CP

    ‏2013-06-11T12:32:03Z  
    • mrmag
    • ‏2013-06-11T10:04:35Z
    I have one clarifying question.
     
    What is the right way to stop processing of the current node? In the propagation() procedure of my constraint I calculate the lower bound for the current node. And then I compare it with the incumbent and if the lower bound is greater than the incumbent then I run fail() procedure:
     
    if (lower_bound >= incumbent)
        getCP().fail();
     
    Is that right? For some instances I get an internal error. Sometimes the program crashes. Sometimes it works.
     
    The version of CPLEX is 12.5 without fix. The program is written in C++ with VS9.0.
     

    Hi

    CPO replay the actual incumbent before exiting when it must stop searching. For example when a solution is proven optimal. During this replay, your code is wrong.

    You have only the right to set the minimum of the objective term to the lower bound you found.

     

    You must add the objective in your model and the search will do the correct work. That is, during the optimization phase, the objective will be constrained to be strictly less than the one of the last incumbent and during replay to be equal to the incumbent.

    be obj the expression of the incumbent in function of the variables of the model.

    You add

    model.add(IloMinimize(env, obj));

    To the model.

    and your propagate member of the constraint will be

    class MyConstraint : public IlcConstraintI {

    IlcFloatExp _obj; // the objective

    /* ... */

    }

    void MyConstraintI::propagate() {

      IlcFloat lb = //compute a lower bound of the objective

    _obj.setMin(lb);

    /* ... */

    }

     

  • mrmag
    mrmag
    28 Posts

    Re: User defined bounds in CP

    ‏2013-06-11T14:13:16Z  
    • GGR
    • ‏2013-06-11T12:32:03Z

    Hi

    CPO replay the actual incumbent before exiting when it must stop searching. For example when a solution is proven optimal. During this replay, your code is wrong.

    You have only the right to set the minimum of the objective term to the lower bound you found.

     

    You must add the objective in your model and the search will do the correct work. That is, during the optimization phase, the objective will be constrained to be strictly less than the one of the last incumbent and during replay to be equal to the incumbent.

    be obj the expression of the incumbent in function of the variables of the model.

    You add

    model.add(IloMinimize(env, obj));

    To the model.

    and your propagate member of the constraint will be

    class MyConstraint : public IlcConstraintI {

    IlcFloatExp _obj; // the objective

    /* ... */

    }

    void MyConstraintI::propagate() {

      IlcFloat lb = //compute a lower bound of the objective

    _obj.setMin(lb);

    /* ... */

    }

     

    Hi GGR.
     
    Thank you for the prompt answer. I implemented the bounds in your way and CPO throws an exception. Here is a part of the code:
     
    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);
    }
     
    It throws the following exception:
    Concert exception caught: IloExtractable 296 IloNumDivI has not been extracted by IloAlgorithm 0
    F18
     
    It seems that the lower level of the CPO does not accept expressions. Is there any way to realize an objective expression on the Ilc level?
     
    Updated on 2013-06-11T15:49:41Z at 2013-06-11T15:49:41Z by mrmag
  • Philippe_Refalo
    Philippe_Refalo
    50 Posts

    Re: User defined bounds in CP

    ‏2013-06-12T15:10:57Z  
    • mrmag
    • ‏2013-06-11T14:13:16Z
    Hi GGR.
     
    Thank you for the prompt answer. I implemented the bounds in your way and CPO throws an exception. Here is a part of the code:
     
    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);
    }
     
    It throws the following exception:
    Concert exception caught: IloExtractable 296 IloNumDivI has not been extracted by IloAlgorithm 0
    F18
     
    It seems that the lower level of the CPO does not accept expressions. Is there any way to realize an objective expression on the Ilc level?
     

    With the latest version of CP Optimizer you don't have access to the underlying expressions of an IloNumExpr.  You need to introduce a new variable for the objective in your model, make it equal to the objective expression, declare the objective on this variable and pass it to your constraint. 

    Philippe

  • mrmag
    mrmag
    28 Posts

    Re: User defined bounds in CP

    ‏2013-06-13T12:41:23Z  

    With the latest version of CP Optimizer you don't have access to the underlying expressions of an IloNumExpr.  You need to introduce a new variable for the objective in your model, make it equal to the objective expression, declare the objective on this variable and pass it to your constraint. 

    Philippe

    Philippe, thank you!

  • Hosssein
    Hosssein
    26 Posts

    Re: User defined bounds in CP

    ‏2014-06-21T02:56:37Z  

    With the latest version of CP Optimizer you don't have access to the underlying expressions of an IloNumExpr.  You need to introduce a new variable for the objective in your model, make it equal to the objective expression, declare the objective on this variable and pass it to your constraint. 

    Philippe

    Hi Philippe,

    I have faced with the same problem. I want to pass the objective function to a user defined constraint. I do not know how I can present the objective function by an auxiliary variable as you said.

    My code in the main file is as follows.

     

    IlcFloatVar MyObjValue(env,0,1000000); // Auxilliary variable for the objective function

    IloNumExpr OBJECTIVE = IloNumExpr(env,0);             

    for(i = 0; i < BNumber_Positions; i++){

           OBJECTIVE += DataMatrix[W[i]]; //W is the array of variables

    }     

    model.add(IloMaximize(env, OBJECTIVE));

    model.add(MyObjValue==OBJECTIVE);

    model.add(IloCheckWhenBound(envvv,ALLVARIABLES,p,WORST_DELTA,BEST_DELTA,Combination,MyObjValue));

     

    I get error in model.add(MyObjValue==OBJECTIVE) because MyObjValue and OBJECTIVE are not consistent.

    The problem is that the objective expression takes float values and I cannot use IloNumVar for the declaration of MyObjValue. Could you please tell me how I can handle this issue?

     

    My constraint is as follows:

     

    typedefIloArray<IloNumArray> NumMatrix;

    typedefIloArray<NumMatrix>   Num3Matrix;

    classIlcCheckWhenBoundI : public IlcConstraintI {

    protected:

           IlcIntVarArray _x;

           IlcInt _a;

           IloNumArray _best_del;

           IloNumArray _worst_del;

           NumMatrix _comb;

           IlcFloatVar _obj;

    public:

           IlcCheckWhenBoundI(IloCP s, IlcIntVarArray x, IlcInt a, IloNumArray worst_del, IloNumArray best_del, NumMatrix comb, IlcFloatVar obj): IlcConstraintI(s), _x(x), _a(a), _worst_del(worst_del), _best_del(best_del), _comb(comb) , _obj(obj){}

           ~IlcCheckWhenBoundI() {}

           virtual void post();

           virtual void propagate() {}

           void varDemon(IlcIntVar v);

    };

    ILCCTDEMON1(RealizeVarBound, IlcCheckWhenBoundI, varDemon, IlcIntVar, v);

     

    voidIlcCheckWhenBoundI::post () {

           _x[_a].whenValue(RealizeVarBound(getCP(), this, _x[_a]));

    }

     

    voidIlcCheckWhenBoundI::varDemon (IlcIntVar v) {

           if (…){

                  _obj.setMax(Upperboundvalue);

    }

    }

     

    IlcConstraint IlcCheckWhenBound(IloCP s, IlcIntVarArray x, IlcInt a, IloNumArray worst_del, IloNumArray best_del,NumMatrix comb ,IlcFloatVar z) {

       return new (s.getHeap()) IlcCheckWhenBoundI(s, x, a, worst_del, best_del, comb , z);

    }

    ILOCPCONSTRAINTWRAPPER6(IloCheckWhenBound, cp, IloIntVarArray, _v, IlcInt, _a, IloNumArray, _worst_del, IloNumArray, _best_del, NumMatrix, _comb, IlcFloatVar , _z) {

           use(cp, _v);

    return IlcCheckWhenBound(cp, cp.getIntVarArray(_v), _a, _worst_del,_best_del, _comb ,_z);

    }

     

    Thanks

    Hossein

     

    Updated on 2014-06-21T05:21:24Z at 2014-06-21T05:21:24Z by Hosssein
  • Philippe_Refalo
    Philippe_Refalo
    50 Posts

    Re: User defined bounds in CP

    ‏2014-06-25T13:26:33Z  
    • Hosssein
    • ‏2014-06-21T02:56:37Z

    Hi Philippe,

    I have faced with the same problem. I want to pass the objective function to a user defined constraint. I do not know how I can present the objective function by an auxiliary variable as you said.

    My code in the main file is as follows.

     

    IlcFloatVar MyObjValue(env,0,1000000); // Auxilliary variable for the objective function

    IloNumExpr OBJECTIVE = IloNumExpr(env,0);             

    for(i = 0; i < BNumber_Positions; i++){

           OBJECTIVE += DataMatrix[W[i]]; //W is the array of variables

    }     

    model.add(IloMaximize(env, OBJECTIVE));

    model.add(MyObjValue==OBJECTIVE);

    model.add(IloCheckWhenBound(envvv,ALLVARIABLES,p,WORST_DELTA,BEST_DELTA,Combination,MyObjValue));

     

    I get error in model.add(MyObjValue==OBJECTIVE) because MyObjValue and OBJECTIVE are not consistent.

    The problem is that the objective expression takes float values and I cannot use IloNumVar for the declaration of MyObjValue. Could you please tell me how I can handle this issue?

     

    My constraint is as follows:

     

    typedefIloArray<IloNumArray> NumMatrix;

    typedefIloArray<NumMatrix>   Num3Matrix;

    classIlcCheckWhenBoundI : public IlcConstraintI {

    protected:

           IlcIntVarArray _x;

           IlcInt _a;

           IloNumArray _best_del;

           IloNumArray _worst_del;

           NumMatrix _comb;

           IlcFloatVar _obj;

    public:

           IlcCheckWhenBoundI(IloCP s, IlcIntVarArray x, IlcInt a, IloNumArray worst_del, IloNumArray best_del, NumMatrix comb, IlcFloatVar obj): IlcConstraintI(s), _x(x), _a(a), _worst_del(worst_del), _best_del(best_del), _comb(comb) , _obj(obj){}

           ~IlcCheckWhenBoundI() {}

           virtual void post();

           virtual void propagate() {}

           void varDemon(IlcIntVar v);

    };

    ILCCTDEMON1(RealizeVarBound, IlcCheckWhenBoundI, varDemon, IlcIntVar, v);

     

    voidIlcCheckWhenBoundI::post () {

           _x[_a].whenValue(RealizeVarBound(getCP(), this, _x[_a]));

    }

     

    voidIlcCheckWhenBoundI::varDemon (IlcIntVar v) {

           if (…){

                  _obj.setMax(Upperboundvalue);

    }

    }

     

    IlcConstraint IlcCheckWhenBound(IloCP s, IlcIntVarArray x, IlcInt a, IloNumArray worst_del, IloNumArray best_del,NumMatrix comb ,IlcFloatVar z) {

       return new (s.getHeap()) IlcCheckWhenBoundI(s, x, a, worst_del, best_del, comb , z);

    }

    ILOCPCONSTRAINTWRAPPER6(IloCheckWhenBound, cp, IloIntVarArray, _v, IlcInt, _a, IloNumArray, _worst_del, IloNumArray, _best_del, NumMatrix, _comb, IlcFloatVar , _z) {

           use(cp, _v);

    return IlcCheckWhenBound(cp, cp.getIntVarArray(_v), _a, _worst_del,_best_del, _comb ,_z);

    }

     

    Thanks

    Hossein

     

    Hi Hossein,

    There shouldn't be any problem using IloNumVar. Could you be give more information about the problem you encounter ?

    Your code should look like this:

    IloNumVar MyObjValue(env, 0, 1000000); // Auxilliary variable for the objective function
     
    IloNumExpr OBJECTIVE = IloNumExpr(env,0);             
    for(i = 0; i < BNumber_Positions; i++){
           OBJECTIVE += DataMatrix[W[i]]; //W is the array of variables
    }     
     
    IloModel model(env);
    model.add(MyObjValue == OBJECTIVE);
    model.add(IloMaximize(env, MyObjValue));
     

    Note that it is better to use the variable MyObjValue as the objective function so that any choice made on this variable will be visible from your custom constraint.

    And the constraint wrapper should be like this:

    ILOCPCONSTRAINTWRAPPER6(IloCheckWhenBound, cp, IloIntVarArray, _v, IlcInt, _a, IloNumArray, _worst_del, IloNumArray, _best_del, NumMatrix, _comb, IloNumVar, _z) {
           use(cp, _v);
           use(cp, _z);
           return IlcCheckWhenBound(cp, cp.getIntVarArray(_v), _a, _worst_del,_best_del, _comb ,cp.getFloatVar(_z));
    }

    Regards

    Philippe

  • Hosssein
    Hosssein
    26 Posts

    Re: User defined bounds in CP

    ‏2014-06-25T18:28:23Z  

    Hi Hossein,

    There shouldn't be any problem using IloNumVar. Could you be give more information about the problem you encounter ?

    Your code should look like this:

    IloNumVar MyObjValue(env, 0, 1000000); // Auxilliary variable for the objective function
     
    IloNumExpr OBJECTIVE = IloNumExpr(env,0);             
    for(i = 0; i < BNumber_Positions; i++){
           OBJECTIVE += DataMatrix[W[i]]; //W is the array of variables
    }     
     
    IloModel model(env);
    model.add(MyObjValue == OBJECTIVE);
    model.add(IloMaximize(env, MyObjValue));
     

    Note that it is better to use the variable MyObjValue as the objective function so that any choice made on this variable will be visible from your custom constraint.

    And the constraint wrapper should be like this:

    ILOCPCONSTRAINTWRAPPER6(IloCheckWhenBound, cp, IloIntVarArray, _v, IlcInt, _a, IloNumArray, _worst_del, IloNumArray, _best_del, NumMatrix, _comb, IloNumVar, _z) {
           use(cp, _v);
           use(cp, _z);
           return IlcCheckWhenBound(cp, cp.getIntVarArray(_v), _a, _worst_del,_best_del, _comb ,cp.getFloatVar(_z));
    }

    Regards

    Philippe

    The IlcConstraint code is as follows:

    typedef IloArray<IloNumArray> NumMatrix;

    typedef IloArray<NumMatrix>   Num3Matrix;

    class IlcCheckWhenBoundI : public IlcConstraintI {

    protected:

           IlcIntVarArray _x;

           IlcInt _a;

           IloNumArray _best_del;

           IloNumArray _worst_del;

           NumMatrix _comb;

           Num3Matrix _best_del_interval;

           IloNumVar _z;

    public:

    IlcCheckWhenBoundI(IloCP s, IlcIntVarArray x, IlcInt a, IloNumArray worst_del, IloNumArray best_del, NumMatrix comb, IloNumVar z): IlcConstraintI(s), _x(x), _a(a), _worst_del(worst_del), _best_del(best_del), _comb(comb), _z(z) {}

           ~IlcCheckWhenBoundI() {}

           virtual void post();

           virtual void propagate() {}

           void varDemon(IlcIntVar v);

    };

     

    ILCCTDEMON1(RealizeVarBound, IlcCheckWhenBoundI, varDemon, IlcIntVar, v);

     

    void IlcCheckWhenBoundI::post () {

           _x[_a].whenValue(RealizeVarBound(getCP(), this, _x[_a]));

    }

     

    void IlcCheckWhenBoundI::varDemon (IlcIntVar v) {

            //Something

    }

     

    IlcConstraint IlcCheckWhenBound(IloCP s, IlcIntVarArray x, IlcInt a, IloNumArray worst_del, IloNumArray best_del,NumMatrix comb, IloNumVar z) {

           return new (s.getHeap()) IlcCheckWhenBoundI(s, x, a, worst_del, best_del, comb, z);

    }

     

    ILOCPCONSTRAINTWRAPPER6(IloCheckWhenBound, cp, IloIntVarArray, _v, IlcInt, _a, IloNumArray, _worst_del, IloNumArray, _best_del, NumMatrix, _comb, IloNumVar, _z) {

           use(cp, _v);

           use(cp, _z);

           return IlcCheckWhenBound(cp, cp.getIntVarArray(_v), _a, _worst_del,_best_del, _comb, cp.getFloatVar(_z));

    }

     

    The problem is that there is an error under cp  in the definition of ILOCPCONSTRAINTWRAPPER6 stating that "Error: no suitable user-defined conversion from "IlcCPOFloatVar" to "IloNumVar" exists".

     

    Best regards,

    Hossein

     

  • Philippe_Refalo
    Philippe_Refalo
    50 Posts

    Re: User defined bounds in CP

    ‏2014-06-27T16:00:18Z  
    • Hosssein
    • ‏2014-06-25T18:28:23Z

    The IlcConstraint code is as follows:

    typedef IloArray<IloNumArray> NumMatrix;

    typedef IloArray<NumMatrix>   Num3Matrix;

    class IlcCheckWhenBoundI : public IlcConstraintI {

    protected:

           IlcIntVarArray _x;

           IlcInt _a;

           IloNumArray _best_del;

           IloNumArray _worst_del;

           NumMatrix _comb;

           Num3Matrix _best_del_interval;

           IloNumVar _z;

    public:

    IlcCheckWhenBoundI(IloCP s, IlcIntVarArray x, IlcInt a, IloNumArray worst_del, IloNumArray best_del, NumMatrix comb, IloNumVar z): IlcConstraintI(s), _x(x), _a(a), _worst_del(worst_del), _best_del(best_del), _comb(comb), _z(z) {}

           ~IlcCheckWhenBoundI() {}

           virtual void post();

           virtual void propagate() {}

           void varDemon(IlcIntVar v);

    };

     

    ILCCTDEMON1(RealizeVarBound, IlcCheckWhenBoundI, varDemon, IlcIntVar, v);

     

    void IlcCheckWhenBoundI::post () {

           _x[_a].whenValue(RealizeVarBound(getCP(), this, _x[_a]));

    }

     

    void IlcCheckWhenBoundI::varDemon (IlcIntVar v) {

            //Something

    }

     

    IlcConstraint IlcCheckWhenBound(IloCP s, IlcIntVarArray x, IlcInt a, IloNumArray worst_del, IloNumArray best_del,NumMatrix comb, IloNumVar z) {

           return new (s.getHeap()) IlcCheckWhenBoundI(s, x, a, worst_del, best_del, comb, z);

    }

     

    ILOCPCONSTRAINTWRAPPER6(IloCheckWhenBound, cp, IloIntVarArray, _v, IlcInt, _a, IloNumArray, _worst_del, IloNumArray, _best_del, NumMatrix, _comb, IloNumVar, _z) {

           use(cp, _v);

           use(cp, _z);

           return IlcCheckWhenBound(cp, cp.getIntVarArray(_v), _a, _worst_del,_best_del, _comb, cp.getFloatVar(_z));

    }

     

    The problem is that there is an error under cp  in the definition of ILOCPCONSTRAINTWRAPPER6 stating that "Error: no suitable user-defined conversion from "IlcCPOFloatVar" to "IloNumVar" exists".

     

    Best regards,

    Hossein

     

    Hi Hossein, 

    Your constraint must have IlcFloatVar as argument type for _z and not IloNumVar. This is the reason for the compilation error in your code.

    Philippe

     

  • Hosssein
    Hosssein
    26 Posts

    Re: User defined bounds in CP

    ‏2014-06-30T05:40:50Z  

    Hi Hossein, 

    Your constraint must have IlcFloatVar as argument type for _z and not IloNumVar. This is the reason for the compilation error in your code.

    Philippe

     

    Thanks again for your reply.

    I corrected the code as you said. My code is working now, but in some instances after a while it gets into the following error if I add (cp.add(_z<=Upperbound)) within IlcConstraint code:

    *** glibc detected *** ./"the name of my cpp file": invalid fastbin entry (free): 0x000000000232ae20 ***

    If I replace (cp.add(_z<=Upperbound)) with (_z.setMax(Upperbound)) the it gets into another error:

    *** glibc detected *** ./ "the name of my cpp file": double free or corruption (out): 0x000000000233c710 ***

    I ran the same code without passing the objective function (removing _z and z variables) to the IlcConstraint and it did not face with any problem. It looks that there is still something wrong in passing the objective variables. What do you think?

     

     

    Ps.

    My cpp code is as follows:

    IloNumVar MyObjValue(envvv,0,1000000);

    model.add(IloMaximize(envvv, MyObjValue));

    model.add(IloCheckWhenBound(envvv,ALLVARIABLES,p,WORST_DELTA,Combination,BEST_DELTA_INTERVAL,MyObjValue));

     

     

    The IlcConstraint code is also as follows:

     

    typedefIloArray<IloNumArray> NumMatrix;

    typedefIloArray<NumMatrix>   Num3Matrix;

    classIlcCheckWhenBoundI : public IlcConstraintI {

    protected:

           IlcIntVarArray _x;

           IlcInt _a;

           //IloNumArray _best_del;

           IloNumArray _worst_del;

           IlcFloatVar _z;

           NumMatrix _comb;

           Num3Matrix _best_del_interval;

    public:      

           IlcCheckWhenBoundI(IloCP s, IlcIntVarArray x, IlcInt a, IloNumArray worst_del, NumMatrix comb, Num3Matrix best_del_interval, IlcFloatVar z): IlcConstraintI(s), _x(x), _a(a), _worst_del(worst_del), _comb(comb), _best_del_interval(best_del_interval), _z(z) {}

           ~IlcCheckWhenBoundI() {}

           virtual void post();

           virtual void propagate() {}

           void varDemon(IlcIntVar v);

    };

     

    ILCCTDEMON1(RealizeVarBound, IlcCheckWhenBoundI, varDemon, IlcIntVar, v);

     

    voidIlcCheckWhenBoundI::post () {

           _x[_a].whenValue(RealizeVarBound(getCP(), this, _x[_a]));

    }

     

    voidIlcCheckWhenBoundI::varDemon (IlcIntVar v) {

    //computation of upperbound

           if (...){

                  _x.getCP().fail();

           }

           else{

                  _x.getCP().add(_z<= Upperbound);

                  //_x.getCP().add(_z.setMax(Upperbound));

    }

    }

     

     

    IlcConstraint IlcCheckWhenBound(IloCP s, IlcIntVarArray x, IlcInt a, IloNumArray worst_del,NumMatrix comb, Num3Matrix best_del_interval, IlcFloatVar z) {

           return new (s.getHeap()) IlcCheckWhenBoundI(s, x, a, worst_del, comb, best_del_interval, z);

    }

     

     

    ILOCPCONSTRAINTWRAPPER6(IloCheckWhenBound, cp, IloIntVarArray, _v, IlcInt, _a, IloNumArray, _worst_del, NumMatrix, _comb, Num3Matrix, _best_del_interval, IloNumVar, _z) {

           use(cp, _v);

           use(cp, _z);

           return IlcCheckWhenBound(cp, cp.getIntVarArray(_v), _a, _worst_del,_comb, _best_del_interval, cp.getFloatVar(_z));

    }

     

    Best regards,

    Hossein

    Updated on 2014-06-30T05:41:16Z at 2014-06-30T05:41:16Z by Hosssein
  • Philippe_Refalo
    Philippe_Refalo
    50 Posts

    Re: User defined bounds in CP

    ‏2014-07-02T09:19:55Z  
    • Hosssein
    • ‏2014-06-30T05:40:50Z

    Thanks again for your reply.

    I corrected the code as you said. My code is working now, but in some instances after a while it gets into the following error if I add (cp.add(_z<=Upperbound)) within IlcConstraint code:

    *** glibc detected *** ./"the name of my cpp file": invalid fastbin entry (free): 0x000000000232ae20 ***

    If I replace (cp.add(_z<=Upperbound)) with (_z.setMax(Upperbound)) the it gets into another error:

    *** glibc detected *** ./ "the name of my cpp file": double free or corruption (out): 0x000000000233c710 ***

    I ran the same code without passing the objective function (removing _z and z variables) to the IlcConstraint and it did not face with any problem. It looks that there is still something wrong in passing the objective variables. What do you think?

     

     

    Ps.

    My cpp code is as follows:

    IloNumVar MyObjValue(envvv,0,1000000);

    model.add(IloMaximize(envvv, MyObjValue));

    model.add(IloCheckWhenBound(envvv,ALLVARIABLES,p,WORST_DELTA,Combination,BEST_DELTA_INTERVAL,MyObjValue));

     

     

    The IlcConstraint code is also as follows:

     

    typedefIloArray<IloNumArray> NumMatrix;

    typedefIloArray<NumMatrix>   Num3Matrix;

    classIlcCheckWhenBoundI : public IlcConstraintI {

    protected:

           IlcIntVarArray _x;

           IlcInt _a;

           //IloNumArray _best_del;

           IloNumArray _worst_del;

           IlcFloatVar _z;

           NumMatrix _comb;

           Num3Matrix _best_del_interval;

    public:      

           IlcCheckWhenBoundI(IloCP s, IlcIntVarArray x, IlcInt a, IloNumArray worst_del, NumMatrix comb, Num3Matrix best_del_interval, IlcFloatVar z): IlcConstraintI(s), _x(x), _a(a), _worst_del(worst_del), _comb(comb), _best_del_interval(best_del_interval), _z(z) {}

           ~IlcCheckWhenBoundI() {}

           virtual void post();

           virtual void propagate() {}

           void varDemon(IlcIntVar v);

    };

     

    ILCCTDEMON1(RealizeVarBound, IlcCheckWhenBoundI, varDemon, IlcIntVar, v);

     

    voidIlcCheckWhenBoundI::post () {

           _x[_a].whenValue(RealizeVarBound(getCP(), this, _x[_a]));

    }

     

    voidIlcCheckWhenBoundI::varDemon (IlcIntVar v) {

    //computation of upperbound

           if (...){

                  _x.getCP().fail();

           }

           else{

                  _x.getCP().add(_z<= Upperbound);

                  //_x.getCP().add(_z.setMax(Upperbound));

    }

    }

     

     

    IlcConstraint IlcCheckWhenBound(IloCP s, IlcIntVarArray x, IlcInt a, IloNumArray worst_del,NumMatrix comb, Num3Matrix best_del_interval, IlcFloatVar z) {

           return new (s.getHeap()) IlcCheckWhenBoundI(s, x, a, worst_del, comb, best_del_interval, z);

    }

     

     

    ILOCPCONSTRAINTWRAPPER6(IloCheckWhenBound, cp, IloIntVarArray, _v, IlcInt, _a, IloNumArray, _worst_del, NumMatrix, _comb, Num3Matrix, _best_del_interval, IloNumVar, _z) {

           use(cp, _v);

           use(cp, _z);

           return IlcCheckWhenBound(cp, cp.getIntVarArray(_v), _a, _worst_del,_comb, _best_del_interval, cp.getFloatVar(_z));

    }

     

    Best regards,

    Hossein

    The right way to bound the variable _z is to write: 

                  _z.setMax(Upperbound);

    I do not see any other problem in your code.

    When you test without bounding _z are you still computing the bound ? In this case the best is to send us a complete example that demonstate the problem so that we can have a look at it.

     

    Regards

     

    Philippe

  • mremn
    mremn
    8 Posts

    Re: User defined bounds in CP

    ‏2014-07-04T07:57:18Z  

    Hello everyone,

    I'm also trying to integrate my own bounds into my program. But computing my bounds is very costly. A problem I observe is that after each fail, when backtracking, the program re-calculates the bounds which are already known before. We can avoid this by memorizing the bound at each node. But I don't know how I can do it.

     

    Thank you very much for your answers,

     

     

  • ChrisBr
    ChrisBr
    60 Posts

    Re: User defined bounds in CP

    ‏2014-07-07T12:40:34Z  
    • mremn
    • ‏2014-07-04T07:57:18Z

    Hello everyone,

    I'm also trying to integrate my own bounds into my program. But computing my bounds is very costly. A problem I observe is that after each fail, when backtracking, the program re-calculates the bounds which are already known before. We can avoid this by memorizing the bound at each node. But I don't know how I can do it.

     

    Thank you very much for your answers,

     

     

    Hello,

    You might try to use a IlcRevInt or a IlcRevFloat.

    I hope this helps,

    Chris.

     

  • Hosssein
    Hosssein
    26 Posts

    Re: User defined bounds in CP

    ‏2014-07-24T11:32:24Z  

    The right way to bound the variable _z is to write: 

                  _z.setMax(Upperbound);

    I do not see any other problem in your code.

    When you test without bounding _z are you still computing the bound ? In this case the best is to send us a complete example that demonstate the problem so that we can have a look at it.

     

    Regards

     

    Philippe

    Thanks Philippe.

    Yes, when I test without bounding _z I am still computing the bound. I still have the problem with my code.

    I have uploaded the zip file of my C++ project in the following link:

    https://www.dropbox.com/s/r2wq7uaezvtle9v/Test2-with%20obj.zip

    Also you need to download the test instance file (Hash-30OR-100-2.data) and a help file to run the project in Linux (help.txt) in the following links:

    https://www.dropbox.com/s/fp0mrbjclkhslgg/Hash-30OR-100-2.data

    https://www.dropbox.com/s/30uunl79uqv0zjz/help.txt

    I will be so thankful if you can run my code in Linux.

    Best regards,

    Hossein

    Updated on 2014-08-07T09:35:49Z at 2014-08-07T09:35:49Z by Hosssein
  • Hosssein
    Hosssein
    26 Posts

    Re: User defined bounds in CP

    ‏2014-08-07T09:28:53Z  

    The right way to bound the variable _z is to write: 

                  _z.setMax(Upperbound);

    I do not see any other problem in your code.

    When you test without bounding _z are you still computing the bound ? In this case the best is to send us a complete example that demonstate the problem so that we can have a look at it.

     

    Regards

     

    Philippe

    Hi again,

    Could you please tell me how long it takes for you to test my code?.

    As I mentioned in previous posts if you remove Line# 343 (_z.setMax((BestObjectiveRelaxedKnapsack-_worst_del[6]));) from the DynamicFiltering.h file, the code does not get into the reported errors.

    Thanks.

    Best regards,

    Hossein

    Updated on 2014-08-07T09:36:40Z at 2014-08-07T09:36:40Z by Hosssein
  • Philippe_Refalo
    Philippe_Refalo
    50 Posts

    Re: User defined bounds in CP

    ‏2014-08-07T13:12:51Z  
    • Hosssein
    • ‏2014-08-07T09:28:53Z

    Hi again,

    Could you please tell me how long it takes for you to test my code?.

    As I mentioned in previous posts if you remove Line# 343 (_z.setMax((BestObjectiveRelaxedKnapsack-_worst_del[6]));) from the DynamicFiltering.h file, the code does not get into the reported errors.

    Thanks.

    Best regards,

    Hossein

    Hi Hossein, 

    I am looking at your code. It seems that the file InitialSolution-XXXX is missing for the data file you provided. Can you send it and check that nothing else is missing ?

    Thanks.

    Philippe

  • Hosssein
    Hosssein
    26 Posts

    Re: User defined bounds in CP

    ‏2014-08-07T20:21:04Z  

    Hi Hossein, 

    I am looking at your code. It seems that the file InitialSolution-XXXX is missing for the data file you provided. Can you send it and check that nothing else is missing ?

    Thanks.

    Philippe

    Sorry. I forgot to attach the other required file. Please put the following data file beside of Hash-30OR-100-2.data at the same directory. You need both files to test the code.

    https://www.dropbox.com/s/w6te17ca5njq0mw/InitialSolution-Hash-30OR-100-2.data

    I tested my code again. When I activate _z.setMax((BestObjectiveRelaxedKnapsack-_worst_del[6])); in DynamicFiltering.h the code gets into an error, but when it is deactivated it works without any problem.

    Thanks again

     

    Best regards,

    Hossein

    Updated on 2014-08-08T08:23:07Z at 2014-08-08T08:23:07Z by Hosssein
  • Philippe_Refalo
    Philippe_Refalo
    50 Posts

    Re: User defined bounds in CP

    ‏2014-08-18T13:31:21Z  
    • Hosssein
    • ‏2014-08-07T20:21:04Z

    Sorry. I forgot to attach the other required file. Please put the following data file beside of Hash-30OR-100-2.data at the same directory. You need both files to test the code.

    https://www.dropbox.com/s/w6te17ca5njq0mw/InitialSolution-Hash-30OR-100-2.data

    I tested my code again. When I activate _z.setMax((BestObjectiveRelaxedKnapsack-_worst_del[6])); in DynamicFiltering.h the code gets into an error, but when it is deactivated it works without any problem.

    Thanks again

     

    Best regards,

    Hossein

    I looked at the code and I do not see any reason for the bound change on _z to create a problem compared to the addition of the constraint. A possible reason could be some reading out of arrays bound. At line 305 :

    int SurgeryA = _worst_del[(BBNumber_Surgeries+1)*(BBP8Size+5)+((_worst_del[2]+1)+k)*(BBP8Size+5)+MINSTART];

    I get an assert violation because the index exceeds the array size. Since you use SurgeryA as an index later on this can cascade into invalid writings. It is difficult to reproduce the same behavior from a platform to another probably because you use time limits for the search.

    Please,  fix this and let me know if you still get an error.

    Philippe

     

     

     

     
  • mremn
    mremn
    8 Posts

    Re: User defined bounds in CP

    ‏2014-08-22T02:44:43Z  
    • ChrisBr
    • ‏2014-07-07T12:40:34Z

    Hello,

    You might try to use a IlcRevInt or a IlcRevFloat.

    I hope this helps,

    Chris.

     

    Thank you Chris for your answer,

     

    For my purpose, I need to memorize values stored in a 2-dimension array. So I need a IlcRevFloatArray but it seems that it does not exit. Could you give me any suggestion?

     

    Thanks again,

     

     

    Updated on 2014-08-22T02:45:05Z at 2014-08-22T02:45:05Z by mremn
  • Hosssein
    Hosssein
    26 Posts

    Re: User defined bounds in CP

    ‏2014-08-22T17:28:48Z  

    I looked at the code and I do not see any reason for the bound change on _z to create a problem compared to the addition of the constraint. A possible reason could be some reading out of arrays bound. At line 305 :

    int SurgeryA = _worst_del[(BBNumber_Surgeries+1)*(BBP8Size+5)+((_worst_del[2]+1)+k)*(BBP8Size+5)+MINSTART];

    I get an assert violation because the index exceeds the array size. Since you use SurgeryA as an index later on this can cascade into invalid writings. It is difficult to reproduce the same behavior from a platform to another probably because you use time limits for the search.

    Please,  fix this and let me know if you still get an error.

    Philippe

     

     

     

     

    Thanks a lot Philippe. I can run it now without any error.

    Best regards,

    Hossein

  • ChrisBr
    ChrisBr
    60 Posts

    Re: User defined bounds in CP

    ‏2014-08-29T15:16:29Z  
    • mremn
    • ‏2014-08-22T02:44:43Z

    Thank you Chris for your answer,

     

    For my purpose, I need to memorize values stored in a 2-dimension array. So I need a IlcRevFloatArray but it seems that it does not exit. Could you give me any suggestion?

     

    Thanks again,

     

     

    Hello,

    You might have a look at the distributed sample "schedsearch_settimes" where an array of IlcRevInt is used, and write something similar.

    Regards,

    Chris.
     

  • mremn
    mremn
    8 Posts

    Re: User defined bounds in CP

    ‏2014-08-30T00:05:59Z  
    • ChrisBr
    • ‏2014-08-29T15:16:29Z

    Hello,

    You might have a look at the distributed sample "schedsearch_settimes" where an array of IlcRevInt is used, and write something similar.

    Regards,

    Chris.
     

    Thank you Chris,

    It's working perfectly.

     

    Best regards,