0

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

基本草图

这是我编写的 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","1","3">,<"l3","3","2">,<"l4","2","5">,<"l4","4","2">};

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

4

1 回答 1

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

{link} Links={<"l1","1","2">,<"l2","1","3">,<"l3","3","2">,<"l4","2","5">,<"l4","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);
}

可以将您的链接转换为边缘

于 2020-09-18T11:35:02.423 回答