1
votes

I am working on an optimisation model using Pyomo (with the iPopt solver) and I am trying to set up a constraint that keeps specific variables of the model outside of a certain range (0,500], that is the variable can either be zero or greater than 500.

As I cannot specify multiple domains to the variables, I am adding a constraint for each variable using binary variables.

The constraint works like this :

model.variable <= 1 + (large_upper_bound-1)*model.binary_variable
model.variable >= 500*model.binary_variable

Here is my code :

model.x2 = Var(binary_vars, within=Binary)

for route in binary_vars:
        model.cons.add(model.x[route[0], route[1], route[2], route[3]] <= (1 + (100000-1)*model.x2[route[0], route[1], route[2], route[3]]))
        model.cons.add(model.x[route[0], route[1], route[2], route[3]] >= (500*model.x2[route[0], route[1], route[2], route[3]]))
model_result = SolverFactory('ipopt').solve(model, tee=True)

The code runs fine, but the solutions for the binary variables are not binary (not 0 or 1), it is either a zero or a random fraction :

dict_values([0.0, 0.0, 0.0, 0.0, 0.0, 0.69771460622592687, 
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
0.0, 0.0, 0.0, 0.0, 0.0,  0.0, 0.52210753137570483, 0.0, 0.0,
0.44349809775540615])

Meaning that the solution for the x variables do not stay out of the specified range.

Could someone help me understand why the binary variables go to decimals ?

How can I stop that and impose the model a set of integers for these binary variables such as [0,1] ?

And/Or if there is another way around this problem ?

Thanks All.

1

1 Answers

3
votes

First, Ipopt only solves continuous problems. It ignores the discrete status of variables and treats them as continuous between their specified bounds.

Second, even if you were to use a MIP solver (e.g., Gurobi, Cplex), it is important to account for the integer tolerance built into these solvers. They may return a value such as .999999 for a binary variable, depending what tolerance setting the solver uses. It’s a good idea to account for this when you examine the solution, perhaps by rounding the solution to an integer where appropriate.