Failed status and optimal value NAN in convex problem


(dariush) #1

I had solve the convex problem, when I added the following codes the cvx_status changes to Failed.
objfunc=cvx(zeros(N,K,M));

and also

if E_km(k)< energy_threshold
objfunc(n,k,m)=0;
end

The complete codes are as follows:

M=3;
N=2;
K=4;
E0=1;
N0=10^-16;
Bw=100e6;

pmax_r=2;
pr_max=pmax_rones(1,M);
min_user_rate=0;
e_avail=E0
ones(1,K,M);
J_nor=10rand(N,K,M);
landa=0.005;
energy_threshold=6e-4;
b_nkm_old(:,:,1)=[ 1 1 0 0;1 0 1 0];
b_nkm_old(:,:,2)=[ 1 0 1 0;1 1 0 0];
b_nkm_old(:,:,3)=[ 0 0 1 1;0 1 1 0];
e_avail(:,:,1)=[5 0 5 0];
e_avail(:,:,2)=[5 5 0 0];
e_avail(:,:,3)=[0 0 5 5];
p_rrh_old=(pmax_r/2)ones(N,M);
alfa_old=[.5 .5 .5];
landa=.5;
R_rrh_min=.4;
e_nkm_old=.5
ones(N,K,M);
rrh_fad=100
rand(N,M);

cvx_begin
variables e_nkm(N,K,M) pr(N,M)
cnr=rrh_fad./(N0*Bw);
tr=log(1+cnr.*pr);
r_rrh=cvx(zeros(N,M));
objfunc=cvx(zeros(N,K,M));

for m=1:M
E_km=e_avail(:,:,m);
r_rrh(:,m)=((1-alfa_old(m))tr(:,m));
for n=1:N
% obj2=r_rrh-landa
pr(n,m)
for k=1:K
check=J_nor(n,:,m)>=J_nor(n,k,m);
say= log(1+sum(((J_nor(n,:,m).*b_nkm_old(n,:,m).*e_nkm(n,:,m).*check.*E_km)/alfa_old(m)))+(J_nor(n,k,m)*b_nkm_old(n,k,m)*e_nkm(n,k,m)*E_km(1,k)));
omega=alfa_old(m)*log(1+sum(((J_nor(n,:,m).*b_nkm_old(n,:,m).*e_nkm_old(n,:,m).*check.*E_km)/alfa_old(m))));

        %             if E_km(k)< energy_threshold
        %                 objfunc(n,k,m)=0;
    end
    for i=1:K
        if(i~=k)
            gerad_e=(J_nor(n,i,m)*b_nkm_old(n,i,m)*E_km(1,i))/(1+sum(((J_nor(n,:,m).*b_nkm_old(n,:,m).*e_nkm_old(n,:,m).*check.*E_km)/alfa_old(m))));
        else
            gerad_e=0;
            omega_hat=omega+gerad_e*(e_nkm(n,k,m)-e_nkm_old(n,k,m));
            
            objfunc(n,k,m)=(say-omega_hat);
            if E_km(k)< energy_threshold
                objfunc(n,k,m)=0;
            end
            
        end
    end
end

end

maximize sum(sum(sum(objfunc)))+sum(sum(r_rrh))-(landa*sum(sum(pr)))
subject to
%constraint for the power of the rrh
for m=1:M
% temp=sum(pr,1);
% temp(:,m)-pr_max(m) <=0;
s=0;
for n=1:N
s=s+ pr(n,m);
end
s-pr_max(m) <=0;
end
%constraint for the rate of the rrh
for m=1:M
temp1=sum(tr,1);
R_rrh_min-temp1(:,m) <=0;
end

%constraint for the enegy of the user
be=b_nkm_old.*e_nkm;
for m=1:M
be_temp= be(:,:,m);
be_t2=sum(be_temp,1);
for k=1:K
be_t2(:,k)-1<=0;
end
end
%dc constraint

for m=1:M
tdc1=objfunc(:,:,m);
btemp=b_nkm_old(:,:,m);
tdc=btemp.*tdc1;
tdc2=sum(tdc,1);
for k=1:K
tdc2(k)-min_user_rate >= 0;
end
end

for m=1:M
for n=1:N
for k=1:K
1>=e_nkm(n,k,m)>=0
end
end

end
for m=1:M
for n=1:N
pr(n,m)>=0;
end
end

1 >= sum(e_nkm,1) >= 0;

cvx_end

I will appreciate you if I receive your advises.

Thanks.


The status failed but still got the result
Cannot perform the operation: {real affine} ./ {real affine}?
Can't solve a feasible problem
(Mark L. Stone) #2

Due to log used in CVX expressions, CVX’s not always successful successive approximation method (read the disclaimers at http://cvxr.com/cvx/doc/advanced.html#the-successive-approximation-method ) was used. Combined with poor problem data scaling, this can result in failure (on the random instance I tried, it failed with SDPT3, but inaccurate solved with SeDuMi).

Using CVXQUAD https://github.com/hfawzi/cvxquad worked for me. Install CVXQUAD and its exponential.m replacement for CVX’s version, as described in the link. For this problem, additional modification is needed to get CVXQUAD’s Pade approximant to be invoked everywhere instead of CVX’s successive approximation method. The easiest way to do that is to replace all scalar instances of log(x) by -rel_entr(1,x) . In the case of tr=log(1+cnr.*pr); which needs to be N by M, I used tr = -rel_entr(ones(N,M),1+cnr.*pr);

Here is the code and output (using SDPT3) to use the CVXQUAD Pade approximant for the random problem instance I ran (note that some of your problem inputs use rand).

cvx_begin
variables e_nkm(N,K,M) pr(N,M)
cnr=rrh_fad./(N0*Bw);
tr = -rel_entr(ones(N,M),1+cnr.*pr);
r_rrh=cvx(zeros(N,M));
objfunc=cvx(zeros(N,K,M));
 
for m=1:M
    E_km=e_avail(:,:,m);
    r_rrh(:,m)=((1-alfa_old(m))*tr(:,m));
    for n=1:N
        %         obj2=r_rrh-landa*pr(n,m)
        for k=1:K
            check=J_nor(n,:,m)>=J_nor(n,k,m);
            say= -rel_entr(1,1+sum(((J_nor(n,:,m).*b_nkm_old(n,:,m).*e_nkm(n,:,m).*check.*E_km)/alfa_old(m)))+(J_nor(n,k,m)*b_nkm_old(n,k,m)*e_nkm(n,k,m)*E_km(1,k)));
            omega=alfa_old(m)*(-rel_entr(1,1+sum(((J_nor(n,:,m).*b_nkm_old(n,:,m).*e_nkm_old(n,:,m).*check.*E_km)/alfa_old(m)))));
            
            %             if E_km(k)< energy_threshold
            %                 objfunc(n,k,m)=0;
        end
        for i=1:K
            if(i~=k)
                gerad_e=(J_nor(n,i,m)*b_nkm_old(n,i,m)*E_km(1,i))/(1+sum(((J_nor(n,:,m).*b_nkm_old(n,:,m).*e_nkm_old(n,:,m).*check.*E_km)/alfa_old(m))));
            else
                gerad_e=0;
                omega_hat=omega+gerad_e*(e_nkm(n,k,m)-e_nkm_old(n,k,m));
                
                objfunc(n,k,m)=(say-omega_hat);
                if E_km(k)< energy_threshold
                    objfunc(n,k,m)=0;
                end
                
            end
        end
    end
end
 
maximize sum(sum(sum(objfunc)))+sum(sum(r_rrh))-(landa*sum(sum(pr)))
subject to
%constraint for the power of the rrh
for m=1:M
    %        temp=sum(pr,1);
    %        temp(:,m)-pr_max(m) <=0;
    s=0;
    for n=1:N
        s=s+ pr(n,m);
    end
    s-pr_max(m) <=0;
end
%constraint for the rate of the rrh
for m=1:M
    temp1=sum(tr,1);
    R_rrh_min-temp1(:,m) <=0;
end
 
%constraint for the enegy of the user
be=b_nkm_old.*e_nkm;
for m=1:M
    be_temp= be(:,:,m);
    be_t2=sum(be_temp,1);
    for k=1:K
        be_t2(:,k)-1<=0;
    end
end
%dc constraint
 
for m=1:M
    tdc1=objfunc(:,:,m);
    btemp=b_nkm_old(:,:,m);
    tdc=btemp.*tdc1;
    tdc2=sum(tdc,1);
    for k=1:K
        tdc2(k)-min_user_rate >= 0;
    end
end
 
for m=1:M
    for n=1:N
        for k=1:K
            1>=e_nkm(n,k,m)>=0
        end
    end
    
end
for m=1:M
    for n=1:N
        pr(n,m)>=0;
    end
end
 
1 >= sum(e_nkm,1) >= 0;
 
cvx_end
=====================================
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
=====================================
=====================================
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
=====================================
=====================================
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
=====================================
=====================================
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
=====================================
=====================================
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
=====================================
=====================================
Using Pade approximation for exponential
cone with parameters m=3, k=3
=====================================
 
Calling SDPT3 4.0: 591 variables, 212 equality constraints
   For improved efficiency, SDPT3 is solving the dual problem.
------------------------------------------------------------

 num. of constraints = 212
 dim. of sdp    var  = 312,   num. of sdp  blk  = 156
 dim. of linear var  = 123
*******************************************************************
   SDPT3: Infeasible path-following algorithms
*******************************************************************
 version  predcorr  gam  expon  scale_data
   HKM      1      0.000   1        0    
it pstep dstep pinfeas dinfeas  gap      prim-obj      dual-obj    cputime
-------------------------------------------------------------------
 0|0.000|0.000|3.5e+02|1.5e+00|6.7e+04| 7.512305e+03  0.000000e+00| 0:0:00| chol  1  1 
 1|0.826|0.758|6.1e+01|3.7e-01|1.7e+04| 2.837660e+03  2.841612e+01| 0:0:00| chol  1  1 
 2|0.608|0.593|2.4e+01|1.5e-01|9.4e+03| 2.514351e+03  2.072211e+01| 0:0:00| chol  1  1 
 3|0.590|0.781|9.9e+00|3.3e-02|4.3e+03| 2.110627e+03 -5.960684e+00| 0:0:00| chol  1  1 
 4|0.822|0.834|1.8e+00|5.5e-03|1.5e+03| 1.136747e+03 -1.147657e+01| 0:0:00| chol  1  1 
 5|0.903|0.966|1.7e-01|1.9e-04|2.9e+02| 2.479458e+02 -1.171831e+01| 0:0:00| chol  1  1 
 6|0.583|0.945|7.1e-02|1.0e-05|2.0e+02| 1.638562e+02 -6.992976e+00| 0:0:00| chol  1  1 
 7|0.660|0.943|2.4e-02|1.3e-04|1.3e+02| 1.090896e+02  4.481088e+00| 0:0:00| chol  1  1 
 8|0.604|0.953|9.5e-03|8.5e-05|8.2e+01| 6.988614e+01  8.187248e+00| 0:0:00| chol  1  1 
 9|0.575|0.742|4.1e-03|8.0e-05|6.3e+01| 5.612269e+01  1.136142e+01| 0:0:00| chol  1  1 
10|0.440|0.946|2.3e-03|4.8e-05|4.9e+01| 4.709577e+01  1.210998e+01| 0:0:00| chol  1  1 
11|0.497|0.521|1.1e-03|6.0e-05|4.2e+01| 4.333632e+01  1.541363e+01| 0:0:00| chol  1  1 
12|0.482|0.940|5.9e-04|3.2e-05|3.3e+01| 3.926860e+01  1.792357e+01| 0:0:00| chol  1  1 
13|0.416|0.476|3.5e-04|4.3e-05|3.1e+01| 3.840472e+01  1.959158e+01| 0:0:00| chol  1  1 
14|0.385|0.911|2.1e-04|2.8e-05|2.7e+01| 3.734513e+01  2.191836e+01| 0:0:00| chol  1  1 
15|0.419|0.397|1.2e-04|4.1e-05|2.6e+01| 3.780036e+01  2.231854e+01| 0:0:00| chol  1  1 
16|0.343|0.464|8.1e-05|4.7e-05|2.5e+01| 3.822784e+01  2.471019e+01| 0:0:00| chol  1  1 
17|0.481|0.862|4.2e-05|2.3e-05|2.0e+01| 3.806769e+01  2.660242e+01| 0:0:01| chol  1  1 
18|0.383|0.383|2.6e-05|2.2e-05|1.8e+01| 3.856060e+01  2.819425e+01| 0:0:01| chol  1  1 
19|0.426|0.757|1.5e-05|1.1e-05|1.6e+01| 3.869419e+01  2.989844e+01| 0:0:01| chol  1  1 
20|0.381|0.390|9.2e-06|9.5e-06|1.4e+01| 3.913976e+01  3.093701e+01| 0:0:01| chol  1  1 
21|0.380|0.518|5.7e-06|6.4e-06|1.3e+01| 3.950227e+01  3.242232e+01| 0:0:01| chol  1  1 
22|0.460|0.786|3.1e-06|2.5e-06|1.0e+01| 3.962576e+01  3.444905e+01| 0:0:01| chol  1  1 
23|0.360|0.409|2.0e-06|2.1e-06|9.5e+00| 4.018772e+01  3.524885e+01| 0:0:01| chol  1  1 
24|0.389|0.520|1.2e-06|1.4e-06|8.5e+00| 4.079540e+01  3.688941e+01| 0:0:01| chol  1  1 
25|0.345|0.436|7.9e-07|1.0e-06|7.9e+00| 4.141662e+01  3.773320e+01| 0:0:01| chol  1  1 
26|0.336|0.360|5.2e-07|8.2e-07|7.3e+00| 4.209676e+01  3.892531e+01| 0:0:01| chol  1  1 
27|0.454|0.614|2.9e-07|4.2e-07|6.3e+00| 4.300766e+01  4.064741e+01| 0:0:01| chol  1  1 
28|0.230|0.696|2.2e-07|1.9e-07|6.5e+00| 4.347305e+01  4.199655e+01| 0:0:01| chol  1  1 
29|0.278|0.887|1.6e-07|6.5e-08|6.9e+00| 4.425340e+01  4.260610e+01| 0:0:01| chol  1  1 
30|0.435|0.573|9.0e-08|6.0e-08|5.8e+00| 4.531255e+01  4.355744e+01| 0:0:01| chol  1  1 
31|0.345|0.409|5.9e-08|5.3e-08|5.4e+00| 4.610101e+01  4.422445e+01| 0:0:01| chol  1  1 
32|0.378|0.419|3.7e-08|4.3e-08|4.9e+00| 4.686910e+01  4.524315e+01| 0:0:01| chol  1  1 
33|0.411|0.668|2.2e-08|2.2e-08|4.1e+00| 4.744852e+01  4.648003e+01| 0:0:01| chol  1  1 
34|0.398|0.502|1.3e-08|1.5e-08|3.7e+00| 4.812766e+01  4.692444e+01| 0:0:01| chol  1  1 
35|0.312|0.531|9.0e-09|9.7e-09|3.5e+00| 4.861016e+01  4.773751e+01| 0:0:01| chol  1  1 
36|0.429|0.799|5.1e-09|3.7e-09|3.0e+00| 4.908657e+01  4.813513e+01| 0:0:01| chol  1  1 
37|0.512|0.757|2.5e-09|2.0e-09|2.4e+00| 4.947224e+01  4.851240e+01| 0:0:01| chol  1  1 
38|0.616|0.678|9.6e-10|1.1e-09|1.6e+00| 4.966238e+01  4.872597e+01| 0:0:01| chol  1  1 
39|0.676|0.740|3.1e-10|5.5e-10|1.1e+00| 4.965518e+01  4.885169e+01| 0:0:01| chol  1  1 
40|0.905|1.000|2.9e-11|4.4e-10|2.3e-01| 4.916273e+01  4.896557e+01| 0:0:01| chol  1  1 
41|0.958|0.978|1.2e-12|2.5e-10|1.2e-02| 4.899646e+01  4.898578e+01| 0:0:01| chol  1  1 
42|0.937|0.993|9.8e-14|4.0e-10|8.3e-04| 4.898744e+01  4.898671e+01| 0:0:01| chol  1  1 
43|0.933|0.997|5.4e-12|3.6e-10|6.0e-05| 4.898679e+01  4.898673e+01| 0:0:01| chol  2  2 
44|0.972|1.000|5.9e-13|5.7e-10|1.1e-05| 4.898675e+01  4.898673e+01| 0:0:01| chol  1  1 
45|0.983|1.000|3.5e-11|1.2e-09|8.1e-07| 4.898674e+01  4.898674e+01| 0:0:01|
  stop: max(relative gap, infeasibilities) < 1.49e-08
-------------------------------------------------------------------
 number of iterations   = 45
 primal objective value =  4.89867370e+01
 dual   objective value =  4.89867362e+01
 gap := trace(XZ)       = 8.10e-07
 relative gap           = 8.18e-09
 actual relative gap    = 8.08e-09
 rel. primal infeas (scaled problem)   = 3.51e-11
 rel. dual     "        "       "      = 1.24e-09
 rel. primal infeas (unscaled problem) = 0.00e+00
 rel. dual     "        "       "      = 0.00e+00
 norm(X), norm(y), norm(Z) = 4.8e+01, 1.5e+10, 1.3e+10
 norm(A), norm(b), norm(C) = 2.3e+02, 1.1e+01, 2.4e+02
 Total CPU time (secs)  = 1.23  
 CPU time per iteration = 0.03  
 termination code       =  0
 DIMACS: 7.5e-11  0.0e+00  2.0e-09  0.0e+00  8.1e-09  8.2e-09
-------------------------------------------------------------------
 
------------------------------------------------------------
Status: Solved
Optimal value (cvx_optval): +63.4101

(dariush) #3

Thanks for your kind and helpful advises.