Nonlinearly constrained problem becomes infeasible when using optimizer

42 views
Skip to first unread message

sean

unread,
Mar 12, 2018, 3:02:37 PM3/12/18
to YALMIP
Hi all, 

I am working on a distributed MPC project and currently have a nonlinear constraint. When I formulate the problem in a slow (i.e. without optimizer) manner, the problem is persistently feasible. I am trying to use "optimizer" to speed up my simulation in PLECS/Simulink; however, when I try to run it on the second iteration it becomes infeasible. I have referenced the yalmipsimulink example for how to construct the optimizer reformulation.

"test_mpc_nodewise.m" is the file to run and for node 1 there are calls to the slow and fast versions. On the second iteration the fast will return NaN due to errorcode 1.

Any pointers are appreciated, thanks!

Sean
mpc_run_nodewise_slow.m
mpc_run_nodewise.m
objective_fn.m
pflow_dynamics.m
test_mpc_nodewise.m

Johan Löfberg

unread,
Mar 12, 2018, 3:35:30 PM3/12/18
to YALMIP
First, exemplary not-minimal-but-very-structured reproducible example

The first time you call mpc_run_nodewise for t=0, you add v(1)==v_k_i to the model, and at that point v_k_i is 305. You also make v(1) a parameter in the problem. When you then call the optimizer object with a value to be replaced with v(1), you will call it with v_k_i = 2.960000000194705e+02, and v_k_i is supposed to replace the parameter v(1), so you effectively instantiate the constraint as  296=305. YALMIP detects this immediately, and returns infeasible

You seem to have mixed up something in the logic. No reason to have v(1)==v_k_i in the model (that's what you would do if you wanted to solve it for the constant value v_k_i (t==0) only). Just declare v(1) as the parameter, and you are done 

Johan Löfberg

unread,
Mar 12, 2018, 4:21:52 PM3/12/18
to YALMIP
BTW, to see what is happening, I set verbose to 2 to see fmincon iterations. In doing so, I noticed that the displayed objective differed. To fix that, in eliminatevariables, add after line 156

model.f = model.f + value'*model.Q(removethese,removethese)*value;

You also want v_neighbors_var when defining your objective in the optimizer construct, not the constant value you have at t=0

sean

unread,
Mar 12, 2018, 6:04:53 PM3/12/18
to YALMIP
Thank you so much Johan! I see how I was confused/illogical with my parameters and variables.

However, I realized I am also not using some of the variables I declared (namely "g_var", "self_id_var", and "ids_var"). However, doing this throws "Function 'subsindex' is not defined for values of class 'sdpvar' " presumably because I am indexing on them in pflow_dynamics.m. Now if I want to use the same function (mpc_run_nodewise) for nodes with different neighbors, I think I need to reconcile this issue as these are declared as parameters in the first iteration instead of as variables in the pflow_dynamics. Is there an efficient solution to this?

Best,

Sean

Johan Löfberg

unread,
Mar 13, 2018, 3:10:40 AM3/13/18
to YALMIP
Do you mean you want to do something like this?

sdpvar x k
data = [5 6];
P = optimizer([x >= data(k)],x,[],k,x);
P(2)

You would have to define that extracted value as the parameter


sdpvar x data_k
data = [5 6];
P = optimizer([x >= data_k],x,[],data_k,x);
P(data(2))




Reply all
Reply to author
Forward
0 new messages