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