Why CVX ignore the constraints while giving 'Solved'

Hello:)

While I tried to solve the optimization problem for my research, I found some errors in data that came from the CVX_solver. So I made a very simple problem to check whether I or CVX is wrong.

For simple explanation, the problem I made is related to UAV trajectory, which tries to minimize the distance between AP and UAV, while satisfying the constraints for maximum velocity and flying energy budget. The problem consists of just one optimization variable, UAV position.

For the outcome, CVX shows the ‘Solved’ with no error description. But, when I check the flying energy from the optimal position of the UAV, solved from the CVX, I found that it violate the constraints that I defined at the CVX. (I think the trouble comes the fact that the velocities that are calculated from the CVX is different from the velocities that are calculated from the optimized variable (position of UAV). )

Here are my code and result, please give me some advice to this trouble…

clear all

T = 40; % Mission time
N_s = 40; % # of frames
t_s = T/N_s; % duration of frame in sec
v_max = 5; % UAV velocity in m/s
H = 80;
mu = 9.65;

p_UI = [-200,0]’;
p_UF = [200,0]’;
p_AP = [0,100]’;
E_th = 5e3;

cvx_begin

cvx_solver mosek

variable p_U(2,N_s+1)
expression d_UA_sq(1,N_s+1)
expression v_U_sq(1,N_s)
expression E_F_U(N_s)

for n = 1 : N_s+1
d_UA_sq(n) = H^2 + norm(p_AP - p_U(:,n),2);
end

for n = 1 : N_s
v_U_sq(n) = norm(p_U(:,n+1) - p_U(:,n),2) /t_s^2; %norm(p_U(:,n+1) - p_U(:,n)) / t_s;
end

for n = 1 : N_s
E_F_U(n) = 1/2mut_sv_U_sq(n); % 1/2mut_spow_pos(v_U(n),2);
end

minimize(sum(d_UA_sq))

subject to

sum(E_F_U) <= E_th;
p_U(:,1)==p_UI;
p_U(:,N_s+1)==p_UF;
for n = 1 : N_s
v_U_sq(n) <= (v_max)^2;
end

cvx_end

%%%%%Comparison between CVX data and real value%%%%%

v_U_update=zeros(1,N_s);
E_F_U_update=zeros(1,N_s);
d_UA_sq_update=zeros(1,N_s+1);

for n = 1 :N_s

v_U_update(n)=norm(p_U(:,n+1) - p_U(:,n)) / t_s;
v_U_sq_update(n) = norm(p_U(:,n+1) - p_U(:,n),2) /t_s^2;
E_F_U_update(n) = 1/2*mu*t_s*(v_U_update(n).^2);

end

for n = 1 :N_s+1

d_UA_sq_update(n) = H^2 + pow_abs(p_AP(1) - p_U(1,n),2) + pow_abs(p_AP(2) - p_U(2,n),2);

end

sum(E_F_U)
sum(E_F_U_update)

Calling Mosek 9.1.9: 284 variables, 125 equality constraints

MOSEK Version 9.1.9 (Build date: 2019-11-21 11:34:40)
Copyright © MOSEK ApS, Denmark. WWW: mosek.com
Platform: Windows/64-X86

Problem
Name :
Objective sense : min
Type : CONIC (conic optimization problem)
Constraints : 125
Cones : 81
Scalar variables : 284
Matrix variables : 0
Integer variables : 0

Optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator - tries : 1 time : 0.00
Lin. dep. - tries : 1 time : 0.00
Lin. dep. - number : 0
Presolve terminated. Time: 0.00
Problem
Name :
Objective sense : min
Type : CONIC (conic optimization problem)
Constraints : 125
Cones : 81
Scalar variables : 284
Matrix variables : 0
Integer variables : 0

Optimizer - threads : 6
Optimizer - solved problem : the primal
Optimizer - Constraints : 80
Optimizer - Cones : 79
Optimizer - Scalar variables : 237 conic : 237
Optimizer - Semi-definite variables: 0 scalarized : 0
Factor - setup time : 0.00 dense det. time : 0.00
Factor - ML order time : 0.00 GP order time : 0.00
Factor - nonzeros before factor : 276 after factor : 276
Factor - dense dim. : 0 flops : 2.63e+03
ITE PFEAS DFEAS GFEAS PRSTATUS POBJ DOBJ MU TIME
0 2.0e+02 0.0e+00 1.0e+03 0.00e+00 4.862135955e+02 -5.527864045e+02 1.0e+00 0.00
1 7.5e+01 3.4e-15 6.3e+02 -9.76e-01 5.519173078e+02 -4.667122551e+02 3.8e-01 0.00
2 3.5e+01 2.4e-13 4.1e+02 -9.40e-01 7.025435939e+02 -2.721381914e+02 1.8e-01 0.00
3 8.7e+00 6.8e-14 1.7e+02 -8.45e-01 1.409531547e+03 6.545709727e+02 4.3e-02 0.00
4 2.5e+00 3.3e-14 4.7e+01 -3.01e-01 2.047057003e+03 1.681016361e+03 1.2e-02 0.00
5 8.9e-01 8.7e-15 1.0e+01 5.64e-01 2.143280194e+03 1.994445657e+03 4.4e-03 0.00
6 1.8e-01 8.4e-15 9.8e-01 8.33e-01 2.203108652e+03 2.170544234e+03 9.1e-04 0.00
7 9.6e-02 3.5e-15 3.8e-01 9.69e-01 2.214871881e+03 2.197592606e+03 4.8e-04 0.00
8 4.2e-03 1.1e-14 3.6e-03 9.82e-01 2.224521933e+03 2.223757919e+03 2.1e-05 0.00
9 4.8e-06 1.0e-13 1.4e-07 1.00e+00 2.224921946e+03 2.224921082e+03 2.4e-08 0.00
10 6.0e-11 2.1e-12 1.7e-12 1.00e+00 2.224922359e+03 2.224922359e+03 3.0e-13 0.00
Optimizer terminated. Time: 0.02

Interior-point solution summary
Problem status : PRIMAL_AND_DUAL_FEASIBLE
Solution status : OPTIMAL
Primal. obj: 2.2249223595e+03 nrm: 5e+03 Viol. con: 2e-09 var: 0e+00 cones: 8e-21
Dual. obj: 2.2249223595e+03 nrm: 8e+00 Viol. con: 0e+00 var: 8e-11 cones: 0e+00
Optimizer summary
Optimizer - time: 0.02
Interior-point - iterations : 10 time: 0.02
Basis identification - time: 0.00
Primal - iterations : 0 time: 0.00
Dual - iterations : 0 time: 0.00
Clean primal - iterations : 0 time: 0.00
Clean dual - iterations : 0 time: 0.00
Simplex - time: 0.00
Primal simplex - iterations : 0 time: 0.00
Dual simplex - iterations : 0 time: 0.00
Mixed integer - relaxations: 0 time: 0.00


Status: Solved
Optimal value (cvx_optval): +264625

ans =

    4825

ans =

5.3628e+04

CVX expressions are not recomputed after optimization so looking at sum(E_F_U) does not make sense. The correct approach is to recompute it from variable values, exactly as you do with E_F_U_update.

There is also something confusing about your use of square here and there. norm(..., 2) and norm(...) are the same 2-norm, there is nothing squared about it, so your notation, model, and the update computation are a bit contradictory to one another with respect to squaring. but maybe that’s just a matter of cleaning up the code.

You just hit the spot! Thanks for your answer.
I missed that ‘norm( ,2)’ means just making a two-norm, not making a two-norm and squaring it.
so I changed the term into

for n = 1 : N_s
v_U_sq(n) = square_pos(norm(p_U(:,n+1) - p_U(:,n))) /t_s^2;
end

and it works well.

Also, It is really helpful to learn that recomputing the value from the optimized variable is the right way.