How paths/routes are defined in sets?

78 Views Asked by At

I am trying to decide the location of recharge station for electric vehicles by using CPLEX. I have created 5 nodes and m vehicles are traveling on 2 routes stopping by different nodes. According to that information, optimum location of the recharge stations should be decided. Basic sketch:

Basic sketch

Here is the beginning of the CPLEX code I wrote:

//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">};

The problem here is, I could not define the paths in the A set also the links start/end points should be in defined in edges. How can I define them to find an optimal solution for RS locations? Ty.

1

There are 1 best solutions below

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

can transform your Links into edges