coin-or / python-mip

Python-MIP: collection of Python tools for the modeling and solution of Mixed-Integer Linear programs
Eclipse Public License 2.0
518 stars 92 forks source link

Does Continuous variable default to be > 0? #159

Closed zuzhaoye closed 2 years ago

zuzhaoye commented 3 years ago

Describe the bug Does Continuous variable default to be > 0?

To Reproduce

from mip import *

m = Model(sense=MINIMIZE, solver_name=CBC) # use GRB for Gurobi
n = 5
x = [m.add_var(var_type=CONTINUOUS) for i in range(n)]

for i in range(n):
    m += x[i] <= -1
    m += x[i] >= -2

m.objective = xsum(x[i] for i in range(n))

m.max_gap = 0.05
status = m.optimize(max_seconds=300)

print(status)
print(m.objective_value)

Expected behavior Expect:

OptimizationStatus.OPTIMAL
-10

But get:

OptimizationStatus.INFEASIBLE
None

Desktop (please complete the following information):

Additional context

If I add a lower bound in definition, then everything works.

M = 1e5 # any large number
x = [m.add_var(var_type=CONTINUOUS, lb = -M) for i in range(n)]
jurasofish commented 3 years ago

Does Continuous variable default to be > 0?

yea, https://docs.python-mip.com/en/latest/classes.html#mip.Model.add_var

zuzhaoye commented 3 years ago

Does Continuous variable default to be > 0?

yea, https://docs.python-mip.com/en/latest/classes.html#mip.Model.add_var

Oh, I see. You default lb to be 0. No more question, appreciate it.