1

I have a system of linear inequalities, and I want to solve it using scipy.optomize.linprog. It's code where I call linprog function:

res = linprog(c, A_ub=A, b_ub=b, A_eq=A_eq, b_eq=b_eq, bounds=(0, 1), options={"disp": True})

It's work fine and It's solve my system, but I want that x[i] can be only 0 or 1(no fractional). It's possible to do this?

[0.0, 2.1239049166742128e-16, 0.0, 0.0, 0.5217391304347825, 1.0, 
0.0, 1.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, 1.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 
1.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, 1.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, 1.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,
0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.47826086956521746, 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, 
1.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]
Dima Kudosh
  • 7,126
  • 4
  • 36
  • 46

1 Answers1

1

Linprog is an LP solver and assumes all variables are continuous. What you are looking for is a Mixed Integer Programming solver. See here for some suggestions for calling MIP solvers from Python.

Community
  • 1
  • 1
Erwin Kalvelagen
  • 15,677
  • 2
  • 14
  • 39