I'm looking for some help to optimize my code execution.
I build up a Model Predictive Control and I use Gurobi QP solver to solve the QP problem on-line.
For each sample time the code create a new model, variables and constrains. The structure of the problem doesn't change during a single simulation, but change the value of coefficients of constraints and objective function.
I want to find a way to update this coefficients due to reduce the time execution of the solver.
Now more than 60% of time execution was passed in build new constrain each time.
In the code example, the QP problem is:
Objective function: x^t H x + F^t x ||| Constrains: A x <= b
F,A and b are matrix that change each time step.
import numpy as N
import gurobipy as gpy
m=gpy.Model()
H=mpcSim.H
A_cons=N.asarray(mpcSim.A_cons)
b=N.asarray(mpcSim.b)
F=mpcSim.F
n_cons,n_stato=A_cons.shape
x={}
for ii in range(n_stato):
x[ii]=m.addVar(lb=-1e20,ub=1e20,name='x{}'.format(ii))
m.update()
for ii in range(n_cons):
m.addConstr(gpy.quicksum(A_cons[ii,jj]*x[jj] for jj in range(n_stato)), gpy.GRB.LESS_EQUAL, b[ii,0],name='Const{}'.format(ii))
m.update()
obj1=gpy.quicksum(gpy.quicksum(H[ii,jj]*x[ii] for ii in range(n_stato))*x[jj] for jj in range(n_stato))
obj2=gpy.quicksum(F[ii,0]*x[ii] for ii in range(n_stato))
m.setObjective(obj1+obj2)
m.optimize()Thanks in advance,
Jack
% Read a example model, comes along with Gurobi installation
model = gurobi_read('afiro.mps.bz2');
% Solve it, print objective value
result = gurobi(model);
disp(result.objval);
% Save a copy of original model
model_org = model;
% Fix some variable to some value
model.lb(5) = 15.0;
model.ub(5) = 15.0;
% Solve again, objective value now larger
result = gurobi(model);
disp(result.objval);
--
---
You received this message because you are subscribed to a topic in the Google Groups "Gurobi Optimization" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/gurobi/89FfTQo48qg/unsubscribe.
To unsubscribe from this group and all its topics, send an email to gurobi+un...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.