Undefined function 'newcnstr' for input arguments of type 'cvx'

cvx_begin
        variables C_NRC_L(L,N_RC);
        [tau_av,hitratio_av] = TAU_AV( C_NVC1_L,C_NVC2_L,C_NRC_L,S_q,Gamma(1));
        Cost_av = COST_AV(C_NVC1_L,C_NVC2_L,C_NRC_L,S_q,Gamma(1));
        tau_Cost_av=tau_av/tau_max+Cost_av/Cost_max;
        minimize tau_Cost_av
        subject to
            C_NRC_L <= 1;
            C_NRC_L >= 0;
            [ones(1,L)*C_NRC_L]'<= S_R*ones(N_RC,1);
    cvx_end

Undefined function ‘newcnstr’ for input arguments of type ‘cvx’.
Error in == (line 12)
b = newcnstr( evalin( ‘caller’, ‘cvx_problem’, ‘[]’ ), x, y, ‘==’ );

Error in TAU_AV (line 56)
if C_NRC_L(q_l,i)==1

Error in CachingwithZipfgamma (line 94)
[tau_av,hitratio_av] = TAU_AV( C_NVC1_L,C_NVC2_L,C_NRC_L,S_q,Gamma(1));

Part of the code of TAU_AV:

    for i=1:N_RC
        if C_NRC_L(q_l,i)==1
            c_ml_RC=1;
        else
            c_ml_RC=0;
        end
        if find(C_NRC_L(q_l,:)==1)>0
            c_ml_RC_sum=1;
        else
            c_ml_RC_sum=0;
        end

TAU_AV is a function I created, which involves judging the value of the element in the variable C_NRC_L, and then prompted an error, I am sure the problem is convex, this may be a violation of the DCP rule, then how should I express the judgment of the element value in the variable ?

You can’t use CVX variables or expressions in logical conditions (in if statements).

Look at the links produced by https://or.stackexchange.com/search?q=logic+constraints to see how to handle this. You will need to declare binary variables and have Gurobi or Mosek available as solver under CVX.

I decided to replace if, but there is a step function expression about variables, and an error occurred. I read the link you posted, but I still don’t know how to deal with this expression.
image image

%if find(C_NRC_L(q_l,:)==1)>0
%c_ml_RC_sum=1;
c_ml_RC_sum=heaviside(sum(C_NRC_L(q_l,:)));
%else
% c_ml_RC_sum=0;
%end

Error in heaviside (line 26)
Invalid data type. Argument must be single, double, or sym.

Error in TAU_AV (line 63)
c_ml_RC_sum=heaviside(sum(C_NRC_L(q_l,:)));

Error in CachingwithZipfgamma (line 95)
[tau_av,hitratio_av] = TAU_AV( C_NVC1_L,C_NVC2_L,C_NRC_L,S_q,Gamma(1));

You can’t just use whatever functions you feel like on CVX varaibes or expressions. Please rad the entire CVX Userts’ Guide http://cvxr.com/cvx/doc/ . heaviside is not supported by CVX.

You need to implement logic constraints using Big M in order to model them in CVX. If you can’t figure out how to do that, please submit at question at https://or.stackexchange.com/ . There are plenty of readers there who will rush to answer your question, because they apparently like getting points.

I use a continuous function to approximate the heaviside.

variables C_NRC_L(L,N_RC) z ;

{sum(C_NRC_L(q_l,:)),1,z} == exponential(1);
c_ml_RC_sum=1/(1+exp(-200*(z-0.5)));

The function or variable'op_rel_entr_epi_cone' is not defined.

Error exponential (line 46)
         op_rel_entr_epi_cone([1 1 sx],0,m,k);

Error TAU_AV (line 65)
              {sum(C_NRC_L(q_l,:)),1,z} == exponential(1);

CVX: Software for Disciplined Convex Programming ©2014 CVX Research
Version 2.1, Build 1127 (95903bf) Sat Dec 15 18:52:07 2018

Installation info:
Path: F:\matlabnewtoolbox\cvx-w64\cvx
MATLAB version: 9.5 (R2018b)
OS: Windows 10 amd64 version 10.0
Java version: 1.8.0_152
Verfying CVX directory contents:
No missing files.
Preferences:
Path: C:\Users\Administrator\AppData\Roaming\MathWorks\MATLAB\cvx_prefs.mat

First of all, I recommend you upgrade to CVX 2.2.

As to the error, I don’t know whether that is due to a bug in CVX 2.1, or a messed up CVX installation, or due to a CVX rules violation. You haven’t shown the complete program, so I don’t know whether all the arguments on the LHS of the exponential(1) constraint are affine, as they must be.

I believe if you get past this error, you will encounter an error on the next line if z is a CVX variable or expression. You should be able to use inv_pos, because the denominator must be positive.

cvx_begin
        variables C_NRC_L(L,N_RC) z ;
        [tau_av,hitratio_av] = TAU_AV(z, C_NVC1_L,C_NVC2_L,C_NRC_L,S_q,Gamma(1));
        Cost_av = COST_AV(z,C_NVC1_L,C_NVC2_L,C_NRC_L,S_q,Gamma(1));
        tau_Cost_av=tau_av/tau_max+Cost_av/Cost_max;
        minimize tau_Cost_av
        subject to
            C_NRC_L <= 1;
            C_NRC_L >= 0;
            [ones(1,L)*C_NRC_L]'<= S_R*ones(N_RC,1);
cvx_end

Part of the code of TAU_AV:

for q_l=1:L
    for j=1:N_VC1
         for i=1:N_RC
                c_ml_RC=C_NRC_L(q_l,i);
                 {sum(C_NRC_L(q_l,:)),1,z} == exponential(1);
                 c_ml_RC_sum=inv_pos(1+exp(-200*(z-0.5)));  
            C_iml1(j,i)=(1-c_il_VC1)*c_il_VC1_sum*C_VV+(1-c_il_VC1_sum)*(c_ml_RC*C_RV+(1-c_ml_RC)*c_ml_RC_sum*C_RCV+(1-c_ml_RC_sum)*C_BV);
         end
    end
...
...
end

sum(C_NRC_L(q_l,:))

ans =

cvx real affine expression (scalar)

CVX Warning:
Models involving “exponential” or other functions in the log, exp, and entropy
family are solved using an experimental successive approximation method.
This method is slower and less reliable than the method CVX employs for
other models. Please see the section of the user’s guide entitled
The successive approximation method
for more details about the approach, and for instructions on how to
suppress this warning message in the future.

The function’newcnstr’ corresponding to input parameters of type’cvxtuple’ is not defined.
Error == (line 3)
b = newcnstr( evalin(‘caller’,‘cvx_problem’,’[]’ ), x, y,’==’ );

Error TAU_AV (line 65)
{sum(C_NRC_L(q_l,:)),1,z} == exponential(1);

Error CachingwithZipfgamma (line 99)
[tau_av,hitratio_av] = TAU_AV(z, C_NVC1_L,C_NVC2_L,C_NRC_L,S_q,Gamma(1));

CVX: Software for Disciplined Convex Programming ©2014 CVX Research
Version 2.2, Build 1148 (62bfcca) Tue Jan 28 00:51:35 2020

Installation info:
    Path: F:\matlabnewtoolbox\cvx2.2-w64\cvx
    MATLAB version: 9.5 (R2018b)
    OS: Windows 10 amd64 version 10.0
    Java version: 1.8.0_152
Verfying CVX directory contents:
    WARNING: The following files/directories are missing:
        F:\matlabnewtoolbox\cvx2.2-w64\cvx\sedumi\.travis.yml
    These omissions may prevent CVX from operating properly.
    WARNING: The following extra files/directories were found:
        F:\matlabnewtoolbox\cvx2.2-w64\cvx\gurobi\w64\grbprobe.exe.lnk
        F:\matlabnewtoolbox\cvx2.2-w64\cvx\gurobi\w64\gurobi(2).mexw64
        F:\matlabnewtoolbox\cvx2.2-w64\cvx\gurobi\w64\gurobi90(2).dll
        F:\matlabnewtoolbox\cvx2.2-w64\cvx\lib\cvx_bcompress_mex(2).mexw64
        F:\matlabnewtoolbox\cvx2.2-w64\cvx\lib\cvx_eliminate_mex(2).mexw64
        F:\matlabnewtoolbox\cvx2.2-w64\cvx\mosek\w64\mosek64_9_1(2).dll
        F:\matlabnewtoolbox\cvx2.2-w64\cvx\mosek\w64\mosekopt(2).mexw64
        F:\matlabnewtoolbox\cvx2.2-w64\cvx\sdpt3\Solver\Mexfun\mexMatvec(2).mexw64
        F:\matlabnewtoolbox\cvx2.2-w64\cvx\sdpt3\Solver\Mexfun\mexexpand(2).mexw64
        F:\matlabnewtoolbox\cvx2.2-w64\cvx\sdpt3\Solver\Mexfun\mexnnz(2).mexw64
        (and 3 more files)
    These files may alter the behavior of CVX in unsupported ways.
Preferences: 
    Path: C:\Users\Administrator\AppData\Roaming\MathWorks\MATLAB\cvx_prefs.mat

Is the warning of CVX2.2 normal?

CVX 2.2 did not get correctly installed.

I recommend you delete all CVX directories from the MATLAB path. Then start a new MATLAB session. Then try installing CVX 2.2. If that doesn’t work, try rebooting your computer,then installing. If that doesn’t succeed, you will have exceeded my ability to help resolve this.

After deleting all the paths, restart the computer and reinstall,is this installed correctly?

CVX: Software for Disciplined Convex Programming ©2014 CVX Research
Version 2.2, Build 1148 (62bfcca) Tue Jan 28 00:51:35 2020

Installation info:
Path: F:\matlabnewtoolbox\cvx2.2-w64\cvx
MATLAB version: 9.5 (R2018b)
OS: Windows 10 amd64 version 10.0
Java version: 1.8.0_152
Verfying CVX directory contents:
WARNING: The following files/directories are missing:
F:\matlabnewtoolbox\cvx2.2-w64\cvx\sedumi.travis.yml
These omissions may prevent CVX from operating properly.
Preferences:
Path: C:\Users\Administrator\AppData\Roaming\MathWorks\MATLAB\cvx_prefs.mat
image
CVX Warning:
Models involving “exponential” or other functions in the log, exp, and entropy
family are solved using an experimental successive approximation method.
This method is slower and less reliable than the method CVX employs for
other models. Please see the section of the user’s guide entitled
The successive approximation method
for more details about the approach, and for instructions on how to
suppress this warning message in the future.

The function'newcnstr' corresponding to input parameters of type'cvxtuple' is not defined.

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

Error TAU_AV (line 65)
              {sum(C_NRC_L(q_l,:)),1,z} == exponential(1);

Error CachingwithZipfgamma (line 97)
     [tau_av,~] = TAU_AV(z, C_NVC1_L,C_NVC2_L,C_NRC_L,S_q,Gamma(1));

This means that you can’t solve this problem?

I run this code, prompt: (C_NRC_L cvx z cvx)

for q_l=1:L
             {sum(C_NRC_L(q_l,:)),1,z} == exponential(1);
             c_ml_RC_sum=inv_pos(1+exp(-200*(z-0.5)));
end
Warning: A non-empty cvx problem already exists in this scope.
    It is being overwritten.
> In cvxprob (line 28)
   In cvx_begin (line 41)
   In exponential (line 41)
Wrong use of cvx_end (line 140)
Internal cvx data corruption.

Error exponential (line 49)
cvx_end

I think CVX is now correctly installed. When I run cvx_setup, i get the same message about sedumi.travis.yml being missing. I think sedumi still works.

As for your error message from running your program, I believe it has to do with a CVX (syntax) violation. You are not allowed to do stuff such as
``if C_NRC_L(q_l,i)==1 when C_NRC_L is a CVX variable or expression. You will have to implement that logic using Big M, and use Mosek as solver (Gurobi can be used if using CVXQUAD). I clearly told you this earlier in the thread. if you didn’t get a reply to your Big M question at or.stackexchange.com , I suggest you edit the question to remove mention of CVX, and just say that you want to understand how to apply Big M to model the logic constraint; the edit will bump the question to the top, so people will see it again.


Thank you for the suggestion. I asked the question in the wrong form. I have re-edited and replied and got the big-M constraint. How to express this constraint in CVX ?
Because this if-then is in my objective function, not in the problem constraint, this big-M constraint needs to be placed in the problem constraint?Do I need to specify the value of M?

Yes. You should ask how to choose M in a comment to the question answer there.