$title HowMany example: Logical constraints option limrow=0, limcol=0, decimals=0, solprint=off; $ontext Consider the following situation: There are 30 people in a class. All of them have taken either 320 or 340, with at least 10 taking each of these classes. 8 of them have taken 364. 10 of them are female. 10 of them are undergraduates. 15 of them are in CS, 10 in Math, 5 in IE. 12 are graduating in December. At least half of the IE undergrads are male. Of the male IE undergraduates, 2 have taken both 364 and 320 OR will graduate in December. Is it possible that there is a female IE undergraduate, graduating in December, that has taken both 320 and 364? If so, what is the maximum number of people that fall into this category? $offtext set i /1*30/; binary variable x320(i), x340(i), x364(i), ugrad(i), cs(i), math(i), ie(i), december(i), female(i); variable howmany; equations c1,c2,c3,c4,c5,c6,c7,c8,c9,c10,c11,c12,c13,c14,c15,c16,c17, c18,c19,c20,c21,c22,c23,c24,c25,c26,c27,c28,c29,c30,c31,c32, objective; * all have taken either 320 or 340 c1(i).. x320(i)+x340(i) =g= 1; * at least 10 have taken 320 c2.. sum(i,x320(i)) =g= 10; * at least 10 have taken 340 c3.. sum(i,x340(i)) =g= 10; * 8 have taken 364 c4.. sum(i,x364(i)) =e= 8; * 10 are female c5.. sum(i,female(i)) =e= 10; * 10 are undergraduates c6.. sum(i,ugrad(i)) =e= 10; * 15 of them are in CS, 10 in Math, 5 in IE. c7.. sum(i,cs(i)) =e= 15; c8.. sum(i,math(i)) =e= 10; c9.. sum(i,ie(i)) =e= 5; * 12 are graduating in December. c10.. sum(i,december(i)) =e= 12; * introduce AND constraint for IE + undergrads positive variable IEugrad(i); IEugrad.up(i) = 1; c11(i).. IEugrad(i) =l= ie(i); c12(i).. IEugrad(i) =l= ugrad(i); c13(i).. IEugrad(i) =g= ie(i) + ugrad(i) -1; * introduce an AND constraint for female + IE undergrads positive variable femaleIEugrad(i); femaleIEugrad.up(i) = 1; c14(i).. femaleIEugrad(i) =l= IEugrad(i); c15(i).. femaleIEugrad(i) =l= female(i); c16(i).. femaleIEugrad(i) =g= IEugrad(i) + female(i) - 1; * male IE ugrads positive variable maleIEugrad(i); c17(i).. maleIEugrad(i) =e= IEugrad(i) - femaleIEugrad(i); * At least half of the IE undergrads are male. c18.. sum(i,maleIEugrad(i)) =g= sum(i,IEugrad(i)) / 2; * variable for those who have taken both 320 AND 364 positive variable x320364(i); x320364.up(i) = 1; c19(i).. x320364(i) =l= x320(i); c20(i).. x320364(i) =l= x364(i); c21(i).. x320364(i) =g= x320(i) + x364(i) -1; * variable for those who have taken 320 and 364 OR graduate in Dec positive variable g320364(i); g320364.up(i) = 1; c22(i).. g320364(i) =g= x320364(i); c23(i).. g320364(i) =g= december(i); c24(i).. g320364(i) =l= x320364(i) + december(i); * variable for those who are both (male IE undergrads) * AND (have taken 320 and 364 or graduate in Dec) positive variable elite(i); elite.up(i) = 1; c25(i).. elite(i) =l= g320364(i); c26(i).. elite(i) =l= maleIEugrad(i); c27(i).. elite(i) =g= g320364(i) + maleIEugrad(i) -1; * Of the male IE undergraduates, 2 have taken both 364 and 320 or will * graduate in December. c28.. sum(i, elite(i)) =e= 2; * variable representing (female IE undergrad) AND (graduates in Dec) * AND (taken both 320 and 364). positive variable possible(i); possible.up(i) = 1; c29(i).. possible(i) =l= femaleIEugrad(i); c30(i).. possible(i) =l= december(i); c31(i).. possible(i) =l= x320364(i); c32(i).. possible(i) =g= femaleIEugrad(i) + december(i) + x320364(i)-2; objective.. howmany =e= sum(i,possible(i)); model students /all/; students.optca = .999; solve students using mip maximizing howmany; parameter num320, num340, num364, numugrad, numfemaleIEugrad, nummaleIEugrad; num320=sum(i,x320.l(i)); num340=sum(i,x340.l(i)); num364=sum(i,x364.l(i)); numugrad=sum(i,ugrad.l(i)); numfemaleIEugrad=sum(i,femaleIEugrad.l(i)); nummaleIEugrad=sum(i,maleIEugrad.l(i)); display howmany.l; display num320, num340, num364, numugrad, numfemaleIEugrad, nummaleIEugrad;