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
514 stars 89 forks source link

Is it possible to set different types of integrality constraints? #277

Open hlukashonak opened 2 years ago

hlukashonak commented 2 years ago

Dear MIP Team,

thank you for the package! I am familiarizing myself with it and unfortunately I was not able to find the answer in the documentation. Is it possible to set various integrality constraints modes in MIP? (like e.g. in milp from scipy):

integrality 1D array_like, optional Indicates the type of integrality constraint on each decision variable. 0 : Continuous variable; no integrality constraint. 1 : Integer variable; decision variable must be an integer within bounds. 2 : Semi-continuous variable; decision variable must be within bounds or take value 0. 3 : Semi-integer variable; decision variable must be an integer within bounds or take value 0.

I found only the relax parameter of the optimize function, but this is not enough for my problem (I actually want to implement the case 3 of the listed above)

Many thanks!

rschwarz commented 2 years ago

I don't think so. In the documentation of Var, the property var_type just gives the options:

(‘B’) BINARY, (‘C’) CONTINUOUS and (‘I’) INTEGER.

sebheger commented 2 years ago

It is not possible yet. The official gurobi python api supports the requested variable definition.

At this point, I have to remark, that the requested variable definition is just a "convenience" feature. You can use a pure integer variable and binary variable together with a set of constraints to model such semi-integer variables.