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

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

 

Also how to force the model to never buy adword 35?

 

Thank you in advance!

 

proc optmodel;
set ADWORDS = 1..100;
num cost_per_click{ADWORDS} = ranuni(123);
num clicks{ADWORDS} = ranuni(567);
num conversions{ADWORDS} = ranuni(789);
num revperconversion=10;
var buy{ADWORDS} >=0;
max effectiveness =sum{a in ADWORDS}((revperconversion*conversions[a])-(clicks[a]*cost_per_click[a]))*buy[a];
con buyAtMost50: sum{a in ADWORDS}buy[a]<=50;
con buyAtMostOfEven: sum{a in ADWORDS: mod(a,2) = 0}buy[a]<=10;
con buyAtMostOfOdd: sum{a in ADWORDS: mod(a,1) = 0}buy[a]<=20;
solve;
Quit;

1 ACCEPTED SOLUTION

Accepted Solutions
RobPratt
SAS Super FREQ

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[35] = 0;

Fixed variable:

 

fix buy[35] = 0;

Change index set declaration:

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

Modify index set after declaration:

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

View solution in original post

2 REPLIES 2
RobPratt
SAS Super FREQ

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[35] = 0;

Fixed variable:

 

fix buy[35] = 0;

Change index set declaration:

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

Modify index set after declaration:

set ADWORDS init 1..100;
ADWORDS = ADWORDS diff {35};
SAScowboy
Fluorite | Level 6

Thank you again! 

hackathon24-white-horiz.png

2025 SAS Hackathon: There is still time!

Good news: We've extended SAS Hackathon registration until Sept. 12, so you still have time to be part of our biggest event yet – our five-year anniversary!

Register Now

Discussion stats
  • 2 replies
  • 1003 views
  • 1 like
  • 2 in conversation