# Used to be possible for SX, but not for MX
x = MX.sym('x')
y = MX.sym('y')
f = Function('f', [vertcat(x,y)],[x+y])
# Old syntax, still valid but less efficient and less readable than the above
xy = MX.sym('xy', 2)
[x,y] = vertsplit(xy);
f = Function('f', [xy],[x+y])
states = struct_symSX( [ 'p', 'v' ])
state_unc = struct_symSX([ entry('X', shapestruct=(states,states)), ])
# This reuses previously defined variables and orders my optimisation variables in a good wayVars = struct_symMX([ ( entry("x", struct=states, repeat=[M,N+1]), entry("u", struct=controls, repeat=[M,N]), entry("X", struct=state_unc, repeat=[M,N+1]),# type='symm' if I want to impose that the matrix is symmetric ),])
# Upper and lower bounds
lbx = Vars( -np.inf )ubx = Vars( np.inf )
# Simple way to group constraintsg = struct_MX( [ entry("dyn",expr=dynconstr), entry("dynX",expr=dynconstrX), entry("v",expr=velconstr), ])
# Upper and lower bounds on the generic constraintslbg = g(0)ubg = g(0)lbg['v'] = -np.inf
sol = solver(arg)Vnum = Vars(sol['x'])gnum = g(nlp([Vnum,Pnum])[1]) # like this I can debug my code very easily!!
print gnum['dyn']
# A trick to store my simulation results in a tidy and easy to use way (could also be replaced by a dictionary)Sim_s = struct_symMX([ ( entry("x", struct=states, repeat=[M,nSim+1]), entry("u", struct=controls, repeat=[M,nSim]), entry("X", struct=state_unc, repeat=[M,nSim+1]), ),])
Sim_data = Sim_s()