Error using mpt to simulate MPC controller

243 views
Skip to first unread message

Greg Marcil

unread,
Feb 23, 2016, 10:06:41 PM2/23/16
to YALMIP
I just installed the mpt toolbox along with the recommended supporting packages here (http://control.ee.ethz.ch/~mpt/3/Main/Installation). Yalmip seems to be installed correctly, as yalmiptest runs successfully. I am using Matlab R2015b.

When I try to run the attached code (which sets up an LTISystem and creates an MPCController, then runs controller.evaluate on a pair of infeasible points), however, I get an error from optimizer/subsref.m within yalmip. The stack trace is below:

Error using reshape
To RESHAPE the number of elements must not change.
Error in optimizer/subsref (line 211)
        varargout{1} = reshape(u(:),self.dimoutOrig{1});
Error in MPCController/evaluate (line 121)
[U, status] = obj.optimizer{xinit};
Error in errorTest (line 22)
[u, feasible, openloop] = ctrl.evaluate([3;3]);

The problem is that yalmip tries to reshape u with dimoutOrig{1}, but u has not been set. The problem begins at line 159 of subsref.m when

output = self.model.solver.callhandle(self.model);


runs callquadprog.m, which ultimately calls out to Matlab's quadprog solver. 


In the case of the problematic point, [3;3], quadprog returns an empty x and the following output at line 63 of callquadprog.m


          algorithm: 'interior-point-convex'

         iterations: 0

       cgiterations: []

    constrviolation: []

      firstorderopt: []

            message: 'The problem is infeasible.…'


For comparison, the point [3;2] is also infeasible but runs without error, and quadprog returns an x of the appropriate dimension and the following output


            message: 'No feasible solution found.…'

          algorithm: 'interior-point-convex'

      firstorderopt: 4.8901e+07

    constrviolation: 1.2786

         iterations: 6

       cgiterations: []


The returned x values are set as Primal and passed back to subsref.m. Lines 167-187 of subsref.m seem to be where u is set to a vector full of NaN, but my failure example does not have an empty self.output.z and then is not handled at all by the else block at line 177 because output.Primal is empty, so u remains equal to an empty vector.


At this point, I am not sure if what I'm seeing is unexpected behavior from quadprog, a bug in the logical structure of lines 167-187 (which doesn't address the possibility that self.output.z may not be empty when output.Primal is empty, although possibly this state is logically inconsistent), or user error, either on my part of that of MPT. Any advice would be greatly appreciated.


Greg

errorTest.m

Johan Löfberg

unread,
Feb 24, 2016, 2:52:49 AM2/24/16
to YALMIP
Yes, quadprog and friends are famous for changing stuff constantly. In my develop branch, I've added

if isempty(x)
    x = nan(length(model.c),1);    
end  

at line 72 in callquadprog, to account for matlab 2015b

Johan Löfberg

unread,
Feb 24, 2016, 2:53:16 AM2/24/16
to YALMIP
You should install a better LP/QP solver though

Greg Marcil

unread,
Feb 24, 2016, 4:21:07 AM2/24/16
to YALMIP
Thanks for your quick reply and advice, Johan!

Shilp Dixit

unread,
Apr 21, 2016, 9:32:59 AM4/21/16
to YALMIP
Apologies for high-jacking the thread.

I am facing the same issue as explained in the post above. I made the changes in callquadpog.m as suggested by you but it turns out, my subsref.m is not calling callquadprog.m!

Next I tried to set
mptopt('lpsolver', 'CDD', 'qpsolver', 'QUADPROG');
at the beginning of the code but to no avail. How can I solve this issue?

Thanks!


Johan Löfberg

unread,
Apr 21, 2016, 9:35:44 AM4/21/16
to YALMIP
To control solver selection in YALMIP, you use sdpsettings

If you re talking about mpt specific code, you should post the question on MPT Google groups

Shilp Dixit

unread,
Apr 21, 2016, 9:43:23 AM4/21/16
to YALMIP
I also try to run the attachment code provided by the OP. Even that doesn't work after I make the suggested changes in callquadprog.m

I will look into sdpsettings.

Thank you for the suggestions.

Johan Löfberg

unread,
Apr 21, 2016, 9:48:03 AM4/21/16
to YALMIP
What happens ? The particular instances above are both infeasible and should return u=nan

Shilp Dixit

unread,
Apr 21, 2016, 9:57:47 AM4/21/16
to YALMIP
Yes. for both the cases u = empty 0X0 double.

I placed a breakpoint on line 72 of callquaprog.m but what I experience is that the breakpoint is not reached and I get the same error as posted by the OP.

Johan Löfberg

unread,
Apr 21, 2016, 10:01:42 AM4/21/16
to YALMIP
If you want to debug things, you'll have to put a break on @optimizer/subsref line 161 and step into the solver call and see where you end up and what happens

Shilp Dixit

unread,
Apr 21, 2016, 10:05:58 AM4/21/16
to YALMIP
Ok I will try to look into the solver call. Hopefully find out the issue.

Thanks!
Reply all
Reply to author
Forward
0 new messages