Decision Optimization

Decision Optimization

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

 View Only
Expand all | Collapse all

Different range

  • 1.  Different range

    Posted Fri October 08, 2010 11:02 AM

    Originally posted by: SystemAdmin


    Hi,
    Is it possible in cplex 12 using java concert technology for a value to have a multiple range.
    I want a constraint where I want a IloNumVar to have values as either zero or number in range say 3 to 11, but nothing in between 0 and 3.
    Could anyone suggest me how this can be done.

    Regards
    #CPLEXOptimizers
    #DecisionOptimization


  • 2.  Re: Different range

    Posted Sat October 09, 2010 02:10 PM

    Originally posted by: SystemAdmin


    > surajjung wrote:
    > I want a constraint where I want a IloNumVar to have values as either zero or number in range say 3 to 11, but nothing in between 0 and 3.

    IloCplex cplex = new IloCplex();
    IloSemiContVar x = cplex.semiContVar(3., 11., IloNumVarType.Float);
    


    /Paul

    Mathematicians are like Frenchmen: whenever you say something to them, they translate it into their own language, and at once it is something entirely different. (Goethe)
    #CPLEXOptimizers
    #DecisionOptimization


  • 3.  Re: Different range

    Posted Mon October 11, 2010 05:45 AM

    Originally posted by: SystemAdmin


    Hi,
    Thank you for the reply.
    I have one another problem. Is it possible to have the constraints which satisfies the range, -10 to -3 and 0 and +3 to +10.
    i.e I want a variable which can take the value from -10 to -3 and 0 and +3 to +10 but nothing in between -3 to +3 except 0.

    Regards
    #CPLEXOptimizers
    #DecisionOptimization


  • 4.  Re: Different range

    Posted Mon October 11, 2010 05:56 AM

    Originally posted by: SystemAdmin


    I'm afraid not.
    What you can do is:
    • Use two variables x1 and x2. x1 is 0 or in 3,10, x2 is 0 or in -10,-3.
    • Replace x by x=x1+x2.
    • Add an additional binary variable b with constraints x1<=10*b, x2>=-10*(1-b). If b=0 then this says x1<=0 (i.e. x1=0) and x2>=-10, if b=1 then this says x1<=10 and x2>=0 (i.e. x2=0).
    Instead of using a binary variable b and the constraints I mentioned you can also use indicator variables/constraints.
    #CPLEXOptimizers
    #DecisionOptimization


  • 5.  Re: Different range

    Posted Mon October 11, 2010 06:35 AM

    Originally posted by: SystemAdmin


    Just curious , but can it be done in the way
    define X as -10 to +10
    define X_abs as 0 or +3 to +10
    force X_abs=|X|
    where |X| is absolute value of X.

    Is it possible?
    If it is could you help me with the implementation of it. AM not sure how to do it.
    #CPLEXOptimizers
    #DecisionOptimization


  • 6.  Re: Different range

    Posted Mon October 11, 2010 07:19 AM

    Originally posted by: SystemAdmin


    Yes, it can also be done in this way The difficult part is to force X_abs = |X|. One direction is simple:
    X_abs >= X
    X_abs >= -X
    This ensures X_abs >= |X|. Now if X_abs has a positive objective function coefficient and you have a minimization problem then you will automatically have X_abs=|X| (otherwise the solution is non-optimal.
    #CPLEXOptimizers
    #DecisionOptimization


  • 7.  Re: Different range

    Posted Mon October 11, 2010 06:40 AM

    Originally posted by: SystemAdmin


    IloCplex model = new IloCplex();
        IloNumVar X[] = model.numVarArray(noOfVar, -10, 10);
        IloSemiContVar X1[] = model.semiContVarArray(noOfVar, 3, 10, IloNumVarType.Float);
        IloSemiContVar X2[] = model.semiContVarArray(noOfVar, -3, -10, IloNumVarType.Float);
        
    for (int i = 0; i < X.length; ++i) {
                model.addEq(model.sum(X1[i], X2[i]), X[i]);
                model.addLe(X1[i],model.prod(10, b));
                model.addGe(X2[i],model.prod(-10, model.sum(1, model.prod(-1, b))));
            }
    


    Could you please check if this is the correct implementation of your method..
    Cplex 12 java concert tech.
    #CPLEXOptimizers
    #DecisionOptimization


  • 8.  Re: Different range

    Posted Mon October 11, 2010 07:21 AM

    Originally posted by: SystemAdmin


    Looks correct except for the constructor if X2. In this constructor you must swap -3 and -10. -10 is the lower bound and -3 is the upper bound.
    And you probably need a b-variable for each variable in X, don't you? Or are all your X[i] positive/negative simultaneously?
    #CPLEXOptimizers
    #DecisionOptimization


  • 9.  Re: Different range

    Posted Mon October 11, 2010 08:00 AM

    Originally posted by: SystemAdmin


    Thanks,
    IloCplex model = null;
        IloNumVar X[] = model.numVarArray(noOfVar, -11, 11);
        IloSemiContVar X1[] = model.semiContVarArray(noOfVar, 3, 11, IloNumVarType.Float);
        IloSemiContVar X2[] = model.semiContVarArray(noOfVar, -11, -3, IloNumVarType.Float);
        IloNumVar E[] = model.numVarArray(noOfRev, -100, 100);
        IloNumVar E_abs[] = model.numVarArray(noOfRev, 0, 100);
        model = new IloCplex();
        IloNumVar b[]=model.boolVarArray(noOfVar);
     
          
           for (int i = 0; i < E.length; ++i) {
                model.addLe(model.prod(1.0, E[i]), E_abs[i]);
                model.addLe(model.prod(-1.0, E[i]), E_abs[i]);
            }
     
            for (int i = 0; i < X.length; ++i) {
                model.addEq(model.sum(X1[i], X2[i]), X[i]);
                model.addLe(X1[i],model.prod(10, b[i]));
                model.addGe(X2[i],model.prod(-10, model.sum(1, model.prod(-1, b[i]))));
            }
     
            IloNumExpr exprn1 = model.scalProd(X, X);
     
            IloNumExpr exprn2 = model.sum(E_abs);
     
            model.addMinimize(model.sum(model.prod(0.7, exprn1),
                    model.prod(0.3, exprn2)));
    


    Here I have added my code with the optimization equation...
    But I get the warning, " Bound infeasibility column 'IloX386'."

    The error is persistent even if i increase the bounds to very higer ranges.
    Is there anything wrong I am doing?

    Regards
    #CPLEXOptimizers
    #DecisionOptimization


  • 10.  Re: Different range

    Posted Mon October 11, 2010 08:25 AM

    Originally posted by: SystemAdmin


    Sorry, my fault. I didn't remember that semi-continuous variables must not have negative bounds (from the docs):

    A semi-continuous variable is a variable that by default can take the value 0 (zero) or any value between its semi-continuous lower bound (sclb) and its upper bound (ub). The semi-continuous lower bound (sclb) must be finite. The upper bound (ub) need not be finite. The semi-continuous lower bound (sclb) must be greater than or equal to 0 (zero). An attempt to use a negative value for the semi-continuous lower bound (sclb) will result in that bound being treated as 0 (zero).

    So instead of using X, X1 and X2 as described before you should use
    • X1 is 0 or in 3,10
    • X2 is 0 or in 3,10
    • X = X1 - X2
    • X1 <= 10*b
    • -X2 >= -10*(1-b)
    This should do the trick. I changed your code accordingly and no longer get the error:
    import ilog.cplex.*;
    import ilog.concert.*;
     
    public class Semi {
       public static void main(String[] args) {
          try {
             int noOfVar = 10;
             int noOfRev = 5;
             IloCplex model = new IloCplex();
             IloNumVar X[] = model.numVarArray(noOfVar, -11, 11);
             IloSemiContVar X1[] = model.semiContVarArray(noOfVar, 3, 11, IloNumVarType.Float);
             IloSemiContVar X2[] = model.semiContVarArray(noOfVar, 3, 11, IloNumVarType.Float);
             IloNumVar E[] = model.numVarArray(noOfRev, -100, 100);
             IloNumVar E_abs[] = model.numVarArray(noOfRev, 0, 100);
             IloNumVar b[]=model.boolVarArray(noOfVar);
     
     
             for (int i = 0; i < E.length; ++i) {
                model.addLe(model.prod(1.0, E[i]), E_abs[i]);
                model.addLe(model.prod(-1.0, E[i]), E_abs[i]);
             }
     
             for (int i = 0; i < X.length; ++i) {
                model.addEq(model.diff(X1[i], X2[i]), X[i]);
                model.addLe(X1[i],model.prod(10, b[i]));
                model.addGe(model.prod(-1., X2[i]),model.prod(-10, model.sum(1, model.prod(-1, b[i]))));
             }
     
             IloNumExpr exprn1 = model.scalProd(X, X);
     
             IloNumExpr exprn2 = model.sum(E_abs);
     
             model.addMinimize(model.sum(model.prod(0.7, exprn1),
                                         model.prod(0.3, exprn2)));
     
             model.solve();
          } catch (IloException e) {
             System.err.println("IloException: " + e);
          }
       }
    }
    

    #CPLEXOptimizers
    #DecisionOptimization


  • 11.  Re: Different range

    Posted Mon October 11, 2010 09:58 AM

    Originally posted by: SystemAdmin


    Thanks a lot...
    Highly appreciated...
    But suddenly I started getting lots of multiple solutions and running out of memory...
    Regards
    #CPLEXOptimizers
    #DecisionOptimization


  • 12.  Re: Different range

    Posted Tue October 12, 2010 02:48 AM

    Originally posted by: SystemAdmin


    Don't know if these multiple solutions and the out of memory are a problem with CPLEX or with your model? Anyway, if you want to discuss this it would be nice if you opened a new thread here.
    #CPLEXOptimizers
    #DecisionOptimization