Hi,
I am trying to create a code like this;
,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:)
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?
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
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?
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 ;
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 <.
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.