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

- Subscribe to 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
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

02-06-2017 12:12 AM

Hi,

I am trying to do an iterative linearization procedure by row generation in proc optmodel. Between successive iterations i need to find the argmax of the current solution and also store the solution value of that particular index to add a cut and the cuts keep accumulating until convergence is reached. I could not find a fucntion that could give me the index. what is the best way to go about this?

Accepted Solutions

Solution

02-07-2017
05:38 AM

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

Posted in reply to karthick_gopal

02-06-2017 10:57 AM - edited 02-06-2017 11:20 AM

There is no built-in support for argmax of an array, but here are five ways to compute it yourself:

```
proc optmodel;
set MYSET = /a b c d e/;
num a {MYSET} = [13 100 37 100 42];
num max = max {i in MYSET} a[i];
put max=;
/* set of indices that achieve the max */
set ARGMAXSET = {i in MYSET: a[i] = max};
put ARGMAXSET=;
/* last index that achieves the precomputed max */
str argmax;
for {i in MYSET: a[i] = max} argmax = i;
put argmax=;
/* first index that achieves the precomputed max */
for {i in MYSET: a[i] = max} do;
argmax = i;
leave;
end;
put argmax=;
/* last index that achieves the max, calculated within the loop */
num max1 init -constant('BIG');
for {i in MYSET} do;
if max1 <= a[i] then do;
max1 = a[i];
argmax = i;
end;
end;
put max1= argmax=;
/* first index that achieves the max, calculated within the loop */
num max2 init -constant('BIG');
for {i in MYSET} do;
if max2 < a[i] then do;
max2 = a[i];
argmax = i;
end;
end;
put max2= argmax=;
quit;
```

For some examples of row generation in PROC OPTMODEL, see this SAS Global Forum paper...

http://support.sas.com/resources/papers/proceedings16/SAS3161-2016.pdf

...and the "Milk Collection" and "Lost Baggage Distribution" examples in the SAS/OR doc:

All Replies

Solution

02-07-2017
05:38 AM

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

Posted in reply to karthick_gopal

02-06-2017 10:57 AM - edited 02-06-2017 11:20 AM

There is no built-in support for argmax of an array, but here are five ways to compute it yourself:

```
proc optmodel;
set MYSET = /a b c d e/;
num a {MYSET} = [13 100 37 100 42];
num max = max {i in MYSET} a[i];
put max=;
/* set of indices that achieve the max */
set ARGMAXSET = {i in MYSET: a[i] = max};
put ARGMAXSET=;
/* last index that achieves the precomputed max */
str argmax;
for {i in MYSET: a[i] = max} argmax = i;
put argmax=;
/* first index that achieves the precomputed max */
for {i in MYSET: a[i] = max} do;
argmax = i;
leave;
end;
put argmax=;
/* last index that achieves the max, calculated within the loop */
num max1 init -constant('BIG');
for {i in MYSET} do;
if max1 <= a[i] then do;
max1 = a[i];
argmax = i;
end;
end;
put max1= argmax=;
/* first index that achieves the max, calculated within the loop */
num max2 init -constant('BIG');
for {i in MYSET} do;
if max2 < a[i] then do;
max2 = a[i];
argmax = i;
end;
end;
put max2= argmax=;
quit;
```

For some examples of row generation in PROC OPTMODEL, see this SAS Global Forum paper...

http://support.sas.com/resources/papers/proceedings16/SAS3161-2016.pdf

...and the "Milk Collection" and "Lost Baggage Distribution" examples in the SAS/OR doc:

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

Posted in reply to RobPratt

02-07-2017 01:23 PM

Thank you rob!