Operations Research topics: SAS/OR,
SAS Optimization, and SAS Simulation Studio

VRP- with multiple tables

Reply
New Contributor
Posts: 4

VRP- with multiple tables

Hi,

 

 

I am trying to create a code like this;

 

http://support.sas.com/documentation/cdl/en/ormpug/67517/HTML/default/viewer.htm#ormpug_decomp_examp...

 

,but with two tables.

 

First table is node_table includes nodes,vehicle_type etc.

 

Second table is vehicle_table includes type, capacity .

 

vehicle_type from node_table and type from vehicle_table are same. Should I  specify this in code, and how?

 

And I want to add a capacity  constraint  for each type of vehicle?How can I add this?

 

Thanks in advanceSmiley Happy

SAS Employee
Posts: 540

Re: VRP- with multiple tables

Posted in reply to orangejuss

Suppose your vehicle_table looks like this (with possibly different capacity values across vehicles):

data vehicle_data;
   input vehicle capacity;
   datalines;
1 3000
2 3000
3 3000
4 3000
5 3000
6 3000
7 3000
8 3000
;

Then in the PROC OPTMODEL code, you would have:

   set VEHICLES;
   num capacity {VEHICLES};
   read data vehicle_table into VEHICLES=[vehicle] capacity;

And you would also need to change the Flow declaration as follows:

   var Flow {ARCS, k in VEHICLES} >= 0 <= capacity[k];

Regarding vehicle_type, do you want to restrict which vehicles can service each node?

New Contributor
Posts: 4

Re: VRP- with multiple tables

Sorry, I described the problem a little bit wrong .

 

The data vehicle_data and node_data like as follows.


data vehicle_data;
input vehicle capacity type
datalines;
1 20 a
2 50 a
3 25 b
4 30 all
5 40 a
6 15 b
7 25 a
8 20 all
;

data node_data;
input node vehicle_type ;
datalines;
1 a
2 b
3 b
4 a
5 a
6 a
7 b
8 b
9 b
10 a
;

The capacity constraint I  wrote is total_time. I am calculating travel time between nodes and adding capacity(it is time variable),
total_time should less than or equal to 5 hours. But I am not sure  that is calculated seperately for each type o vehicle.
And I want to restrict vehicles as their type.For instance, vehicle which is type a , should visit the node that has job a. Vehicle which type is all ,can visit every node.

 

Thank you

SAS Employee
Posts: 540

Re: VRP- with multiple tables

[ Edited ]
Posted in reply to orangejuss

Here's how you can enforce the type restrictions:

data vehicle_data;
   input vehicle capacity type $;
   datalines;
1 20 a
2 50 a
3 25 b
4 30 all
5 40 a
6 15 b
7 25 a
8 20 all
;
data node_data;
   input node vehicle_type $;
   datalines;
1 a
2 b
3 b
4 a
5 a
6 a
7 b
8 b
9 b
10 a
;

proc optmodel;
   set VEHICLES;
   num capacity {VEHICLES};
   str type {VEHICLES};
   read data vehicle_data into VEHICLES=[vehicle] capacity type;

   set NODES;
   str vehicle_type {NODES};
   read data node_data into NODES=[node] vehicle_type;

   set NODES_k {k in VEHICLES} = {i in NODES: type[k] in {'all',vehicle_type[i]}};
   put NODES_k[*]=;
   set ARCS_k {k in VEHICLES} = {i in NODES_k[k], j in NODES_k[k]: i ne j};

   var Flow {k in VEHICLES, <i,j> in ARCS_k[k]} >= 0;
quit;

 

Or, if you prefer to keep the indexing of the original example, with k last:

   set ARCS_VEHICLES = setof {k in VEHICLES, <i,j> in ARCS_k[k]} <i,j,k>;
   var Flow {<i,j,k> in ARCS_VEHICLES} >= 0;

And similar changes for UseNode and UseArc.

 

 

What does your capacity constraint look like?

New Contributor
Posts: 4

Re: VRP- with multiple tables

Thank youSmiley Happy

 

the constraint I wrote look like this;

 

num time_minute{<i,j> in arcs}= traveltime[i,j]+capacity[j]; 

 

con _capacity{<i,j> in arcs}: sum{k in vehicles} time_minute[i,j] *usearc[i,j,k]<5*60 ;

 

SAS Employee
Posts: 540

Re: VRP- with multiple tables

Posted in reply to orangejuss

I suspect that you want a constraint for each vehicle instead, as follows:

con _capacity{k in vehicles}: sum{<i,j> in arcs} time_minute[i,j] *usearc[i,j,k]<=5*60 ;

And notice the <= rather than <.

Ask a Question
Discussion stats
  • 5 replies
  • 260 views
  • 1 like
  • 2 in conversation