BookmarkSubscribeRSS Feed
orangejuss
Fluorite | Level 6

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 advance:)

5 REPLIES 5
RobPratt
SAS Super FREQ

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?

orangejuss
Fluorite | Level 6

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

RobPratt
SAS Super FREQ

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?

orangejuss
Fluorite | Level 6

Thank you:)

 

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 ;

 

RobPratt
SAS Super FREQ

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 <.

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

Multiple Linear Regression in SAS

Learn how to run multiple linear regression models with and without interactions, presented by SAS user Alex Chaplin.

Find more tutorials on the SAS Users YouTube channel.

Discussion stats
  • 5 replies
  • 990 views
  • 1 like
  • 2 in conversation