Conceptual help with CVX


As a part of my research, I am considering a scenario where some of the control inputs are blocked-predetermined (implemented as constraints) whereas other control inputs are to be determined. These control inputs depend on one another. Consider the following:

I am trying to find optimal control inputs (U) for multiple (controllable) vehicles amongst other (uncontrollable) vehicles using MPC. To ensure collision avoidance at each instant (distance between vehicles > 0):

  1. at each instant, the system is informed about the control inputs (and thus the state variables) of uncontrolled vehicle/s corresponding to that istant. When I run this in CVX, CVX returns result as infeasible.

  2. the system has information about the control inputs of uncontrolled vehicle/s for the entire simulation horizon (all instances). When I run this in CVX, CVX returns result as solved.

Can case 1 be solved using CVX ? The matlab code is rather long, so I choose to skip, but in case it is required, I can upload it as well.

In real life online-application, a system will take fresh inputs at each instant (case 1 above) to solve MPC and provide control input. Is it also possible to get control inputs generated by CVX at each instant, rather than obtaining control inputs (of all instances in the time horizon) at once at the end of the optimization?

Any help or inputs would be greatly appreciated :slightly_smiling_face:

(Michael C. Grant) #2

I’m afraid this simply isn’t the right forum for this question. This isn’t the place to bring general or domain-specific modeling issues; you should seek a forum devoted to your particular application (MPC). If you are having specific trouble with models in CVX, then you should consider posting the model itself, and what you expected CVX to do.


Hello Michael,

Many thanks for your reply. I managed to solve the issue (case 1 and case 2 above) by rephrasing the optimization problem. More importantly, when there is an optimization problem over an horizon (N), I want to know whether I can get outputs ‘U’ from CVX (control inputs ‘U’ for the system) at each instant (i = [1 … N-1]) rather than getting them all together at the end of the simulation, for real time implementation? I suppose the creators of the tool CVX would be best to help.

Here is a sample code:

cvx begin
variables U(nv,N) ; % N = time horizon ; nv = number of vehicles
expressions X(2*nv,N) d_bw_vehicles(nv-1,N) U_diff(nv,N-1); % X(:,1) = [p1; v1] (position and velocity tuple); U is acceleration

for i = 1: N-1 % over time horizon of N instants,

X(1:2*nv,n+1) = bigA*X(1:2*nv,n)+ bigB*U(1:nv,n); % A,B are state matrices;

for c = 1:nv-1  % c= car count
    d_bw_vehicles(c,n+1) = X(2*c+1,n+1) - X(2*c-1,n+1) 

    if n>1 % Braking constraint
        -0.25<= (U(:,n)-U(:,n-1))<= 0.25;

if n >1  % used in optimization function
    U_diff(:,n)= U(:,n)-U(:,n-1);


% Some constraints
X(1:2:2nv,:)>=0; % location at all time x >0
nv,:)>=0; % velocity at all times >0

% Boundary conditions
X(:,1)=X_initial; %initial location and velocity;
U(:,1)== exp(-9); % initial acc =0;
X(2:2:2*nv,N)== exp(-9); % final velocity of all vehicles = 0

%Optimization problem

cvx end

Best Regards,