BookmarkSubscribeRSS Feed
shidehrafigh
Fluorite | Level 6

Hi

 

I am going through the example on SAS's website to learn about Proc Optmodel (the link below).

https://documentation.sas.com/?cdcId=pgmsascdc&cdcVersion=9.4_3.2&docsetId=casmopt&docsetTarget=casm...

 

code taken from SAS website:
proc optmodel;
/* declare sets and data indexed by sets */
set <string> Products;
set <string> Processes;
num Profit{Products};
num AvailableTime{Processes};
num RequiredTime{Products,Processes};
/* declare the variable */
var Amount{Products};
/* maximize objective function (profit) */
maximize TotalProfit = sum{p in Products} Profit[p]*Amount[p];
/* subject to constraints */
con Availability{r in Processes}:
sum{p in Products} RequiredTime[p,r]*Amount[p] <= AvailableTime[r];
/* abstract algebraic model that captures the structure of the */
/* optimization problem has been defined without referring */
/* to a single data constant */
/* populate model by reading in the specific data instance */
read data Products into Products=[name] Profit;
read data Processes into Processes=[name] AvailableTime=Available_time
{p in Products} <RequiredTime[p,name]= col(p)>;
/* solve LP using primal simplex solver */
solve with lp / solver = primal_spx;
/* display solution */
print Amount;
quit;

 

1- My first question is on the parameter RequiredTime that  is being defined by two sets (products and processes).

num RequiredTime{Products,Processes};

Requiredtime is only available in processess data set and not in products, what is the logic for defining this parameter against two datasets one of which does not contain this attribute?

2- the next question is if anyone can help me understand the constraint which is  summarizing all 4 constraints as explained in the example in one line?

 

Thank you

 

2 REPLIES 2
Ksharp
Super User

Check the INDEX :
set <string> Products;
set <string> Processes;
And using the following to make them happen ( have value ).
read data Products into Products=[name]
read data Processes into Processes=[name]

You can refer to the value by these two INDEX , just as x{i} , I is INDEX .

And better post it at OR forum and calling  @RobPratt 

RobPratt
SAS Super FREQ

1. The confusion might stem from the fact that the names Products and Processes are both used in two different ways: as OPTMODEL sets and as SAS DATA sets.  In this example, except for the first word after READ DATA, they always refer to OPTMODEL sets.  To help see what is going on, I recommend using the PRINT statement after the second READ DATA statement populates the RequiredTime parameter:

print RequiredTime;

2. To see what the CON statement is doing, I recommend using the EXPAND statement:

expand Availability;

You will see four constraints (one per member of the Processes set), as in the previous PROC OPTMODEL session in this example.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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