I want to compare Gurobi and Scipy's linear programming tools, such as linprog. Scipy requires to specify problems in a matrix-list-vector-form while Gurobi works like here such that
m = Model()
m.addVar(...) %for variables
m.addConstr(..>) %for constraints
m.update() %for updating the model
m.optimize % for optimizing the model
m.params %for getting parameters
m._vars %for getting variables
in comparison Scipy
Minimize: c^T * x
Subject to: A_ub * x <= b_ub
A_eq * x == b_eq
c : array_like
Coefficients of the linear objective function to be minimized.
A_ub : array_like, optional
2-D array which, when matrix-multiplied by x, gives the values of the upper-bound inequality constraints at x.
b_ub : array_like, optional
1-D array of values representing the upper-bound of each inequality constraint (row) in A_ub.
A_eq : array_like, optional
2-D array which, when matrix-multiplied by x, gives the values of the equality constraints at x.
b_eq : array_like, optional
1-D array of values representing the RHS of each equality constraint (row) in A_eq.
bounds : sequence, optional
My goal is to write the code in only one method and still benchmark the results with both solvers. In order to speed up comparing the solvers:
Does there exist Gurobi-style model construction of LP problems for Scipy?
Does there exist some package to make the two methods interchangeable (I could write scipy-style for Gurobi or in Gurobi-style for Scipy)?
Does scipy provide any other interface to specify linear programming problems?
That sounds like a lot of work to show the obvious:
There are some ways you could do that:
abs(some_vector)
might introduce auxiliary variables)No matter what you do, solution-process analysis will be a big part of your code as linprog might fail a lot. It's also not able to handle big sparse models.
Remarks based on your gurobi-example