Topic
  • 4 replies
  • Latest Post - ‏2013-07-17T14:51:59Z by Antoine_Mtl
Antoine_Mtl
Antoine_Mtl
5 Posts

Pinned topic IlcIntVar with a positive Min and a Negative Max

‏2013-07-12T21:08:33Z |

Hello,

I've written my own constraint and I've got a problem when I'm trying to extract some information.

For a variable IlcIntVar surgeonBegin, I have:

surgeonBegin.getMin() = 1

surgeonBegin.getMax() = -23

When I solve the CP problem without my ownconstraint, there is no problem.

Do you know what could be the problem ?

Thank you

 

There is the code:

 

class IlcCtrI: public IlcConstraintI {

    public:
    IlcCtrI(IloCP cp, IlcIntVar surgeonBegin);
    ~IlcCtrI();
    void post();
    void propagate();
    void pushDemon();

    private:
    IlcIntVar _surgeonBegin;
};

void IlcCtrI::propagate() {

    //update bounds
    int surgeonBeginLB(_surgeonBegin.getMin());
    int surgeonBeginUB(_surgeonBegin.getMax());    ...................

}

/*
 * Handle for IlcCtrI
 */
IlcConstraint IlcCtr(IloCP cp, IlcIntVar surgeonBegin){
    return (new (cp.getHeap())  IlcCtrI(cp, surgeonBegin));
}

/*
 * Wrapper for IlcCtr => use the constraint in concert (model.add(..))
 */

ILOCPCONSTRAINTWRAPPER1(IloCtr, cp, IloIntVar, surgeonBegin){
    use(cp, surgeonBegin);
    IlcIntVar c_surgeonBegin =cp.getIntVar(surgeonBegin);
    return (IlcCtr(cp, c_surgeonBegin));
}

surgeonBegin is initialized with IloIntVar(_env)

  • ol
    ol
    62 Posts
    ACCEPTED ANSWER

    Re: IlcIntVar with a positive Min and a Negative Max

    ‏2013-07-17T09:11:17Z  

    Hi,

    Thanks for the answer.

    I'm using CPLEX 12.5.

    There is the output:

    Min 0 and Max -7
     ! ----------------------------------------------------------------------------
     ! Minimization problem - 2 variables, 2 constraints
    Min 0 and Max -7
     ! Initial process time : 0.00s (0.00s extraction + 0.00s propagation)
     !  . Log search space  : 52.0 (before), 52.0 (after)
     !  . Memory usage      : 531.8 kB (before), 531.8 kB (after)
     ! Using sequential search.
     ! ----------------------------------------------------------------------------
     !          Best Branches  Non-fixed            Branch decision
    Min 0 and Max 0
     *             0        1 0.00s                 on _itv0
    Min 0 and Max 0
     ! ----------------------------------------------------------------------------
     ! Search terminated normally, 1 solution found.
     ! Best objective         : 0 (optimal - effective tol. is 0)
     ! Number of branches     : 3
     ! Number of fails        : 2
     ! Total memory usage     : 604.4 kB (563.9 kB CP Optimizer + 40.6 kB Concert)
     ! Time spent in solve    : 0.00s (0.00s engine + 0.00s extraction)
     ! Search speed (br. / s) : 300.0
     ! ----------------------------------------------------------------------------

    The output is wrong while the branching process haven't started.

    The source:

    #include <iostream>
    #include <ilcp/cp.h>
    #include <ilcp/cpext.h>
     
    /*
     * Definition of IlcCtrI
     */
    class IlcCtrI: public IlcConstraintI{
    IlcIntVar _begin;
     
    public:
    IlcCtrI(IloCP cp, IlcIntVar begin);
    ~IlcCtrI();
    void post();
    void propagate();
    };
     
    /*
     * Handle for IlcCtrI
     */
    IlcConstraint IlcCtr(IloCP cp, IlcIntVar begin){
    return (new (cp.getHeap()) IlcCtrI(cp, begin));
    }
     
    /*
     * Wrapper for IlcCtr => use the constraint in concert (model.add(..))
     */
     
    ILOCPCONSTRAINTWRAPPER1(IloCtr, cp, IloIntVar, begin){
    use(cp, begin);
    IlcIntVar c_begin(cp.getIntVar(begin));
    return (IlcCtr(cp, c_begin));
    }
     
    int main() {
    // TODO Auto-generated method stub
    IloEnv env;
    try {
    IloModel model(env);
    IloIntVar begin(env);
     
    IloIntervalVar tasks(env,5);
    model.add(begin == IloStartOf(tasks));
     
    model.add(IloCtr(env, begin));
     
    model.add(IloMinimize(env, begin));
     
    IloCP cp(model);
    cp.solve();
    cp.end();
     
    model.end();
    } catch(IloException& e){
    env.out() << " ERROR: " << e << "\n";
    }
    env.end();
    }
     
    /*
     * Definition IlcCtrI's methods
     */
    IlcCtrI::IlcCtrI(IloCP cp, IlcIntVar begin):
    IlcConstraintI(cp),
    _begin(begin) {}
     
    IlcCtrI::~IlcCtrI() {}
     
    void IlcCtrI::propagate() {
     
    //update bounds
    int beginLB(_begin.getMin());
    int beginUB(_begin.getMax());
     
    std::cout << "Min " << beginLB << " and Max " << beginUB << std::endl;
    }
     
    void IlcCtrI::post(){
    _begin.whenDomain(this);
    }
     

     

    Hello,

    I suspect you use a 64 bits machine. By casting a 64 bits integer (the upper bound of the variable) to a 32 bit int like this:

    //update bounds
    int beginLB(_begin.getMin());
    int beginUB(_begin.getMax());

    you may have such surprise. Try to cast to an IlcInt instead.

    //update bounds
    IlcInt beginLB(_begin.getMin());
    IlcInt beginUB(_begin.getMax());

    regards,

    Olivier

  • ol
    ol
    62 Posts

    Re: IlcIntVar with a positive Min and a Negative Max

    ‏2013-07-15T10:39:43Z  

    Hello,

    quite strange indeed! could you send a program reproducing the problem? which version do you use?

     

    Olivier

  • Antoine_Mtl
    Antoine_Mtl
    5 Posts

    Re: IlcIntVar with a positive Min and a Negative Max

    ‏2013-07-16T00:41:59Z  
    • ol
    • ‏2013-07-15T10:39:43Z

    Hello,

    quite strange indeed! could you send a program reproducing the problem? which version do you use?

     

    Olivier

    Hi,

    Thanks for the answer.

    I'm using CPLEX 12.5.

    There is the output:

    Min 0 and Max -7
     ! ----------------------------------------------------------------------------
     ! Minimization problem - 2 variables, 2 constraints
    Min 0 and Max -7
     ! Initial process time : 0.00s (0.00s extraction + 0.00s propagation)
     !  . Log search space  : 52.0 (before), 52.0 (after)
     !  . Memory usage      : 531.8 kB (before), 531.8 kB (after)
     ! Using sequential search.
     ! ----------------------------------------------------------------------------
     !          Best Branches  Non-fixed            Branch decision
    Min 0 and Max 0
     *             0        1 0.00s                 on _itv0
    Min 0 and Max 0
     ! ----------------------------------------------------------------------------
     ! Search terminated normally, 1 solution found.
     ! Best objective         : 0 (optimal - effective tol. is 0)
     ! Number of branches     : 3
     ! Number of fails        : 2
     ! Total memory usage     : 604.4 kB (563.9 kB CP Optimizer + 40.6 kB Concert)
     ! Time spent in solve    : 0.00s (0.00s engine + 0.00s extraction)
     ! Search speed (br. / s) : 300.0
     ! ----------------------------------------------------------------------------

    The output is wrong while the branching process haven't started.

    The source:

    #include <iostream>
    #include <ilcp/cp.h>
    #include <ilcp/cpext.h>
     
    /*
     * Definition of IlcCtrI
     */
    class IlcCtrI: public IlcConstraintI{
    IlcIntVar _begin;
     
    public:
    IlcCtrI(IloCP cp, IlcIntVar begin);
    ~IlcCtrI();
    void post();
    void propagate();
    };
     
    /*
     * Handle for IlcCtrI
     */
    IlcConstraint IlcCtr(IloCP cp, IlcIntVar begin){
    return (new (cp.getHeap()) IlcCtrI(cp, begin));
    }
     
    /*
     * Wrapper for IlcCtr => use the constraint in concert (model.add(..))
     */
     
    ILOCPCONSTRAINTWRAPPER1(IloCtr, cp, IloIntVar, begin){
    use(cp, begin);
    IlcIntVar c_begin(cp.getIntVar(begin));
    return (IlcCtr(cp, c_begin));
    }
     
    int main() {
    // TODO Auto-generated method stub
    IloEnv env;
    try {
    IloModel model(env);
    IloIntVar begin(env);
     
    IloIntervalVar tasks(env,5);
    model.add(begin == IloStartOf(tasks));
     
    model.add(IloCtr(env, begin));
     
    model.add(IloMinimize(env, begin));
     
    IloCP cp(model);
    cp.solve();
    cp.end();
     
    model.end();
    } catch(IloException& e){
    env.out() << " ERROR: " << e << "\n";
    }
    env.end();
    }
     
    /*
     * Definition IlcCtrI's methods
     */
    IlcCtrI::IlcCtrI(IloCP cp, IlcIntVar begin):
    IlcConstraintI(cp),
    _begin(begin) {}
     
    IlcCtrI::~IlcCtrI() {}
     
    void IlcCtrI::propagate() {
     
    //update bounds
    int beginLB(_begin.getMin());
    int beginUB(_begin.getMax());
     
    std::cout << "Min " << beginLB << " and Max " << beginUB << std::endl;
    }
     
    void IlcCtrI::post(){
    _begin.whenDomain(this);
    }
     

     

  • ol
    ol
    62 Posts

    Re: IlcIntVar with a positive Min and a Negative Max

    ‏2013-07-17T09:11:17Z  

    Hi,

    Thanks for the answer.

    I'm using CPLEX 12.5.

    There is the output:

    Min 0 and Max -7
     ! ----------------------------------------------------------------------------
     ! Minimization problem - 2 variables, 2 constraints
    Min 0 and Max -7
     ! Initial process time : 0.00s (0.00s extraction + 0.00s propagation)
     !  . Log search space  : 52.0 (before), 52.0 (after)
     !  . Memory usage      : 531.8 kB (before), 531.8 kB (after)
     ! Using sequential search.
     ! ----------------------------------------------------------------------------
     !          Best Branches  Non-fixed            Branch decision
    Min 0 and Max 0
     *             0        1 0.00s                 on _itv0
    Min 0 and Max 0
     ! ----------------------------------------------------------------------------
     ! Search terminated normally, 1 solution found.
     ! Best objective         : 0 (optimal - effective tol. is 0)
     ! Number of branches     : 3
     ! Number of fails        : 2
     ! Total memory usage     : 604.4 kB (563.9 kB CP Optimizer + 40.6 kB Concert)
     ! Time spent in solve    : 0.00s (0.00s engine + 0.00s extraction)
     ! Search speed (br. / s) : 300.0
     ! ----------------------------------------------------------------------------

    The output is wrong while the branching process haven't started.

    The source:

    #include <iostream>
    #include <ilcp/cp.h>
    #include <ilcp/cpext.h>
     
    /*
     * Definition of IlcCtrI
     */
    class IlcCtrI: public IlcConstraintI{
    IlcIntVar _begin;
     
    public:
    IlcCtrI(IloCP cp, IlcIntVar begin);
    ~IlcCtrI();
    void post();
    void propagate();
    };
     
    /*
     * Handle for IlcCtrI
     */
    IlcConstraint IlcCtr(IloCP cp, IlcIntVar begin){
    return (new (cp.getHeap()) IlcCtrI(cp, begin));
    }
     
    /*
     * Wrapper for IlcCtr => use the constraint in concert (model.add(..))
     */
     
    ILOCPCONSTRAINTWRAPPER1(IloCtr, cp, IloIntVar, begin){
    use(cp, begin);
    IlcIntVar c_begin(cp.getIntVar(begin));
    return (IlcCtr(cp, c_begin));
    }
     
    int main() {
    // TODO Auto-generated method stub
    IloEnv env;
    try {
    IloModel model(env);
    IloIntVar begin(env);
     
    IloIntervalVar tasks(env,5);
    model.add(begin == IloStartOf(tasks));
     
    model.add(IloCtr(env, begin));
     
    model.add(IloMinimize(env, begin));
     
    IloCP cp(model);
    cp.solve();
    cp.end();
     
    model.end();
    } catch(IloException& e){
    env.out() << " ERROR: " << e << "\n";
    }
    env.end();
    }
     
    /*
     * Definition IlcCtrI's methods
     */
    IlcCtrI::IlcCtrI(IloCP cp, IlcIntVar begin):
    IlcConstraintI(cp),
    _begin(begin) {}
     
    IlcCtrI::~IlcCtrI() {}
     
    void IlcCtrI::propagate() {
     
    //update bounds
    int beginLB(_begin.getMin());
    int beginUB(_begin.getMax());
     
    std::cout << "Min " << beginLB << " and Max " << beginUB << std::endl;
    }
     
    void IlcCtrI::post(){
    _begin.whenDomain(this);
    }
     

     

    Hello,

    I suspect you use a 64 bits machine. By casting a 64 bits integer (the upper bound of the variable) to a 32 bit int like this:

    //update bounds
    int beginLB(_begin.getMin());
    int beginUB(_begin.getMax());

    you may have such surprise. Try to cast to an IlcInt instead.

    //update bounds
    IlcInt beginLB(_begin.getMin());
    IlcInt beginUB(_begin.getMax());

    regards,

    Olivier

  • Antoine_Mtl
    Antoine_Mtl
    5 Posts

    Re: IlcIntVar with a positive Min and a Negative Max

    ‏2013-07-17T14:51:59Z  
    • ol
    • ‏2013-07-17T09:11:17Z

    Hello,

    I suspect you use a 64 bits machine. By casting a 64 bits integer (the upper bound of the variable) to a 32 bit int like this:

    //update bounds
    int beginLB(_begin.getMin());
    int beginUB(_begin.getMax());

    you may have such surprise. Try to cast to an IlcInt instead.

    //update bounds
    IlcInt beginLB(_begin.getMin());
    IlcInt beginUB(_begin.getMax());

    regards,

    Olivier

    Thank you, it was the right problem