Obsidian | Level 7

## WHY WE USE IMPVAR?

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
SAS Super FREQ

## Re: WHY WE USE IMPVAR?

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 Super FREQ

## Re: WHY WE USE IMPVAR?

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];
``````

Discussion stats