SAS Optimization, and SAS Simulation Studio

turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-13-2017 01:22 AM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to orangejuss

12-13-2017 12:47 PM

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?

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RobPratt

12-14-2017 03:17 AM

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

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to orangejuss

12-14-2017 11:10 AM - edited 12-14-2017 11:13 AM

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?

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RobPratt

12-15-2017 02:41 AM

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 ;

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to orangejuss

12-15-2017 03:23 PM

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