You are on page 1of 5

BinaryVariablesCookbook

LMH,2012

DRAFTPleaseletmeknowifyoufindanymistakes!Alsoifthereissomethingelseyouthinkshould
beonhereletmeknowandIlladdit.

Note:ThroughoutthisdocumentyoucanassumeanyvariablelabeledasXisbinary(0,1).Anyvariable
labeledasQiscontinuous(usuallynonnegative)

1.Simplebinarychoices(e.g.Tazerinvestornotinoneoffiveprojects)
Procedure:Definedecisionvariabledasbinary(X1,X2XN);usethemintheobjective
2.Binarychoiceswithsimplequantitativeconstraints(e.g.investinnomorethan3projects)
Procedure:Definedecisionvariablesasbinary(notationasabove);Writeconstraintsofthe
form
X1+X2XN>=SomeNumber
or
X1+X2+XN<=SomeNumber
Seelogicpartbelowformorecomplexinterrelationships
2.Simplebinarychoicesthataffectnumericconstraintsorobjectives(Examples:buyingextraalmonds
infabulousnuts).Theexamplebelowisafixedcostinvestment,butthereareothervariantsthatare
similar.
Procedure:
Defineabinarydecisionvariable(callitX)
Addintotheobjective:Max[OriginalObjectiveCostofInvestment*X]
Addintotheconstraint:SomeLHS<=SomeRHS+ExtraStuff*X

Orinstandardform:SomeLHSExtraStuff*X<=SomeRHS

3.Fixedcostplantdecision(Example:DeluxeCanscannotproduceanythingwithoutaninvestment;
withinvestmentquantityisunconstrained)
Procedure:
Defineabinarydecisionvariable(callitX)tocontrolacontinuousvariable(Q)
ChooseavalueforBigMwhichislargerthananyconceivablevalueofQ

Addintotheobjective:MaxOriginalObjectiveCostofInvestment*X
Constraintform:

Q<=BigM*X

Orinstandardform:

QBigM*X<=0

Whythisworks:

IfX=0thentheconstraintbecomesQ<=0,butsinceQ>=0thismeansthatQ=0

IfX=1thentheconstraintbecomesQ<=BigM

Inotherwords,unconstrained

Note:Youcanreversethislogictosetabinaryvariableto1whensomethingisgreaterthanorlessthan
aspecifiedquantity.
4.Identifyinginequalitiessetabinaryvariableto1whenavariableexceedsacertainvalue.
Procedure:

Defineabinaryvariable(X)andavariableitistiedto(Q)

TosetX=1ifQ>SomeNumbertry:
Q+BigM*(1X)>=SomeNumber

QBigM*X<=SomeNumber

Toseewhythisworks:
SupposeQ>SomeNumberthenthefirstconstraintneverbindsXcanbe0or1,butthesecond
constraintrequiresX=1.Thus,ifQ>=SomeNumberthenXmustbe1
SupposeQ<SomeNumberthenthefirstconstraintforcesXtobe0,whilethesecondconstraint
leavesXunconstrained.
ThecombinationofthesetwothereforetakecareofbothpossibleconditionsforQ
Note:thatgiventhewaythisiswrittenQ=SomeNumberleavesXunconstrained.
AlsoNote:Thisisverysimilarto#4above.

5.Piecewisefunctions.Youhavealreadyseenthisabove#2appliedtoconstraints,butyouusethis
typeoflogictocreatepiecewiseobjectivefunctions.
Forinstance,ifyouhaveanXvariablethatrepresentssomecondition(definedbysomesetof
constraintselsewhere)youcanwriteanobjectivethathasadifferentslopedependingonX.

Procedure:

DefineabinaryvariableX.Createconstraintsthatsetsittothecorrectvalue

Objectivecanbewrittenas:X*Q+(1X)*More*Q

SoifX=1thentheobjectiveisMaxQ,whenX=0theObjectiveisMore*Q

UsuallyyouwouldusethiswhenXissetbasedonarangeofQvalues(see#4above)
Beware:YouwillnotethatXismultipliedbyQ.Thistypeofformulationshouldbeavoidedas
muchaspossiblebecauseitisextremelydifficulttosolvenumerically.Idontthinkyoucanget
aroundthatherebutyoushouldnotethatthisissomethingwenormallytrytoavoid.Solver
maynotbeabletosolvethisproperly.

6.MutualExclusionforcingacontinuousvariabletoonlytakeoncertainvalues.
Procedure:
Defineabinarydecisionvariable(callitX)andavariableyouaregoingtocontrol(Q)
DoNOTputitintheobjective
Constraint:Q=SomeNumber*X+SomeOtherNumber(1X)

(thus,QcaneitherbeSomeNumberorSomeOtherNumberbutnothingelse)

ExtendstoarbitrarynumberofchoiceswithmoreXs.Forinstance,Q=100or500or1000
Q=100X1+500X2+1000X3
X1+X2+X3=1
Technicallyyoucangetawaywith1lessbinaryvariablethanallowedvalueofQ,butitisusually
easierjusttohaveonevariableforeachvalueandtoaddtheconstraintasabove.Sotheabove
canberewrittenas:
Q=100*X1+500*X2+1000*(1X1X2)
X1+X2<=1
7.LogicProblems.Thiswascoveredintheslides:
IfX1XNarebinaryvariables(inputs)andYisabinaryoutputthen
OR:Y>=X1,Y>=X2Y>=XN,Y<=X1+X2XN
AND:Y<=X1,Y<=X2.Y>=X1+X2+X3XN(N1)

NOT:Y=1X1
CancombineintovariouscombinationsusingintermediateY:
ForinstanceY=X1AND(X2ORX3)
StartwithdefiningaYforeachterm
Y1>=X2,Y1>=X3,Y1<=X2+X3(thisimplementstheX2orX3)
Then
Y<=X1,Y<=Y1,Y>=X1+Y21

8.MinimumandMaximumConstraints
SupposeyouhavetwodecisionvariablesR1,R2andyouwanttomakeQhaveaspecificrelationshipto
them.Therearereallyfourpossibilities,twoofwhicharetrivialanddontrequirebinary:
a.Q>=Max(R1,R2)iseasy.JustQ>=R1,Q>=R2
b.Q<=Min(R1,R2)isalsoeasy.JustQ<=R1,Q<=R2
Theseworkbecauseonlyonebinds,theotherisslack.Weusedthistechniqueintheproject
managementcrashingproblem.
However,youmaywantmorecomplicatedrelationshipssuchas:
c.Q>=Min(R1,R2).Thisiskindofhard.Youcombinethetechniqueformutualexclusion(#6)withthe
techniqueinpart#4tosetX=1ifR1>R2
Thatwouldbe:
R1+BigM*(1X)>=R2

R1BigM*X<=R2

ThenyoucanwriteQ>=R1*(1X)+R2*X
Inotherwords,thefirsttwoconstraintscompareR1andR2andsetX=1ifR1isgreater.Thenyouselect
whethertouseR1orR2asthelowerbounddependingonwhichisless(ifX=1ifR1isgreaterthen1
X1=1ifitisless).
d.Q<=Max(R1,R2)usesthesametechniquetodefineXandthentheconstraintbecomes

Q<=R1*X+R2*(1X)

___Thatsallfolks!

You might also like