How to define two related indexes in sum section by using Cplex

Viewed 51

I have been working on the mathematical model for a long time and now I have some problems. In this model we have nodes and edges and the flows that pass through these nodes according to the topology. We also have network functions that we use to create two length chains.

First, I don't know how to define two dependent indices that use the same range. for example: cons1 , sum (j in 1..2: j+1 in 1..1 && nj[j] in Nodes && nj[j+1] in 0..9). Is it correct or not?

Second How to define IL decision variable.

I just got this error:"Cannot use type range for int" in cons19 and cons20. I will write the explanation of the two constraints 19 and 20, but I don't know how to change the code.

Constraints (19) and (20) are flow conservation constraints for the (destination node). Constraint (19) makes sure that one of the incoming links of the destination node is assigned to route from the node hosting the last NF of the service chain (nJ ) to the destination node (df ) that is also represented as the J + 1 service. In addition, Constraint (20) assigns one of the outgoing links of the node serving the last service to the (J + 1)th service order. I put my whole code for you.

Dear Mr Fleischer, I have asked you several times questions and I am very grateful for your kindness, but if you can, please help me this time as well. Thanks in advance.

      using CPLEX;

      int Numnodes=10;

      range Nodes = 0..Numnodes;
    
     //...................................................

   //total links number=> int L=13;

   tuple edge{
       key int fromnode;
       key int tonode;
             }

    {edge} Edges with fromnode,tonode in Nodes = 
   {<0,1>,<1,3>,<2,3>,<3,4>,<3,5>,<3,6>,<4,5>,<4,6>,<4,8>,<5,6>,<6,7>,<6,9>,<9,10>};

  {edge} Lin with fromnode,tonode in Nodes = 
  {<0,1>,<1,3>,<2,3>,<3,4>,<3,5>,<3,6>,<4,5>,<4,6>,<4,8>,<5,6>,<6,7>,<6,9>,<9,10>};

  {edge} Lout with fromnode,tonode in Nodes = 
  {<0,1>,<1,3>,<2,3>,<3,4>,<3,5>,<3,6>,<4,5>,<4,6>,<4,8>,<5,6>,<6,7>,<6,9>,<9,10>};

tuple cflow{
  key int node1;
  key int node2;
     }

 {cflow} Flows with node1,node2 in Nodes= {<0,1>, <0,3>, <0,4>, <0,5>, <0,6>, <0,7>, <0,8>, 
  <0,9>, <0,10>, <1,3>, <1,4>, <1,5>, <1,6>, <1,7>, <1,8>, <1,9>, <1,10>, <2,3>, <2,4>, <2,5>, 
  <2,6>, <2,7>, <2,8>, <2,9>, <2,10>,<3,4>, <3,5>, <3,6>, <3,7>, <3,8>, <3,9>, <3,10>, <4,5>, 
  <4,6>, <4,7>, <4,8>, <4,9>, <4,10>, <5,6>, <5,7>, <5,9>, <5,10>,<6,7>, <6,9>, <6,10>, 
   <9,10>};

tuple arraytoset
 {
 cflow ed;
 int rank;
   }
{arraytoset} srout = union(ed in Flows) {<ed,i> | i in 1..card(Routes[ed])};

//....................................................................................

//number flows

range F = 1..50;

//length chains

int J[f in Flows] = 2; 

int nj[1..2];

//.......................................................................................

//VNFs
{string} V = {"Proxy", "Firewall", "IDS", "DPI", "NAT"};

//An NF instance v hosted on node n is characterized by its service rate of requests.

float u[V][Nodes]=...; 

//transmission rate.

float C[l in Edges]=...; 

//Delays

float Dvn[V][Nodes]=...; //denote t

//landa

 float landa[f in Flows]=(0.5+rand(2))/2;

 //..............................................................

 //MAIN DECISION VARIABLES

  dvar int I[V][Nodes][Flows][1..2] in 0..1; 

  //denotes that an NF instance v hosted at node n is used by the j-th service on the service 
  chain of flow f.

  dvar int IL[l in Edges][Flows][1..2][Nodes][1..1][0..9] in 0..1; 

  //denotes that link l is used by flow f to route from the j-th to (j + 1)-th NF service, 
    hosted at node nj and nj+1.                            

    dvar int Y[V][Nodes]; 

    //represents the number of NF type v instances that are hosted at node n.

    //Decision variables related  with non linear equations

    dvar int z[l1 in Lout][Flows][1..2][Nodes][1..1][0..9][V] in 0..1;

    //Related  with floor function

     dexpr float x[f in Flows] = sum(v in V, n in Nodes, j in 1..2) I[v][n][f][j] / J[f];

     dvar int s[f in Flows];

     dvar float floorequ[i in Flows] in 0..0.99999;

  //Total delays

dexpr float DT = sum(l in Edges, f in Flows, j in 1..2: j+1 in 1..1 && nj[j] in   Nodes && 
nj[j+1] in 0..9) IL[l][f][j][nj[j]][j+1][nj[j+1]] * Dlink[l];

dexpr float DP = sum(v in V, n in Nodes, f in Flows, j in 1..2) I[v][n][f][j] * Dvn[v][n];

//MAIN objective functions

dexpr float objmodel1 = sum(n in Nodes, v in V) (Y[v][n] * Cpuvnf[v] / Cpunode[n]);//to minimize the use of cores

dexpr float objmodel2 = sum(l in Edges, f in Flows, j in 1..2: j+1 in 1..1 && nj[j] in Nodes 
&& nj[j+1] in 0..9) ((IL[l][f][j][nj[j]][j+1][nj[j+1]] * landa[f]) / C[l]); //to minimize the utilization of link capacities. 

dexpr float objmodel3 = sum(f in Flows) s[f];

maximize staticLex(objmodel3, -objmodel1, -objmodel2);

subject to{
 
//constrains with j,j+1,nj[j],nj[j+1] are wrong, I don't know how to define these.

forall (<o,d> in Edges) 

cons1: sum(f in Flows, j in 1..2: j+1 in 1..1 && nj[j] in Nodes && nj[j+1] in 0..9) (IL[<o,d>] 
[f][j][nj[j]][j+1][nj[j+1]] * landa[f]) <= C[<o,d>];

   
forall (n in Nodes)
    cons2: sum(v in V) Y[v][n] * Cpuvnf[v] <= Cpunode[n];

forall (v in V, n in Nodes)
    cons3: sum(f in Flows, j in 1..2) I[v][n][f][j] * landa[f] <= u[v][n];
      
                  
forall (n in Nodes, v in V, f in Flows, j in 1..2)
    cons4: Y[v][n] >= I[v][n][f][j];
      
      
forall (f in Flows, j in 1..2)
    cons5: sum(n in Nodes, v in V) I[v][n][f][j] == 1;
   
forall (i in Flows)
    cons6a: x[i]==s[i]+floorequ[i];                 

forall (f in Flows)
    cons7: DT + DP <= Dflow[f];       
     

    //convert non_linear_equation_11 to new linear constraints == constraints 8, 9, 10
   
    forall (f in Flows, j in 1..2: j+1 in 1..1 && nj[j] in Nodes && nj[j+1] in 0..9, v in V) 
    
    cons8: sum(<o1,d1> in Lout) z[<o1,d1>][f][j][nj[j]][j+1][nj[j+1]][v] == 1;
   
    forall (<o1,d1> in Lout, f in Flows, j in 1..2: j+1 in 1..1 && nj[j] in Nodes && nj[j+1] 
    in 0..9, v in V) {
    
    cons9: 3 * z[<o1,d1>][f][j][nj[j]][j+1][nj[j+1]][v] <= (IL[<o1,d1>][f][j][nj[j]][j+1] 
           [nj[j+1]] + I[v][nj[j]][f][j] + I[v][nj[j+1]][f][j+1]);
    
    cons10: z[<o1,d1>][f][j][nj[j]][j+1][nj[j+1]][v] >= (IL[<o1,d1>][f][j][nj[j]][j+1] 
    [nj[j+1]] + I[v][nj[j]][f][j] + I[v][nj[j+1]][f][j+1]) - 2; }
               
    //convert non_linear_equation_12 to new linear constraints == constraints 11, 12, 13

    forall (f in Flows, j in 1..2: j+1 in 1..1 && nj[j] in Nodes && nj[j+1] in 0..9, v in V) 
    
    cons11: sum(<o2,d2> in Lin) z[<o2,d2>][f][j][nj[j]][j+1][nj[j+1]][v] == 1;
   
    forall (<o2,d2> in Lin, f in Flows, j in 1..2: j+1 in 1..1 && nj[j] in Nodes && nj[j+1] in 
     0..9, v in V) {         

    cons12: 3 * z[<o2,d2>][f][j][nj[j+1]][j+1][nj[j+1]][v] <= (IL[<o2,d2>][f][j][nj[j]][j+1] 
    [nj[j+1]] + I[v][nj[j]][f][j] + I[v][nj[j+1]][f][j+1]);

     cons13: z[<o2,d2>][f][j][nj[j]][j+1][nj[j+1]][v] >= (IL[<o2,d2>][f][j][nj[j]][j+1] 
     [nj[j+1]] + I[v][nj[j]][f][j] + I[v][nj[j+1]][f][j+1]) - 2;  } 
   
      //constraints 14, 15                    

      forall(f in Flows, j in 1..2: j+1 in 1..1 && nj[j] in Nodes && nj[j+1] in 0..9, v in V){
   
       cons14: sum(<o1,d1> in Lout) IL[<o1,d1>][f][j][nj[j]][j+1][nj[j+1]] <= 1;

        cons15: sum(<o2,d2> in Lin) IL[<o2,d2>][f][j][nj[j]][j+1][nj[j+1]] <= 1; }

        //constraints 16            

        forall (f in Flows, j in 1..2: j+1 in 1..1 && nj[j] in Nodes && nj[j+1] in 0..9)

        cons16:  (sum(<o2,d2> in Lin) IL[<o2,d2>][f][j][nj[j]][j+1][nj[j+1]]) - (sum(<o1,d1> 
        in Lout) IL[<o1,d1>][f][j][nj[j]][j+1][nj[j+1]]) == 0;      

         //constraints 17, 18   

       forall (f in Flows, j in 1..2: j+1 in 1..1 && nj[j] in Nodes && nj[j+1] in 0..9, v in 
           V) {  

       cons17:  sum(<o2,d2> in Lin) IL[<o2,d2>][f][0][0][1][1] == I[v][1][f][1];

       cons18: sum(<o1,d1> in Lout) IL[<o1,d1>][f][0][0][1][1] == I[v][1][f][1];    }                       
     
       //constraints 19, 20           

       forall (f in Flows, j in 1..2: j+1 in 1..1 && nj[j] in Nodes && nj[j+1] in 0..9, v in 
        V) {

      cons19: sum(<o2,d2> in Lin) IL[<o2,d2>][f][1..2][9][1..1][10] == I[v][9][f][1..2];    

      cons20: sum(<o1,d1> in Lout) IL[<o1,d1>][f][1..2][9][1..1][10] == I[v][9][f][1..2];}}
         
       assert forall(f in Flows) s[f]==floor(x[f]);        

       execute DISPLAY_After_SOLVE {

       writeln("objmodel1==", objmodel1, "objmodel2==", objmodel2, "objmodel3==", objmodel3); 
       
            }

data file:

   Cpunode=[1, 1, 1, 5, 4, 4, 5, 1, 10, 1, 1]; //number of core for each 
   node
   
   Cpuvnf=[1, 1, 1, 1, 1]; //number of core that each vnf wants

   C=[1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 1000, 
   1000, 1000]; //1ms

    u=[[10,10,10,10,10,10,10,10,10,10,10] 
    [10,10,10,10,10,10,10,10,10,10,10] 
    [10,10,10,10,10,10,10,10,10,10,10]  
    [10,10,10,10,10,10,10,10,10,10,10]  
    [10,10,10,10,10,10,10,10,10,10,10]]; //10Mbps

    Dvn=[[0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 
         0.003, 0.003] 
     [0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 
     0.003, 0.003] 
     [0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 
     0.003, 0.003] 
     [0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 
     0.003, 0.003]  
     [0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 0.003, 
     0.003, 0.003] ]; //3ms

    Dlink=[0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 0.01, 
    0.01, 0.01, 0.01]; //10ms

    Dflow=[0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04,
    0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04,
    0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04,
    0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 0.04, 
    0.04, 0.04, 0.04, 0.04, 0.04, 0.04]; //40ms
1 Answers

If r is a range , v[r] is not a value!

So in your model you should change

cons19: sum(<o2,d2> in Lin) IL[<o2,d2>][f][1..2][9][1..1][10] == I[v][9][f][1..2];
      cons20: sum(<o1,d1> in Lout) IL[<o1,d1>][f][1..2][9][1..1][10] == I[v][9][f][1..2]; 

into

cons19: sum(<o2,d2> in Lin) IL[<o2,d2>][f][1][9][1][10] == I[v][9][f][1];   

      cons20: sum(<o1,d1> in Lout) IL[<o1,d1>][f][1][9][1][10] == I[v][9][f][1];

At least this will solve the error and you will be able to go further

Related