"Invalid constraint: {concave} == {real affine}"when using CVXQUAD

Hello everyone,I have a concave problem which objective function cantains ‘‘log’’.But it may be ‘‘failed’’ with some parameters when cvx slove it.so I read Mark’s top post“ CVXQUAD: How to use CVXQUAD’s Pade Approximant ”and install CVXQUAD to instead SCA method,But when I change the’‘log’’ by ‘’-rel_entr(1,cvx_expression)’’,the CVX told me a error:

**Disciplined convex programming error:**

** Invalid constraint: {concave} == {real affine}**

error cvxprob/newcnstr (line 72)
            newcnstr( prob, x{k}, y{k}, op );

error  ==  (line 3)
b = newcnstr( evalin( 'caller', 'cvx_problem', '[]' ), x, y, '==' );

error rel_entr_quad (line 59)
        {shiftdim(x,-2),shiftdim(y,-2),shiftdim(z,-2)} == ...

error trajectory_original (line 54)
   R=sum(-rel_entr_quad(1,(1+c_-gama_0*c_.*P_U).*inv_pos(lll+P_U*gama_0))/log(2)-F_k.*mmm);

But my problem can be accepted by cvx when I use ‘‘log’’.
my model is:


there is my code:

clc;
clear;
w_S=[0,0];
w_D=[300,0];
w_Ek=[200,200];
r_k=20;
sigama_square=1.25e-20*20000000;   %-169dBm/Hz   B=20Mhz
gama_0_dB=80;    %80dB
gama_0=10^(gama_0_dB/10);
beta_0=gama_0*sigama_square;  %-50dB
fai=3;
P_S_ave=1;
P_S_max=4;
P_U_ave=0.01;
P_U_max=0.04;
H=100;
V=3;
slot=0.5;
T=200;
N=T/slot;
d_SD=abs(norm(w_S-w_D)); 
c_=zeros(1,N);
e_=zeros(1,N);
P_S=ones(1,N);
P_U=ones(1,N)./100;
F_k=zeros(1,N);
m_k=zeros(1,N);
q_l_1=zeros(N,2);
q_0=[-100,100];
q_F=[500,100];
load data.mat
q_l_1(:,1)=q_x;
q_l_1(:,2)=q_y;
R_all=zeros(1,N);
iter_num=1;
w_k=zeros(N,2);
d_SE=zeros(1,N);
q_x_record=zeros(N,100);
q_y_record=zeros(N,100);
while(1)   
    for n=1:N
        w_k(n,1)=w_Ek(1)+r_k*(w_Ek(1)-q_l_1(n,1))/norm(q_l_1(n,:)-w_Ek);
        w_k(n,2)=w_Ek(2)+r_k*(w_Ek(2)-q_l_1(n,2))/norm(q_l_1(n,:)-w_Ek);
        d_SE(n)=norm(w_k(n,:)-w_S);
        c_(n)=(exp(psi(1))*gama_0*P_S(n))/d_SD^fai;
        e_(n)=gama_0*P_S(n)/d_SE(n)^fai;
        m_k(n)=norm(q_l_1(n,:)-w_k(n,:))^2;
        F_k(n)=e_(n)*gama_0*P_U(n)/(log(2)*(m_k(n)+gama_0*P_U(n))*((e_(n)+1)*m_k(n)+gama_0*P_U(n)));
    end
cvx_begin
variables q_x(N) q_y(N)
variable lll(N)
variable mmm(N)
expression R(N)
for n=1:N
    R(n)=-rel_entr(1,1+c_(n)-c_(n)*P_U(n)*gama_0*inv_pos(lll(n)+P_U(n)*gama_0))/log(2)-F_k(n)*mmm(n);      
end
maximize sum(R)
subject to
for n=1:N
    lll(n)+norm(q_l_1(n,:))^2-2*(q_l_1(n,:)-w_D)*[q_x(n),q_y(n)]'-norm(w_D)^2-H^2<=0;
    (q_x(n)-w_k(n,1))^2+(q_y(n)-w_k(n,2))^2+H^2-mmm(n)<=0;
end
for n=2:N
(q_x(n)-q_x(n-1))^2+(q_y(n)-q_y(n-1))^2<=(5)^2;
end
q_x(1)==q_0(1);
q_y(1)==q_0(2);
q_x(N)==q_F(1);
q_y(N)==q_F(2);
cvx_end
q_l_1(:,1)=q_x;
q_l_1(:,2)=q_y;
q_x_record(:,iter_num)=q_x;
q_y_record(:,iter_num)=q_y;
iter_num=iter_num+1;
R_all(iter_num)=cvx_optval;
if iter_num==15 || abs(R_all(iter_num)-R_all(iter_num-1))<0.001
    break;
end
end
save 'record.mat';

when I use ‘‘log’’ in my objective function,i.e.
R(n)=log(1+c_(n)-c_(n)*P_U(n)*gama_0*inv_pos(lll(n)+P_U(n)*gama_0))/log(2)-F_k(n)*mmm(n);
the CVX can accept it and solved it successfully by using SCA method in some parameter before install CVXQUAD.
And when I omit all of my constraints and run the program again,the error still occur,So I think there are something wrong in my objective function.
could someone can help me? very appreciate you help:smiling_face_with_three_hearts:

First of all, make sure you are using CVX 2.1, not CVX 3.0beta.

This problem is not reproducible because not all the input data is provided. Can you please provide a small, self-contained version which exhibits the problem, perhaps by crunching down all the input data to something where you can directly assign all the inputs with MATLAB assignments. Also provide the complete log rather than rel_entr version of the code which you said doesn’t generate an error (other than Successive Approximation Method maybe failing).

I don’t even see the error-triggering line of code in your program. I don’t know if the code is being crunched down prior to issuing the error message, but I thought the error message should relate to the code as originally written, not as internally processed by CVX. You ought to be able to see whether the error message occurs before or after the maximize sum(R) statement.

In the event this error is occurring due to a CVX bug, you can try rewriting your code (still using rel_entr) and see whether the error still occurs. For instance, objective = 0; for i = 1:N, objective = objective -rel_entr(... ; end; maximize(objective) .

Hi Mark,Thanks you for your reply.
And I’m sure that i’m using CVX2.1.I’m sorry i forgot the ‘‘data.mat’’,actually the file only save some initial point.
there is the code which can be run directly without error and CVX can solve it by using SCA.

    clc;
    clear;
    w_S=[0,0];
    w_D=[300,0];
    w_Ek=[200,200];
    r_k=20;
    sigama_square=1.25e-20*20000000;   %-169dBm/Hz   B=20Mhz
    gama_0_dB=80;    %80dB
    gama_0=10^(gama_0_dB/10);
    beta_0=gama_0*sigama_square;  %-50dB
    fai=3;
    P_S_ave=1;
    P_S_max=4;
    P_U_ave=0.01;
    P_U_max=0.04;
    H=100;
    V=3;
    slot=0.5;
    T=200;
    N=T/slot;
    d_SD=abs(norm(w_S-w_D)); 
    c_=zeros(1,N);
    e_=zeros(1,N);
    P_S=ones(1,N);
    P_U=ones(1,N)./100;
    F_k=zeros(1,N);
    m_k=zeros(1,N);
    q_l_1=zeros(N,2);
    q_0=[-100,100];
    q_F=[500,100];
    load data.mat
    q_x=zeros(N,1);
    q_y=zeros(N,1);
    for n=1:N
        q_x(n)=q_0(1)+(n-1)*(q_F(1)-q_0(1))/(N-1);
    end
    for n=1:N/2
        q_y(n)=q_0(2)+(n-1)*(200-q_0(2))/((N-2)/2);
    end
    for n=(N/2+1):N
        q_y(n)=q_y(N/2)+(n-1-N/2)*(q_F(2)-q_y(N/2))/((N-2)/2);
    end
    q_l_1(:,1)=q_x;
    q_l_1(:,2)=q_y;
    R_all=zeros(1,N);
    iter_num=1;
    w_k=zeros(N,2);
    d_SE=zeros(1,N);
    q_x_record=zeros(N,100);
    q_y_record=zeros(N,100);
    while(1)   
        for n=1:N
            w_k(n,1)=w_Ek(1)+r_k*(w_Ek(1)-q_l_1(n,1))/norm(q_l_1(n,:)-w_Ek);
            w_k(n,2)=w_Ek(2)+r_k*(w_Ek(2)-q_l_1(n,2))/norm(q_l_1(n,:)-w_Ek);
            d_SE(n)=norm(w_k(n,:)-w_S);
            c_(n)=(exp(psi(1))*gama_0*P_S(n))/d_SD^fai;
            e_(n)=gama_0*P_S(n)/d_SE(n)^fai;
            m_k(n)=norm(q_l_1(n,:)-w_k(n,:))^2;
            F_k(n)=e_(n)*gama_0*P_U(n)/(log(2)*(m_k(n)+gama_0*P_U(n))*((e_(n)+1)*m_k(n)+gama_0*P_U(n)));
        end
    cvx_begin
    variables q_x(N) q_y(N)
    variable lll(N)
    variable mmm(N)
    expression R(N)
    for n=1:N
        R(n)=log(1+c_(n)-c_(n)*P_U(n)*gama_0*inv_pos(lll(n)+P_U(n)*gama_0))/log(2)-F_k(n)*mmm(n);      
    end
    maximize sum(R)
    subject to
    for n=1:N
        lll(n)+norm(q_l_1(n,:))^2-2*(q_l_1(n,:)-w_D)*[q_x(n),q_y(n)]'-norm(w_D)^2-H^2<=0;
        (q_x(n)-w_k(n,1))^2+(q_y(n)-w_k(n,2))^2+H^2-mmm(n)<=0;
    end
    for n=2:N
    (q_x(n)-q_x(n-1))^2+(q_y(n)-q_y(n-1))^2<=(5)^2;
    end
    q_x(1)==q_0(1);
    q_y(1)==q_0(2);
    q_x(N)==q_F(1);
    q_y(N)==q_F(2);
    cvx_end
    q_l_1(:,1)=q_x;
    q_l_1(:,2)=q_y;
    q_x_record(:,iter_num)=q_x;
    q_y_record(:,iter_num)=q_y;
    iter_num=iter_num+1;
    R_all(iter_num)=cvx_optval;
    if iter_num==15 || abs(R_all(iter_num)-R_all(iter_num-1))<0.001
        break;
    end
    end
    save 'record.mat';

There is another version which I mentioned that will occur errors

clc;
clear;
w_S=[0,0];
w_D=[300,0];
w_Ek=[200,200];
r_k=20;
sigama_square=1.25e-20*20000000;   %-169dBm/Hz   B=20Mhz
gama_0_dB=80;    %80dB
gama_0=10^(gama_0_dB/10);
beta_0=gama_0*sigama_square;  %-50dB
fai=3;
P_S_ave=1;
P_S_max=4;
P_U_ave=0.01;
P_U_max=0.04;
H=100;
V=3;
slot=0.5;
T=200;
N=T/slot;
d_SD=abs(norm(w_S-w_D)); 
c_=zeros(1,N);
e_=zeros(1,N);
P_S=ones(1,N);
P_U=ones(1,N)./100;
F_k=zeros(1,N);
m_k=zeros(1,N);
q_l_1=zeros(N,2);
q_0=[-100,100];
q_F=[500,100];
load data.mat
q_x=zeros(N,1);
q_y=zeros(N,1);
for n=1:N
    q_x(n)=q_0(1)+(n-1)*(q_F(1)-q_0(1))/(N-1);
end
for n=1:N/2
    q_y(n)=q_0(2)+(n-1)*(200-q_0(2))/((N-2)/2);
end
for n=(N/2+1):N
    q_y(n)=q_y(N/2)+(n-1-N/2)*(q_F(2)-q_y(N/2))/((N-2)/2);
end
q_l_1(:,1)=q_x;
q_l_1(:,2)=q_y;
R_all=zeros(1,N);
iter_num=1;
w_k=zeros(N,2);
d_SE=zeros(1,N);
q_x_record=zeros(N,100);
q_y_record=zeros(N,100);
while(1)   
    for n=1:N
        w_k(n,1)=w_Ek(1)+r_k*(w_Ek(1)-q_l_1(n,1))/norm(q_l_1(n,:)-w_Ek);
        w_k(n,2)=w_Ek(2)+r_k*(w_Ek(2)-q_l_1(n,2))/norm(q_l_1(n,:)-w_Ek);
        d_SE(n)=norm(w_k(n,:)-w_S);
        c_(n)=(exp(psi(1))*gama_0*P_S(n))/d_SD^fai;
        e_(n)=gama_0*P_S(n)/d_SE(n)^fai;
        m_k(n)=norm(q_l_1(n,:)-w_k(n,:))^2;
        F_k(n)=e_(n)*gama_0*P_U(n)/(log(2)*(m_k(n)+gama_0*P_U(n))*((e_(n)+1)*m_k(n)+gama_0*P_U(n)));
    end
cvx_begin
variables q_x(N) q_y(N)
variable lll(N)
variable mmm(N)
expression R(N)
for n=1:N
    R(n)=-rel_entr(1,1+c_(n)-c_(n)*P_U(n)*gama_0*inv_pos(lll(n)+P_U(n)*gama_0))/log(2)-F_k(n)*mmm(n);      
end
maximize sum(R)
subject to
for n=1:N
    lll(n)+norm(q_l_1(n,:))^2-2*(q_l_1(n,:)-w_D)*[q_x(n),q_y(n)]'-norm(w_D)^2-H^2<=0;
    (q_x(n)-w_k(n,1))^2+(q_y(n)-w_k(n,2))^2+H^2-mmm(n)<=0;
end
for n=2:N
(q_x(n)-q_x(n-1))^2+(q_y(n)-q_y(n-1))^2<=(5)^2;
end
q_x(1)==q_0(1);
q_y(1)==q_0(2);
q_x(N)==q_F(1);
q_y(N)==q_F(2);
cvx_end
q_l_1(:,1)=q_x;
q_l_1(:,2)=q_y;
q_x_record(:,iter_num)=q_x;
q_y_record(:,iter_num)=q_y;
iter_num=iter_num+1;
R_all(iter_num)=cvx_optval;
if iter_num==15 || abs(R_all(iter_num)-R_all(iter_num-1))<0.001
    break;
end
end
save 'record.mat';

The only difference between the two version is in the second using -rel_entr(1,cvx_expression) instead of ‘‘log(cvx_expression)’’ in the objective function. I’m really confused about it why cvx told me an error about the constrain rather than the objective function.
Thank you very much for your help!

And then I omit the maximize sum(R) and all of the constrain,the error still occur.So I think there must be something wrong in objective function which maybe violated the DCP ruleset.
However,the cvx told me that 1+c_(n)-c_(n)*P_U(n)*gama_0*inv_pos(lll(n)+P_U(n)*gama_0) is cvx concave expression (scalar) so the log(1+c_(n)-c_(n)*P_U(n)*gama_0*inv_pos(lll(n)+P_U(n)*gama_0)) also should be concave.But why -rel_entr(1,expression) goes wrong?
Did I make some common sense mistakes?

I don’t know what I am supposed to do to run your program. Can you get rid of the extraneous stuff and just have a code which runs CVX once, not as part of a loop (presuming you still get the error)? Can you please post a clean code which just runs without modification and is as simple as possible while still demonstrating the error?

Can you post the exact error messages received, and exactly where they occurred? That should be easy to determine. Also, try my suggestion on building up objective instead of using R expression array. At this point I still don’t know whether there is an error in your code or a bug in CVX.

This is the code:

  clc;
    clear;
    w_S=[0,0];
    w_D=[300,0];
    w_Ek=[200,200];
    r_k=20;
    sigama_square=1.25e-20*20000000;   %-169dBm/Hz   B=20Mhz
    gama_0_dB=80;    %80dB
    gama_0=10^(gama_0_dB/10);
    beta_0=gama_0*sigama_square;  %-50dB
    fai=3;
    P_S_ave=1;
    P_S_max=4;
    P_U_ave=0.01;
    P_U_max=0.04;
    H=100;
    V=3;
    slot=0.5;
    T=200;
    N=T/slot;
    d_SD=abs(norm(w_S-w_D)); 
    c_=zeros(1,N);
    e_=zeros(1,N);
    P_S=ones(1,N);
    P_U=ones(1,N)./100;
    F_k=zeros(1,N);
    m_k=zeros(1,N);
    q_l_1=zeros(N,2);
    q_0=[-100,100];
    q_F=[500,100];
    load data.mat
    q_x=zeros(N,1);
    q_y=zeros(N,1);
    for n=1:N
        q_x(n)=q_0(1)+(n-1)*(q_F(1)-q_0(1))/(N-1);
    end
    for n=1:N/2
        q_y(n)=q_0(2)+(n-1)*(200-q_0(2))/((N-2)/2);
    end
    for n=(N/2+1):N
        q_y(n)=q_y(N/2)+(n-1-N/2)*(q_F(2)-q_y(N/2))/((N-2)/2);
    end
    q_l_1(:,1)=q_x;
    q_l_1(:,2)=q_y;
    R_all=zeros(1,N);
    iter_num=1;
    w_k=zeros(N,2);
    d_SE=zeros(1,N);
    q_x_record=zeros(N,100);
    q_y_record=zeros(N,100);

        for n=1:N
            w_k(n,1)=w_Ek(1)+r_k*(w_Ek(1)-q_l_1(n,1))/norm(q_l_1(n,:)-w_Ek);
            w_k(n,2)=w_Ek(2)+r_k*(w_Ek(2)-q_l_1(n,2))/norm(q_l_1(n,:)-w_Ek);
            d_SE(n)=norm(w_k(n,:)-w_S);
            c_(n)=(exp(psi(1))*gama_0*P_S(n))/d_SD^fai;
            e_(n)=gama_0*P_S(n)/d_SE(n)^fai;
            m_k(n)=norm(q_l_1(n,:)-w_k(n,:))^2;
            F_k(n)=e_(n)*gama_0*P_U(n)/(log(2)*(m_k(n)+gama_0*P_U(n))*((e_(n)+1)*m_k(n)+gama_0*P_U(n)));
        end
    cvx_begin
    variables q_x(N) q_y(N)
    variable lll(N)
    variable mmm(N)
    expression R(N)
    for n=1:N
        R(n)=-rel_entr(1,1+c_(n)-c_(n)*P_U(n)*gama_0*inv_pos(lll(n)+P_U(n)*gama_0))/log(2)-F_k(n)*mmm(n);      
    end
    maximize sum(R)
    subject to
    for n=1:N
        lll(n)+norm(q_l_1(n,:))^2-2*(q_l_1(n,:)-w_D)*[q_x(n),q_y(n)]'-norm(w_D)^2-H^2<=0;
        (q_x(n)-w_k(n,1))^2+(q_y(n)-w_k(n,2))^2+H^2-mmm(n)<=0;
    end
    for n=2:N
    (q_x(n)-q_x(n-1))^2+(q_y(n)-q_y(n-1))^2<=(5)^2;
    end
    q_x(1)==q_0(1);
    q_y(1)==q_0(2);
    q_x(N)==q_F(1);
    q_y(N)==q_F(2);
    cvx_end

And this is the error:

illegal usage cvxprob/newcnstr (line 192)
Disciplined convex programming error:
   Invalid constraint: {concave} == {real affine}

error cvxprob/newcnstr (line 72)
            newcnstr( prob, x{k}, y{k}, op );

error  ==  (line 3)
b = newcnstr( evalin( 'caller', 'cvx_problem', '[]' ), x, y, '==' );

error cvx/rel_entr (line 80)
                { -q, xt, yt } == exponential( sz ); %#ok

error cvx_forum (line 67)
        R(n)=-rel_entr(1,1+c_(n)-c_(n)*P_U(n)*gama_0*inv_pos(lll(n)+P_U(n)*gama_0))/log(2)-F_k(n)*mmm(n);

What happens if you just type the RHS, rather than R(n) = RHS ? Does it show concave expression without error message? What happens if you use the objective = objective + … construct instead of R(n) = … which I mentioned earlier?

There is another error:Index exceeds the number of array elements. Do I need to represent the objective function to a matrix form?

I don’t know what you are doing. The errors you are reporting keep changing, so I can;t keep track of what error goes with what. I recommend simplifying your problem, get rid of outer loops around cvx_begin … cvx_end, and step through the program one line at a time as necessary to determine what errors are occurring where, and to examine the items going into any statements which generate errors.

you means in this form?

expression objective
for n=1:N
    objective=objective-rel_entr(1,1+c_(n)-c_(n)*P_U(n)*gama_0*inv_pos(lll(n)+P_U(n)*gama_0))/log(2)-F_k(n)*mmm(n);      
end

Yes. I’m not sure if this is different, but instead of
expression objective
use
expression = 0

However there are not seems to be different. I will try something else to slove it according to your suggestion.
Thank you very much for your patient help.

I met the same problem. Have you solved it? If so, could you tell me how to solve it?Thank you very much.

1 Like

None of those code you provided can be run successfully.

I recommend you to use Mosek 9.0 together with YALMIP to deal with exp cone problem. It may be more efficient.