## Proc Optmodel constraint help

Could someone help me figure out how to add a constraint that requires at least one of adwords 3,5,7 to be bought?

proc optmodel;
num revperconversion=10;
solve;
Quit;

1 ACCEPTED SOLUTION

Accepted Solutions

## Re: Proc Optmodel constraint help

First a correction to your constraint:

``con buyAtMostOfOdd: sum{a in ADWORDS: mod(a,2) = 1}buy[a]<=20;``

Now here is a way to force 3, 5, 7:

``````con AtLeastOne357: sum {a in {3,5,7}} buy[a] >= 1;
``````

And here are four alternative ways to avoid 35.

Explicit constraint:

``con No35: buy = 0;``

Fixed variable:

``fix buy = 0;``

Change index set declaration:

``set ADWORDS = 1..100 diff {35};``

Modify index set after declaration:

``````set ADWORDS init 1..100;
2 REPLIES 2

## Re: Proc Optmodel constraint help

First a correction to your constraint:

``con buyAtMostOfOdd: sum{a in ADWORDS: mod(a,2) = 1}buy[a]<=20;``

Now here is a way to force 3, 5, 7:

``````con AtLeastOne357: sum {a in {3,5,7}} buy[a] >= 1;
``````

And here are four alternative ways to avoid 35.

Explicit constraint:

``con No35: buy = 0;``

Fixed variable:

``fix buy = 0;``

Change index set declaration:

``set ADWORDS = 1..100 diff {35};``

Modify index set after declaration:

``````set ADWORDS init 1..100;