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

Hi,

I dont know why we use IMPVAR.

I have the following code

PROC OPTMODEL;
/* declare sets and parameters */
set RESOURCES = /labor metal wood/;
set PRODUCTS = /desks chairs bookcases bedframes/;
num selling_price {PRODUCTS} = [94 79 125 109];
num cost {RESOURCES} = [14 20 11];
num availability {RESOURCES} = [225 117 420];
num required {PRODUCTS, RESOURCES} =
[2 1 3
1 1 3
3 1 4
2 1 4];
/* declare variables */
var NumProd {PRODUCTS} >= 0;
impvar Revenue = sum {p in PRODUCTS}
selling_price[p] * NumProd[p];
impvar AmountUsed {r in RESOURCES} =
sum {p in PRODUCTS} NumProd[p] * required[p,r];
impvar TotalCost = sum {r in RESOURCES}
cost[r] * AmountUsed[r];
/* declare constraints */
con Usage {r in RESOURCES}:
AmountUsed[r] <= availability[r];
/* declare objective */
max NetProfit = Revenue - TotalCost;
/*print model formulation*/
expand;
/*solve the model*/
solve;
/*print parts of the model*/
print NumProd;
quit;

I have two question:

1-Please can someone tell me why are we using IMPVAR?

2- Can someone solve the above example using VAR only so that I can know the difference between VAR and IMPVAR.

thanks

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

As described here, implicit variables are useful when the same expression is needed in several places and you don't want to increase the number of explicit variables and constraints.

For your code, if you wanted to replace the first implicit variable, for example, it would look like this:

*impvar AmountUsed {r in RESOURCES} =
   sum {p in PRODUCTS} NumProd[p] * required[p,r];
var AmountUsed {RESOURCES};
con AmountUsedCon {r in RESOURCES}: AmountUsed[r] =
   sum {p in PRODUCTS} NumProd[p] * required[p,r];

 

View solution in original post

1 REPLY 1
RobPratt
SAS Super FREQ

As described here, implicit variables are useful when the same expression is needed in several places and you don't want to increase the number of explicit variables and constraints.

For your code, if you wanted to replace the first implicit variable, for example, it would look like this:

*impvar AmountUsed {r in RESOURCES} =
   sum {p in PRODUCTS} NumProd[p] * required[p,r];
var AmountUsed {RESOURCES};
con AmountUsedCon {r in RESOURCES}: AmountUsed[r] =
   sum {p in PRODUCTS} NumProd[p] * required[p,r];

 

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

Register now!

Discussion stats
  • 1 reply
  • 2243 views
  • 0 likes
  • 2 in conversation