Decision Optimization

Decision Optimization

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


#Analytics
#DecisionOptimization
#DecisionOptimization
 View Only
  • 1.  Saving IloNumExpr or constant double value in the same variable

    Posted 06/10/20 01:06 PM


    Hello,

    I am currently working on an LP formulation. During this process I create the following constraint, involving two objects r and s. Depending on their state they can either have a variable or a fixed value associated with their width:

    IloNumVar variable_s_position, variable_r_position, variable_s_width, variable_r_width;
    IloNumExpr distance = sum($variable_s_position, prod(-1, $variable_r_position));
    
    if(r.isFlexible){
        if (s.isFlexible) {
            IloNumExpr lower_bound = sum($variable_width_s, $variable_width_r);
            add(ge(distance_below,lower_bound);
        } else {
            IloNumExpr lower_bound = sum(fixed_width_s, $variable_width_r);
            add(ge(distance_below,lower_bound);
        }
    } else {
        if (s.isFlexible) {
            IloNumExpr lower_bound = sum($variable_width_s, fixed_width_r);
            add(ge(distance_below,lower_bound);
        } else {
            double lower_bounds = fixed_width_s + fixed_width_r;
            add(ge(distance_below,lower_bound);
        }
    }


    As you can see, I'm using the line "add(ge(distance_below,lower_bound);" 4 times, once in every branch. I realize that the fourth call is not the same function call as the second argument is a double variable instead of an IloNumExpr. I would like to refactor the code in something along the lines of the following example:

    IloNumVar variable_s_position, variable_r_position, variable_s_width, variable_r_width;
    IloNumExpr distance = sum($variable_s_position, prod(-1, $variable_r_position));
    IloNumExpr lower_bound;
    
    if(r.isFlexible){
        if (s.isFlexible) {
            lower_bound = sum($variable_width_s, $variable_width_r);
        } else {
            lower_bound = sum(fixed_width_s, $variable_width_r);
        }
    } else {
        if (s.isFlexible) {
            lower_bound = sum($variable_width_s, fixed_width_r);
        } else {
            lower_bounds = fixed_width_s + fixed_width_r;
        }
    }
    
    add(ge(distance_below,lower_bound);


    For the first three branches, this would work fine, but in the fourth branch, I would be assigning a double value to a IloNumExpr, which is not valid. Is there a way to save a constant value OR a an IloNumExpr in the same variable, such that this variable can be used as the right hand side of a constraint?

    Comment: In the actual program, the case distinction might exceed 4 branches and need up to 64 calls to (almost) the same line.



    ------------------------------
    Soeren Nickel
    ------------------------------

    #DecisionOptimization


  • 2.  RE: Saving IloNumExpr or constant double value in the same variable

    Posted 06/10/20 04:06 PM
    You did not specify which API you are using. If it is Java, you can invoke linearNumericExpr(lower_bound) on the IloCplex instance to get a linear numeric expression equal to lower_bound.

    ------------------------------
    Paul Rubin
    Professor Emeritus
    Michigan State University
    ------------------------------



  • 3.  RE: Saving IloNumExpr or constant double value in the same variable

    Posted 06/10/20 04:18 PM
    Thank you very much, I'm indeed using Java (I'll remember to specify that in future questions) and this solves my problem.

    ------------------------------
    Soeren Nickel
    ------------------------------