DAE parameter setting

257 views
Skip to first unread message

Oscar Villegas Mier

unread,
Aug 14, 2018, 11:52:03 AM8/14/18
to CasADi

Dear all.

I am working with an Optimization Problem using CasADi, based on the DAE example provided for an MINLP.

As i intend to use it in a Loop, i need to set the parameters to change each time, but i am not sure if what i have is correct. I dont get any error, and the optimization seems to start solving as i get very big solving times.

Working with linear problems, i set the parameters in my model as symbolic variables and then feed this vector to the solver, and my vector of values to the solution function. This works.

Working with the DAE part, i am not sure how to carry this parameters.

What i am doing now is:

-Defining my ODEs and my algebraic equations, with the parameters as 1x1 symbolic variables. (is a one dimensional parameter)
-Defining a DAE, based on this and sending the parameter asa vector (u,p) in the parameter part of the DAE function.

-Define the functions as f(x,zu,p)
-Define the Optimization problem with another symbolic variable for the parameters, with n time steps and set the P vector with the symbolics, and the solver with the vector of values.

I would appreciate your comments regarding this, or if there is any example where the parameters are used as I intend.

Best Regards

Oscar V.



# DAE  formulation

u = ca.SX.sym("u", nu) # Control
x = ca.SX.sym("x", nx ) # Differential states
y = ca.SX.sym("y", ny)
#Algebraic states

T_Amb = ca.SX.sym("T_Amb")
LOAD_H = ca.SX.sym("LOAD_H")

dxdt = ODE ..

f_z = Algebraic equations...

daepar
= ca.vertcat(u,T_Amb,LOAD_H)

dae = {'x':x, 'z':y, 'p':daepar, 'ode':dxdt, 'alg':f_z}

I = ca.integrator('I','collocation', dae)

f = ca.Function('f', [x, y, daepar], [dxdt,f_z], ['x', 'z', 'p'], ['ode','alg'])
fz = ca.Function('fz', [y, x, daepar], [f_z], ['z','x', 'p'], ['alg'])

N = time horizon

# Optimal control problem formulation

X = [ ca.MX.sym("x", nx) for i in range(N+1)]
U = [ ca.MX.sym("u", nu) for i in range(N)]
T_AMB = ca.MX.sym("T_AMB",N)
LOAD_H_P  = ca.MX.sym("Pth_LOAD_H_P ", N)

...

for k in range(N):
    r = I(x0=X[k],z0=z0,p=ca.vertcat(U[k],T_AMB[k],Pth_LOAD_H_P[k]))


p = ca.vertcat(T_AMB,LOAD_H_P)

p_track = ca.vertcat(T_Amb_vals,Load_vals)

nlp = {"x": ca.veccat(*V), "p": p, "f": J, "g": gaps}
solver = ca.nlpsol('solver','ipopt',nlp,opts)
solution = solver(x0 = ca.vertcat(*V_init), p = p_track, lbx = lbw, ubx = ubw, lbg = g_min, ubg = g_max)

Joris Gillis

unread,
Aug 14, 2018, 3:14:38 PM8/14/18
to CasADi
Dear Oscar,

The pattern you are using makes sense indeed if you intend to call 'solver' inside a for loop.

Best,
  Joris
Reply all
Reply to author
Forward
0 new messages