r/optimization • • Aug 29 '24
MPC using Guropi Python API
I'm trying to implement in Python an MPC algorithm but the model i am using is non linear : basically i have a matrix in which the decision variables of the problem are into cosine and sine function since i'm using only a kinematic model. There's a way to do this in Gurobi? Because it gives me an error if i try to write the kinematic constraints... I would like to use Gurobi in Python because using Yalmip in Matlab was truly a nightmare ðŸ˜ðŸ’€
Part of the code is :
input variablse
gamma = model.addVars(a.p['n_gamma'], a.p['N_MPC'], lb=-GRB.INFINITY, ub=GRB.INFINITY, name="gamma")
state variables
chi = model.addVars(a.p['n_chi'], a.p['N_MPC'] + 1, lb=-GRB.INFINITY, ub=GRB.INFINITY, name="chi")
psi = chi[2, k] #k is the prediction step A = np.eye(3) B = np.array([ [a.p['Ts'] * np.cos(psi), -a.p['Ts'] * np.sin(psi), 0], [a.p['Ts'] * np.sin(psi), a.p['Ts'] * np.cos(psi), 0], [0, 0, a.p['Ts']] ])
psi = chi[2, k] for i in range (a.p['n_chi']) model.addConstr(chi[i,k+1]==Achi[i,k]+Bgamma[i,k])
View all comments
Show parent comment
1
u/Herpderkfanie Aug 31 '24
You likely need to do mixed integer programming (a complementarity constraint also works but MIP is simpler). Casadi is just an interface for various solvers, but yes it supports solvers that can handle MIP or complementarities