How can i set a Variable constraints

Am I right that you want to set variable constraints (different for each shooting node) for a part of your state vector x?

You can do this with the .set() method of the ocp-solver object whilst working with parameters as constraint variables.

Heres a quick example:

# set constraints in init phase
p_lb = cs.SX.sym('p_lb')
p_ub = cs.SX.sym('p_ub')
ocp.constraints.lb = [1, 1, p_lb, 1]
ocp.constraints.ub = [5, 5, p_ub, 5]
ocp.model.parameter = cs.vertcat([p_lb, p_ub])
...

# set parameter p_lb and p_ub in control cycle
param_values = [ [1, 1], [2, 2], [3, 3], ..., [n, n]]

# set parameter values (which define constraints for x2) for each node
for n in range(N):
   ocp_solver.set(n, 'p', param_values[n])

this is just a short example that should suit your needs. You have to dive deeper into how to formulate those parameters of course :slight_smile:

1 Like