Decision Optimization

Decision Optimization

Delivers prescriptive analytics capabilities and decision intelligence to improve decision-making.

 View Only
Expand all | Collapse all

IlcIntVar with a positive Min and a Negative Max

  • 1.  IlcIntVar with a positive Min and a Negative Max

    Posted Fri July 12, 2013 05:09 PM

    Originally posted by: Antoine_Mtl


    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)


    #CPOptimizer
    #DecisionOptimization


  • 2.  Re: IlcIntVar with a positive Min and a Negative Max

    Posted Mon July 15, 2013 06:40 AM

    Originally posted by: ol


    Hello,

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

     

    Olivier


    #CPOptimizer
    #DecisionOptimization


  • 3.  Re: IlcIntVar with a positive Min and a Negative Max

    Posted Mon July 15, 2013 08:42 PM

    Originally posted by: Antoine_Mtl


    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);
    }
     

     


    #CPOptimizer
    #DecisionOptimization


  • 4.  Re: IlcIntVar with a positive Min and a Negative Max

    Posted Wed July 17, 2013 05:11 AM

    Originally posted by: ol


    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


    #CPOptimizer
    #DecisionOptimization


  • 5.  Re: IlcIntVar with a positive Min and a Negative Max

    Posted Wed July 17, 2013 10:52 AM

    Originally posted by: Antoine_Mtl


    Thank you, it was the right problem


    #CPOptimizer
    #DecisionOptimization