How to define a matrix variable, whose element is 0 or 1?

I used the keyword “integer” to define a matrix whose element is integer(only 0 or 1 is available), but it failed.
variables x_de(D, E) integer;
restrict the scope of x_de to 0~1:
% non negativity
x_de >= 0;
x_de <= 1;

I learned from the user’s guide below:
For MIDCPs, the integer and binary keywords are used to declare integer and binary variables, respectively:
variable p(10) integer

You will have to be more specific I am afraid. What do you mean it “failed”? Can you supply the full model? What specifically is it that leads you to believe CVX is not doing what is asked of it?

I want to implement “Minimum bottleneck utilization routing, flow-link formulation” algorithm in Matlab. The algorithm is shown below:

I use cvx_solver Mosek as the prefs. My code is shown below.

  • netStruct caller code:

netStruct.nodeXYPositionTable = [1578 118;1430 49;1694 269;1445 305;1842 377;1632 524;437 572;312 751;549 403;497 771;557 508;439 210;761 294;311 338;528 670;660 886;787 818;683 1153;438 1002;934 880;283 578;571 1173;779 1446;807 1077;1217 820;968 1047;930 713;688 1310;1309 921;1438 621];
netStruct.nodeName = {‘W11’,‘W12’,‘W13’,‘W14’,‘W15’,‘W16’,‘W21’,‘W22’,‘W23’,‘W24’,‘W25’,‘W26’,‘W31’,‘W32’,‘W33’,‘W34’,‘W35’,‘W36’,‘W41’,‘W42’,‘W43’,‘W44’,‘W45’,‘W46’,‘W51’,‘W52’,‘W53’,‘W54’,‘W55’,‘W56’};
netStruct.linkTable = [1 2;1 6;1 12;1 25;2 1;2 3;2 7;2 26;3 2;3 4;3 8;3 27;4 3;4 5;4 9;4 28;5 4;5 6;5 10;5 29;6 1;6 5;6 11;6 30;7 2;7 8;7 12;7 18;8 3;8 7;8 9;8 13;9 4;9 8;9 10;9 14;10 5;10 9;10 11;10 15;11 6;11 10;11 12;11 16;12 1;12 7;12 11;12 17;13 8;13 14;13 18;13 24;14 9;14 13;14 15;14 19;15 10;15 14;15 16;15 20;16 11;16 15;16 17;16 21;17 12;17 16;17 18;17 22;18 7;18 13;18 17;18 23;19 14;19 20;19 24;19 30;20 15;20 19;20 21;20 25;21 16;21 20;21 22;21 26;22 17;22 21;22 23;22 27;23 18;23 22;23 24;23 28;24 13;24 19;24 23;24 29;25 1;25 20;25 26;25 30;26 2;26 21;26 25;26 27;27 3;27 22;27 26;27 28;28 4;28 23;28 27;28 29;29 5;29 24;29 28;29 30;30 6;30 19;30 25;30 29];
netStruct.linkLengthInKm = [8059 8058 7558 7558 8059 8059 6709 1299 8059 8059 1299 6709 8059 8059 7558 7558 8059 8059 6709 1299 8058 8059 1299 6709 6709 8059 8058 8084 1299 8059 8059 5576 7558 8059 8059 2716 6709 8059 8059 8084 1299 8059 8059 5576 7558 8058 8059 2716 5576 8059 8058 8262 2716 8059 8059 4216 8084 8059 8059 4216 5576 8059 8059 8262 2716 8059 8059 4216 8084 8058 8059 4216 4216 8059 8058 8084 4216 8059 8059 2716 8262 8059 8059 5576 4216 8059 8059 8084 4216 8059 8059 2716 8262 8058 8059 5576 7558 2716 8059 8058 1299 5576 8059 8059 6709 8084 8059 8059 7558 2716 8059 8059 1299 5576 8059 8059 6709 8084 8058 8059 ];
netStruct.linkCapacityInErlangs = [7333439 7335259 8337891 8337891 7333439 7333439 10581674 282261534 7333439 7333439 282261534 10581674 7333439 7333439 8337891 8337891 7333439 7333439 10581674 282261534 7335259 7333439 282261534 10581674 10581674 7333439 7335259 7288151 282261534 7333439 7333439 15318790 8337891 7333439 7333439 64566979 10581674 7333439 7333439 7288151 282261534 7333439 7333439 15318790 8337891 7335259 7333439 64566979 15318790 7333439 7335259 6977496 64566979 7333439 7333439 26795927 7288151 7333439 7333439 26795927 15318790 7333439 7333439 6977496 64566979 7333439 7333439 26795927 7288151 7335259 7333439 26795927 26795927 7333439 7335259 7288151 26795927 7333439 7333439 64566979 6977496 7333439 7333439 15318790 26795927 7333439 7333439 7288151 26795927 7333439 7333439 64566979 6977496 7335259 7333439 15318790 8337891 64566979 7333439 7335259 282261534 15318790 7333439 7333439 10581674 7288151 7333439 7333439 8337891 64566979 7333439 7333439 282261534 15318790 7333439 7333439 10581674 7288151 7335259 7333439 ];
netStruct.demandTable = [1 2;3 4];
netStruct.offeredTrafficInErlangs = [1000 2000];
[exitFlag exitMsg netStruct] = fa_minimaxUtilization_xde_v4(netStruct)

  • function “fa_minimaxUtilization_xde_v3” code:

    u_e = netStruct.linkCapacityInErlangs;
    h_d = netStruct.offeredTrafficInErlangs;

    N = size(netStruct.nodeXYPositionTable, 1);
    E = size(netStruct.linkTable, 1);
    D = size(netStruct.demandTable, 1);
    A_ne = linkTable2incidenceMatrix(netStruct.linkTable, N);
    w_nd = linkTable2incidenceMatrix(netStruct.demandTable, N);
    cvx_begin

     cvx_quiet(true);
     
     variables rho; % rho: utilization of the link with highest utilization
    
     variables x_de(D, E) binary; % x_de: fraction [0...1] of traffic of d, that traverses link e
    
     minimize( rho )
    
     subject to
    
    
     	A_ne * x_de' == w_nd;
    
     	h_d * x_de <= rho * u_e;
    
     	rho <= 1;
     	
     	x_de >= 0;
    
         x_de <= 1;
    

    cvx_end

  • function linkTable2incidenceMatrix return an incidence matrix (a NxE
    matrix in which an element ane is equal to 1 if node n is the origin
    node of link e, -1 if node n is the destination node of link e, and
    zero otherwise).

The error message is shown below

Error using variable (line 83)
Invalid variable name: binary
This is a reserved word in CVX.
Trying to declare a structured matrix? Use the VARIABLE keyword
instead.

Error in variables (line 26)
evalin( ‘caller’, [ 'variable ', varargin{k} ] );

Error in fa_minimaxUtilization_xde_v4 (line 36)
variables x_de(D, E) binary; % x_de: fraction [0…1] of
traffic of d, that traverses link e

I have to restrict the range of xde as below picture:

Question:What is the problem with the variable x_de of the cvx defined as below:

"variables x_de(D, E) binary;"
or "BINARY VARIABLE x_de(D,E);"

Now I know where the problem is, I should use:

variable x_de(D, E) binary;

not

“variables x_de(D,E) binary;”.

Yeah, I know it is a bit of a pain to have such a subtle distinction between variable and variables. I can probably improve that error message to make it more clear. I am glad you figured it out.