如何在集中定义路径/路线?

问题描述

我正在尝试使用 CPLEX 来确定电动汽车充电站的位置。我创建了5个节点,m辆汽车在2条路线上行驶,并由不同的节点停止。根据这些信息,应该确定充电站的最佳位置。基本草图:

Basic sketch

这是我编写的CPLEX代码的开头:

//sets
 int n=...;  //nodes
 int a=...;  //path
 int m=...;  //set of ES travel on path
 int cost=...; //cost of locating a station at node i
 float rechargerate=5;     //increased riding distance per charge (km/min)
 int batterycapacity=5;   //full charge range
 
 range N=1..n;
 range M=1..m;
 range A=1..a;
 
 
 tuple edge        
 {int i; 
 int j;
 }
setof(edge) edges       = {<i,j> | i,j in N : i!=j};

tuple link {
    key string link_id;
    string    org;
    string   dst;
}

{link} Links={<"l1","1","2">,<"l2","3">,<"l3","3",<"l4","2","5">,"4","2">};

这里的问题是,我无法在集合中定义路径,而且链接的起点/终点应在中定义。如何定义它们以找到RS定位的最佳解决方案?是的

解决方法

tuple link {
    string link_id;
    string    org;
    string   dst;
}

{link} Links={<"l1","1","2">,<"l2","3">,<"l3","3",<"l4","2","5">,"4","2">};

tuple od
{
  string org;
  string dst;
}

{od} ods={<i.org,i.dst> | i in Links};

sorted {string} points={l.org | l in Links} union {l.dst | l in Links};

range N=1..card(points);

tuple edge        
 {int i; 
 int j;
 }
setof(edge) edges       = {<i,j> | i,j in N : <item(points,i-1),item(points,j-1)> in ods};

execute
{
  writeln(edges);
}

可以将您的链接变成边缘