我是Cplex的新手,我想在cplex中定义两个名为PathOfEdge(工作路径交叉链接i的节点集)和PathOfOut((工作路由不跨越链路i的节点集))的两个集合,怎么能我定义了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]=...;
PathOfEdge是否正确?
//PathOfEdge
{path_edge} PathOfEdge[l in Links]= {<dem,k>|dem in Demands, k in K_sp : l in PathOfDemands[dem][k]};
我网络中k-shortest路径代码的一小部分:
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
以及网络的节点和链接。
//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>,
....}
答案 0 :(得分:1)
这看起来是正确的:
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>}]
问候