BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
karthick_gopal
Calcite | Level 5

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?

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

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:

http://go.documentation.sas.com/?docsetId=ormpex&docsetVersion=14.2&docsetTarget=titlepage.htm&local...

 

View solution in original post

2 REPLIES 2
RobPratt
SAS Super FREQ

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:

http://go.documentation.sas.com/?docsetId=ormpex&docsetVersion=14.2&docsetTarget=titlepage.htm&local...

 

SAS Innovate 2025: Call for Content

Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!

Submit your idea!

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
  • 2 replies
  • 1551 views
  • 0 likes
  • 2 in conversation