cplexibm-ilog-opl

Defining two sets in cplex


I am new to Cplex an I want to define two sets named PathOfEdge (Set of nodes whose working routes cross link i) and PathOfOut ((Set of nodes whose working routes does not cross link i))in cplex, How can I define PathOfOut set ?

// Basic network configuration nodes and links

{string} Hubs = ...;

tuple link {

    key string link_id;
    string    org;
    string   dst;
}
tuple demand {
    string    org;
    string    dst;
}
tuple path_edge
{   demand request;
    int k_sp;

    {link} Links = ...;
    // basic demand creation based on origin and destination node.
    {demand} Demands ={<source,tail>|source in Hubs, tail in Hubs: source!= tail };
    //Set of eligible routes for recovery of the ith span failure.
    {link} PathOfDemands[Demands][K_sp]=...;

Is it correct for PathOfEdge?

    //PathOfEdge 
{path_edge} PathOfEdge[l in Links]= {<dem,k>|dem in Demands, k in K_sp : l in PathOfDemands[dem][k]};

A small part of my code for k-shortest path in the network:

PathOfDemands=[
//node1
//node1->2

[{<link1 , node1, node2>},  {<link2, node1, node6>,<link11, node6, node2>},     {<link2 , node1, node6>,<link5 , node6, node5>,<link6 , node5, node3>,<link13, node3, node2>}],

//node 1->6
[{<link2 , node1, node6>},       {<link1, node1, node2>,<link3 , node2, node6>},        {<link1, node1, node2>,<link4 , node2, node3>,<link14, node3, node5>,<link12, node5, node6>}],

//node 1->3
[{<link1 , node1, node2>,<link4 , node2, node3>},     {<link2 , node1, node6>,<link11, node6, node2>,<link4 , node2, node3>},    {<link2 , node1, node6>,  <link5 , node6, node5>,<link6 , node5, node3>}],

//node 1->5
[{<link2 , node1, node6>,<link5 , node6, node5>},   {<link1 , node1, node2>,<link3 , node2, node6>,<link5 , node6, node5>},     {<link1 , node1, node2>, <link3 , node2, node6>,<link6 , node3, node5>}],

//node 1->4
[{<link1 , node1, node2>,<link4 , node2, node3>,<link8 , node3, node4>},        {<link2 , node1, node6>,<link5 , node6, node5>,<link7 , node5, node4>},     {<link1 , node1, node2>,<link5 , node3, node4>,<link5 , node6, node5>,<link7 , node5, node4>}],

//node2

//node2->1
.
.
.
//node 6->5

and nodes and links of the network.

    //define nodes of n6s8 network.
        Hubs = {
           node1,
           node2,
           node3,
           node4,
           node5,
           node6,

    };
    //
    Links = {
      <link1 , node1, node2>,
      <link2 , node1, node3>,
      <link3 , node2, node3>,
      <link4 , node2, node4>,
      <link5 , node3, node4>,
      <link6 , node3, node5>,
      <link7 , node4, node5>,
      <link8 , node4, node6>,
      <link9 , node5, node6>,
    ....}

Solution

  • This looks right:

    tuple link {
        key string link_id;
        string    org;
        string   dst;
    }
    
    {link} Links={<"l1","A","B">,<"l2","B","C">,<"l3","C","D">,<"l4","D","E">};
    
    // basic demand creation based on origin and destination node.
    {int} Demands = {1,2};
    {int} K_sp={3,4};
    
    //Set of eligible routes for recovery of the ith span failure.
    {link} PathOfDemands[Demands][K_sp]=[[
    {<"l1","A","B">,<"l3","C","D">,<"l4","D","E">},
    {<"l2","B","C">,<"l3","C","D">,<"l4","D","E">}],
    [{<"l1","A","B">,<"l2","B","C">,<"l4","D","E">},
    {<"l1","A","B">,<"l2","B","C">,<"l3","C","D">}]
    ];
    
    tuple path_edge
    {   int request;
        int k_sp;
    }
    
    //PathOfEdge 
    {path_edge} PathOfEdge[l in Links]=
     {<dem,k>|dem in Demands, k in K_sp : l in PathOfDemands[dem][k]};
    
    
     execute
     {
      writeln(PathOfEdge);
     }
    

    gives

    [{<1 3> <2 3> <2 4>} {<1 4> <2 3> <2 4>} {<1 3> <1 4> <2 4>} {
            <1 3> <1 4> <2 3>}]
    

    and then later

    {path_edge} PathOfOut[l in Links]= 
     {<dem,k>|dem in Demands, k in K_sp : l not in PathOfDemands[dem][k]};
    
     execute
     {
      writeln(PathOfOut);
     }
    

    which gives

    [{<1 4>} {<1 3>} {<2 3>} {<2 4>}]
    

    regards