Solved
New Contributor
Posts: 4

# Optmodel indicator variable construction problem.

Hello.

Could somebody help me with the following problem, I have to construct dummy variables z such that:

for x>0 z = 1 otherwise z = 0

(later I plan to add those dummy variables), in order to solve an optimisation problem

I tried without much success two methods:

1)if x>0 then 1 else 0;

2) x <= x.ub * z    (taken from and example of the SAS/OR 9.3 User's Guide Mathematical Programming Examples.

None works, in the second case after solving the problem SAS returns z = 1 even for x = 0 as can be seen in the following modification of the diet problem  (here x = diet,  z = IsUsed).

1]dietIsUsed
Cheese0.4494991
Fish0.5000001
Milk0.0535991
Potato1.8651681
Yogurt0.0000001

In the case diet[Bread] = 0 and diet[Yogurt] = 0  IsUsed is equal to 1 .... and not zero as I expected. I obtaitned the result above results from the program:

proc optmodel;
/* declare index set */
set<str> FOOD;

/*set <str> al;*/

/* declare variables */
var diet{FOOD} >= 0;
var IsUsed{FOOD} Binary;

/* objective function */
num cost{FOOD};
min f=sum{i in FOOD}cost*diet;

/* constraints */
num prot{FOOD};
num fat{FOOD};
num carb{FOOD};
num cal{FOOD};
num min_cal, max_prot, min_carb, min_fat;
con cal_con: sum{i in FOOD}cal*diet >= 300;
con prot_con: sum{i in FOOD}prot*diet <= 10;
con carb_con: sum{i in FOOD}carb*diet >= 10;
con fat_con: sum{i in FOOD}fat*diet >= 8;

read data fooddata into FOOD=[name] cost prot fat carb cal;

/* bounds on variables */
diet['Fish'].lb = 0.5;
diet['Fish'].ub = 1.2;
diet['Milk'].ub = 1.6;
diet ['Potato'].ub = 10.1;
diet ['Yogurt'].ub = 0.7;
diet ['Cheese'].ub = 0.6;

/* Bin bounds */

diet[al] <= diet[al].ub * IsUsed[al];

C. FOparinetto

Accepted Solutions
Solution
‎03-18-2014 12:32 PM
SAS Employee
Posts: 538

## Re: Optmodel indicator variable construction problem.

Your "link" constraints enforce only one side of the implication (if diet > 0 then IsUsed = 1) and the solution does respect that.

If you also want the converse (if IsUsed =1 then diet > 0), then you need another set of constraints.  You also need to decide how small of a value for diet is considered to be positive.  For example, would you accept diet = 1e-6 as positive?  Suppose that your tolerance is called epsilon.  Then the following constraints should do what you want:

diet[al] >= epsilon * IsUsed[al];

All Replies
Solution
‎03-18-2014 12:32 PM
SAS Employee
Posts: 538

## Re: Optmodel indicator variable construction problem.

Your "link" constraints enforce only one side of the implication (if diet > 0 then IsUsed = 1) and the solution does respect that.

If you also want the converse (if IsUsed =1 then diet > 0), then you need another set of constraints.  You also need to decide how small of a value for diet is considered to be positive.  For example, would you accept diet = 1e-6 as positive?  Suppose that your tolerance is called epsilon.  Then the following constraints should do what you want:

diet[al] >= epsilon * IsUsed[al];

New Contributor
Posts: 4

## Re: Optmodel indicator variable construction problem.

Many thanks Rob.

diet[al] >= 1e-6*IsUsed[al];

I obtain:

[1]dietIsUsed
Cheese0.4494991
Fish0.5000001
Milk0.0535991
Potato1.8651681
Yogurt0.0000000

Best regards.

🔒 This topic is solved and locked.