How can I minimize or maximize a function (even numerically) with logical arguments, taking only 0s and 1s, also with constraints? E.g.
NMinimize[{x1 * 24 + x2*51 + x1*x2 *36, 12 x1+36 x2<44}, {x1,x2}]
The example of course is stupid one, but question as a matter of principle, when you have many arguments.
Min[Pick[Outer[Function[{x1, x2}, x1*24 + x2*51 + x1*x2*36], {0, 1}, {0, 1}], Outer[Function[{x1, x2}, 12 x1 + 36 x2 < 44], {0, 1}, {0, 1}]]]
? $\endgroup$Min[Pick[Function[{x1, x2}, x1*24 + x2*51 + x1*x2*36] @@@ Tuples[{0, 1}, 2], Function[{x1, x2}, 12 x1 + 36 x2 < 44] @@@ Tuples[{0, 1}, 2]]]
. Adjust the second argument ofTuples[]
as seen fit. $\endgroup$NMinimize[{x1*24 + x2*51 + x1*x2*36, 12 x1 + 36 x2 < 44 && And @@ (0 <= # <= 1 && # \[Element] Integers & /@ {x1, x2})}, {x1, x2}]
$\endgroup$