Simple LP problem
AnsweredHi all,
I am trying to solve a simple LP problem, as below:
min V = transpose(L)*a
a,q
s.t. Bq = f
−σ −a ≤ q
+σ +a ≥ q
a ≥ 0,
V is the volume of an imagined truss structure, with L and a being vectors containing the lengths and cross section areas of all the members in the truss [L1, L2, ..., Lm] and [a1, a2, ..., am]. q is the force in each member [q1, q2, ..., qm] and f is some external applied force [f1x , f1y , f1z, f2x , f2y , f2z, ..., fnx, fny , fnz] on a discritized set of nodes n in the design space. σ + and σ − are some arbitrary limits. B is an equilibrium matrix relating q and f. The optimization variables are a and q.
I tried the following code but to no avail. I am confident all the matrix and vectors are correct as I can get an answer from cvxpy so I think it is just some error to do with the Gurobi API. Any advice would be welcome.
m = Model()
m.modelSense = GRB.MINIMIZE
q = m.addMVar(shape=len(Cn), lb=-GRB.INFINITY, ub=GRB.INFINITY, vtype=GRB.CONTINUOUS, name="q")
a = m.addMVar(shape=len(Cn), lb=0.0, ub=GRB.INFINITY, vtype=GRB.CONTINUOUS, name="a")
m.update()
m.addConstr(a >= 0.0)
m.addConstr(q >= -sigC*a)
m.addConstr(q <= sigT*a)
m.addConstr(B@q == F)
m.setObjective(np.transpose(L)@a)
m.optimize()
Warning for adding constraints: zero or small (< 1e-13) coefficients, ignored
Gurobi Optimizer version 9.0.3 build v9.0.3rc0 (win64)
Optimize a model with 63 rows, 30 columns and 109 nonzeros
Model fingerprint: 0xa09758e5
Coefficient statistics:
Matrix range [4e-01, 1e+00]
Objective range [1e+00, 2e+00]
Bounds range [0e+00, 0e+00]
RHS range [1e+00, 1e+00]
Presolve removed 1 rows and 0 columns
Presolve time: 0.02s
Solved in 0 iterations and 0.02 seconds
Infeasible model
-
Official comment
This post is more than three years old. Some information may not be up to date. For current information, please check the Gurobi Documentation or Knowledge Base. If you need more help, please create a new post in the community forum. Or why not try our AI Gurobot?. -
Hi James,
Some variables are not defined (sigT, B, and F), so it's hard to see why the model would be infeasible and your code is also not reproducible.
I recommend you write out the generated model as LP file and check whether it is actually what you intended to model:
m.write('model.lp')Cheers,
Matthias0 -
Thanks Matthias for the advice re. m.write()
I am looking into it now!
James
0 -
In addition to that, the warning
Warning for adding constraints: zero or small (< 1e-13) coefficients, ignored
indicates that you might have run into numerical trouble when creating the model.
Maybe, you can scale your coefficients to some reasonable range. If not, it might become hard to solve your problem using a floating point solver like Gurobi.
0 -
Hi Thomas,
'might have run into numerical trouble when creating the model.'
Yes I believe it was this, an error in B somewhere. Have managed to solve this now, thanks!
James
0
Post is closed for comments.
Comments
5 comments