mixed int programming using a multiplication

Viewed 606

I want to minimise a simple function where x1 is continuous and i1 is an integer.

The below example gives me a Can not multiply with type <class 'mip.entities.LinExpr'>

Is it really true that MIP cannot handle multiplications?

from mip import Model, CONTINUOUS, INTEGER, minimize, xsum
import numpy as np

m = Model()

def func(x1, i1):
  return (x1 - .5) * (i1 - 1)
print(func(0, 0))
print(func(.5, 1))

x1 = m.add_var(var_type=CONTINUOUS)
i1 = m.add_var(var_type=INTEGER)

# constraint
m += x1 + i1 >= 0

m.objective = func(x1, i1)
# m.objective = minimize(xsum((x1 - .5) * (i1 - 1)))

status = m.optimize()
print(status)
print(m.objective_value)

for v in m.vars:
  print(v.name, v.x)

1 Answers

You would need to use a different solver that can handle nonlinear expressions. You could use the academic solver PySCIPOpt or the commercial, free-for-academics solver Gurobi - both have a very good and intuitive Python interface that looks very similar to your code.

Related