Failed using CVX. Please help


#1
function [p_m_out, fval_4, flag_4] = p_m_calc_CVX(alpha, S_m_r, p_m_r, q_m_r_x, q_m_r_y)

global P_charge;
global H;
global d_min;
global V_max;
global S;
global P_max;
global freq; 
global light_speed; 
global B;
global yeta_los;
global delta2;

global K;
global M;
global N;

global R_th;

global P_user;


%%constants initialize
D_I = round(N/M);

alpha_m_n = sum(alpha,3);

O = 1/(yeta_los * (4*pi*freq/light_speed)^2);
alpha1 = reshape(alpha(:,:,1), N, M);
alpha2 = reshape(alpha(:,:,2), N, M);

A11_mk_1 = O./(H*H + (q_m_r_x - P_user(1,1)).^2 + (q_m_r_y - P_user(2,1)).^2); %p_m[n]的系数
A11_mk_2 = O./(H*H + (q_m_r_x - P_user(1,2)).^2 + (q_m_r_y - P_user(2,2)).^2);

A33_mk_r1 = log(repmat(sum((O.*p_m_r./(H*H + (q_m_r_x - P_user(1,1)).^2 + (q_m_r_y - P_user(2,1)).^2)), 2), 1, M) - O.*p_m_r./(H*H + (q_m_r_x - P_user(1,1)).^2 + (q_m_r_y - P_user(2,1)).^2) + B*delta2) ./ log(2);
A33_mk_r2 = log(repmat(sum((O.*p_m_r./(H*H + (q_m_r_x - P_user(1,2)).^2 + (q_m_r_y - P_user(2,2)).^2)), 2), 1, M) - O.*p_m_r./(H*H + (q_m_r_x - P_user(1,2)).^2 + (q_m_r_y - P_user(2,2)).^2) + B*delta2) ./ log(2);

%coefficients of (p_j[n]-p_j^r[n] in c^lb3
F_jk_r1 = O./(H*H + (q_m_r_x - P_user(1,1)).^2 + (q_m_r_y - P_user(2,1)).^2) ./  (repmat(sum((O.*p_m_r./(H*H + (q_m_r_x - P_user(1,1)).^2 + (q_m_r_y - P_user(2,1)).^2)), 2), 1, M) - O.*p_m_r./(H*H + (q_m_r_x - P_user(1,1)).^2 + (q_m_r_y - P_user(2,1)).^2) + B*delta2);
F_jk_r2 = O./(H*H + (q_m_r_x - P_user(1,2)).^2 + (q_m_r_y - P_user(2,2)).^2) ./  (repmat(sum((O.*p_m_r./(H*H + (q_m_r_x - P_user(1,2)).^2 + (q_m_r_y - P_user(2,2)).^2)), 2), 1, M) - O.*p_m_r./(H*H + (q_m_r_x - P_user(1,2)).^2 + (q_m_r_y - P_user(2,2)).^2) + B*delta2);

cvx_begin
%     cvx_solver mosek
    variable p_m(N, M)

    R_mk1 = zeros(N,1);
    R_mk2 = zeros(N,1);
    
    sum_B22_1 = zeros(N,M);
    sum_B22_2 = zeros(N,M);
    
    sum_C22_1 = zeros(N,M);
    sum_C22_2 = zeros(N,M);
    
    expression sum_B22_1(N,M)
    expression sum_B22_2(N,M)
    
    expression sum_C22_1(N,M)
    expression sum_C22_2(N,M)
    
    expression R_mk1(N,1)
    expression R_mk2(N,1)

    for m=1:1:M
        for m1=1:1:M
            if(m1~=m)
                sum_B22_1(:,m) = sum_B22_1(:,m) + A11_mk_1(:,m1) .* p_m(:,m1);
                sum_B22_2(:,m) = sum_B22_2(:,m) + A11_mk_2(:,m1) .* p_m(:,m1);
                
                sum_C22_1(:,m) = sum_C22_1(:,m) + F_jk_r1(:,m1) .* (p_m(:,m1) - p_m_r(:,m1));
                sum_C22_2(:,m) = sum_C22_2(:,m) + F_jk_r2(:,m1) .* (p_m(:,m1) - p_m_r(:,m1));
            end
        end
        R_mk1 = R_mk1 + alpha1(:,m) .* B .* (log(A11_mk_1(:,m) .* p_m(:,m) .* (1./ S_m_r(:,m)) + sum_B22_1(:,m) + B*delta2) ./ log(2) - A33_mk_r1(:,m) - sum_C22_1(:,m) );
        R_mk2 = R_mk2 + alpha2(:,m) .* B .* (log(A11_mk_2(:,m) .* p_m(:,m) .* (1./ S_m_r(:,m)) + sum_B22_2(:,m) + B*delta2) ./ log(2) - A33_mk_r2(:,m) - sum_C22_2(:,m) );
        
    end
    R_nk1 = sum(R_mk1) ./N;
    R_nk2 = sum(R_mk2) ./N;

    maximize((R_nk1 + R_nk2) ./M )
    
    subject to

        p_m >= 0;
        p_m <= P_max;

cvx_end

p_m_out = p_m;
fval_4 = cvx_optval;
flag_4 = cvx_status;

The outputs of CVX are shown as follows:

Successive approximation method to be employed.
   For improved efficiency, SDPT3 is solving the dual problem.
   SDPT3 will be called several times to refine the solution.
   Original size: 100 variables, 40 equality constraints
   20 exponentials add 160 variables, 100 equality constraints
-----------------------------------------------------------------
 Cones  |             Errors              |
Mov/Act | Centering  Exp cone   Poly cone | Status
--------+---------------------------------+---------
 20/ 20 | 8.000e+00  1.098e+02  0.000e+00 | Solved
 20/ 20 | 8.000e+00s 2.309e+01  0.000e+00 | Solved
 20/ 20 | 5.485e+00  1.660e+00  0.000e+00 | Solved
 20/ 20 | 8.000e+00s 8.875e+00s 0.000e+00 | Failed
 20/ 20 | 6.444e+00  2.838e+00  0.000e+00 | Failed
 20/ 20 | 1.294e+00  7.061e-02  0.000e+00 | Failed
 20/ 20 | 2.844e+00s 4.402e-01s 0.000e+00 | Failed
 20/ 20 | 1.403e+00  8.735e-02  0.000e+00 | Failed
  0/  0 | 0.000e+00  0.000e+00  0.000e+00 | Failed
-----------------------------------------------------------------
Status: Failed
Optimal value (cvx_optval): NaN

Please help me. Thanks in advance.


#2

The formulation are shown as:
image
image
where the sum_{k=1}^K \alpha_{m,k}[n] was replaced by S_m_r(:,m).


(Mark L. Stone) #3

Follow the advice in


and let us know how it works out.


#4

Dear Mark
Many thanks for your help. I already install the CVXQUAD, raplace the exponential.m and add path to the MATLAB. However the problem still exist. I think this is because the log(sum[]) function in my code. May there be any alternative expression of the log(sum[]) function to invoke the pade approximation of the CVXQUAD?
Thanks again.


(Mark L. Stone) #5

Just replace
log(expression)
with
-rel_entr(1,expression)
as described in the link.


#6

Dear Mark
Thanks for your advice. The CVXQUAD is worked. However, the output is still failed. Is there any other wrong?

=====================================
Using Pade approximation for exponential
cone with parameters m=3, k=3
=====================================
=====================================
Using Pade approximation for exponential
cone with parameters m=3, k=3
=====================================
=====================================
Using Pade approximation for exponential
cone with parameters m=3, k=3
=====================================
=====================================
Using Pade approximation for exponential
cone with parameters m=3, k=3
=====================================
 
Calling Mosek 8.0.0.60: 158 variables, 52 equality constraints
   For improved efficiency, Mosek is solving the dual problem.
------------------------------------------------------------

MOSEK Version 8.0.0.60 (Build date: 2017-3-1 13:09:33)
Copyright (c) MOSEK ApS, Denmark. WWW: mosek.com
Platform: Windows/64-X86

Problem
  Name                   :                 
  Objective sense        : min             
  Type                   : CONIC (conic optimization problem)
  Constraints            : 52              
  Cones                  : 24              
  Scalar variables       : 158             
  Matrix variables       : 0               
  Integer variables      : 0               

Optimizer started.
Conic interior-point optimizer started.
Presolve started.
Linear dependency checker started.
Linear dependency checker terminated.
Eliminator started.
Freed constraints in eliminator : 6
Eliminator terminated.
Eliminator started.
Freed constraints in eliminator : 0
Eliminator terminated.
Eliminator - tries                  : 2                 time                   : 0.00            
Lin. dep.  - tries                  : 1                 time                   : 0.02            
Lin. dep.  - number                 : 0               
Presolve terminated. Time: 0.06    
Optimizer  - threads                : 2               
Optimizer  - solved problem         : the primal      
Optimizer  - Constraints            : 46
Optimizer  - Cones                  : 25
Optimizer  - Scalar variables       : 153               conic                  : 113             
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 : 438               after factor           : 450             
Factor     - dense dim.             : 0                 flops                  : 9.22e+003       
ITE PFEAS    DFEAS    GFEAS    PRSTATUS   POBJ              DOBJ              MU       TIME  
0   2.5e+006 1.7e+000 1.5e+001 0.00e+000  5.489230796e+001  0.000000000e+000  1.0e+000 0.14  
1   4.4e+005 3.0e-001 1.1e+000 -1.00e+000 4.772194964e+002  4.414557541e+002  1.7e-001 0.23  
2   3.5e+004 2.4e-002 2.4e-002 -1.00e+000 7.004313411e+003  7.230491813e+003  1.4e-002 0.23  
3   3.2e+001 2.2e-005 6.6e-007 -1.00e+000 7.814884644e+006  8.128069753e+006  1.3e-005 0.25  
4   6.2e+000 4.2e-006 6.4e-008 -9.38e-001 3.585821114e+007  3.712473036e+007  2.5e-006 0.25  
5   3.4e+000 2.3e-006 3.9e-008 -2.04e-001 3.229294932e+007  3.333295996e+007  1.3e-006 0.27  
6   1.0e+000 7.1e-007 2.2e-008 3.61e-001  3.382874136e+007  3.414045547e+007  4.1e-007 0.27  
7   5.8e-001 4.0e-007 1.4e-008 9.84e-001  2.986317555e+007  3.009570056e+007  2.3e-007 0.28  
8   1.7e-001 1.1e-007 6.8e-009 1.04e+000  2.567873629e+007  2.576069580e+007  6.6e-008 0.28  
9   7.5e-002 5.1e-008 3.4e-009 6.15e-001  2.377086799e+007  2.383636147e+007  3.0e-008 0.30  
10  2.3e-002 1.6e-008 1.4e-009 5.96e-001  2.183464949e+007  2.187034446e+007  9.2e-009 0.31  
11  1.1e-002 7.5e-009 6.7e-010 3.94e-001  2.091468053e+007  2.095128629e+007  4.4e-009 0.31  
12  3.9e-003 2.6e-009 2.9e-010 4.10e-001  1.976748942e+007  1.979183294e+007  1.5e-009 0.33  
13  2.1e-003 1.4e-009 1.4e-010 1.96e-001  1.920661418e+007  1.923663085e+007  8.3e-010 0.33  
14  5.8e-004 4.0e-010 4.9e-011 3.09e-001  1.803785296e+007  1.805754150e+007  2.3e-010 0.34  
15  2.2e-004 1.5e-010 1.7e-011 1.63e-001  1.726930763e+007  1.729272669e+007  8.9e-011 0.36  
16  7.6e-005 5.2e-011 6.8e-012 2.77e-001  1.641277897e+007  1.643006193e+007  3.0e-011 0.36  
17  3.7e-005 2.5e-011 2.8e-012 6.07e-002  1.588300481e+007  1.590652289e+007  1.5e-011 0.37  
18  9.7e-006 6.6e-012 8.8e-013 2.35e-001  1.484467957e+007  1.486107026e+007  3.8e-012 0.37  
19  3.1e-006 2.1e-012 2.6e-013 1.07e-001  1.403845786e+007  1.405899987e+007  1.2e-012 0.39  
20  1.1e-006 7.6e-013 1.0e-013 2.42e-001  1.327865047e+007  1.329481064e+007  4.4e-013 0.39  
21  5.5e-007 3.8e-013 4.3e-014 6.19e-004  1.280216918e+007  1.282516396e+007  2.2e-013 0.41  
22  1.3e-007 9.2e-014 1.3e-014 2.16e-001  1.173754932e+007  1.175349401e+007  5.4e-014 0.41  
23  3.7e-008 2.5e-014 3.1e-015 9.86e-002  1.084719653e+007  1.086712321e+007  1.5e-014 0.42  
24  1.4e-008 9.6e-015 1.3e-015 2.55e-001  1.014781612e+007  1.016421209e+007  5.6e-015 0.42  
25  7.5e-009 5.1e-015 5.6e-016 -5.35e-002 9.756077485e+006  9.779632934e+006  3.0e-015 0.44  
26  1.8e-009 1.3e-015 1.8e-016 2.05e-001  8.688095824e+006  8.704535119e+006  7.3e-016 0.44  
27  6.5e-010 4.4e-016 7.6e-017 1.07e-001  7.993530166e+006  8.011638003e+006  2.6e-016 0.45  
28  1.8e-010 1.3e-016 9.3e-018 1.24e-001  7.100754657e+006  7.118981705e+006  7.3e-017 0.45  
29  5.7e-011 3.9e-017 1.8e-017 1.82e-001  6.321910325e+006  6.338849354e+006  2.3e-017 0.47  
30  2.9e-011 2.0e-017 1.5e-017 3.09e-003  5.888367374e+006  5.910652865e+006  1.1e-017 0.48  
31  1.3e-011 5.2e-018 3.5e-017 2.23e-001  4.940161259e+006  4.955648801e+006  3.0e-018 0.48  
32  8.5e-012 2.1e-018 2.0e-017 9.84e-002  4.365715969e+006  4.383256355e+006  1.2e-018 0.50  
33  3.1e-012 1.3e-018 2.3e-017 1.80e-001  4.059523221e+006  4.075918894e+006  7.7e-019 0.50  
34  2.1e-012 1.2e-018 2.0e-017 1.56e-001  3.996448869e+006  4.012633431e+006  7.0e-019 0.51  
35  1.8e-012 1.2e-018 2.2e-017 1.50e-001  3.996215007e+006  4.012398793e+006  7.0e-019 0.51  
36  1.8e-012 1.2e-018 2.2e-017 1.50e-001  3.996215007e+006  4.012398793e+006  7.0e-019 0.53  
Interior-point optimizer terminated. Time: 0.53. 

Optimizer terminated. Time: 0.87    

Interior-point solution summary
  Problem status  : UNKNOWN
  Solution status : UNKNOWN
  Primal.  obj: 3.9962150072e+006   nrm: 3e+012   Viol.  con: 6e-001   var: 0e+000   cones: 0e+000 
  Dual.    obj: 4.0123987933e+006   nrm: 4e+006   Viol.  con: 0e+000   var: 2e-007   cones: 0e+000 
Optimizer summary
  Optimizer                 -                        time: 0.87    
    Interior-point          - iterations : 37        time: 0.53    
      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: Failed
Optimal value (cvx_optval): NaN

(Michal Adamaszek) #7

It looks like your primal has extremely large norm (3e+12) so Mosek has numerical problems and stalls. You probably have to rescale, or it may be an indication that the problem is unbounded. You can also try a solver that natively supports the exponential cone, like Mosek version 9 (although not through cvx?).


#8

Dear Michal
Thanks for your guidance. But, I have no idea how to rescale. Can you give me some examples. Thanks again.


(Erling D.Andersen) #9

Rescaling means choosing another units for the variables e.g. tons instead of kg. Similar for the constraints.

Btw the problem might also be an attainment issue like if you do

\frac{1}{x} \leq 0.0, x \geq 0.

Clearly x has to be very large in any feasible solution. You may something along these lines in your model.

I suggest you think harder about your model to see whether it make sense from engineering point of view.


CVX using MOSEK bug
#10

Dear Erling
Thanks for your guidance. I wll try your way to check my model. I hope it will work, Thanks again.