在 cplex 中定义两个集合

Defining two sets in cplex

我是 Cplex 的新手,我想定义两个名为 PathOfEdge 的集合(工作路线交叉 link i 的节点集合)和 PathOfOut((工作路线不交叉的节点集合 link i)) 在 cplex 中,如何定义 PathOfOut 集?

// 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]=...;

PathOfEdge 是否正确?

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

我的一小部分网络中k-最短路径的代码:

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

以及节点和 link 网络。

    //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>,
    ....}

这看起来不错:

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);
 }

给予

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

之后

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

 execute
 {
  writeln(PathOfOut);
 }

这给出了

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

问候