5
$\begingroup$

I tried to solve an integer-linear optimization problem but failed. I reduced the failed example to the following:

FindMaximum[{x + y, Element[x , {0, 1}], Element[y , {0, 1}]}, {x, y}]

I got the following error:

FindMaximum::elemc: Unable to resolve the domain or region membership condition x\[Element]{0,1}.

I get the same error when using NMaximize instead of FindMaximum.

What am I doing wrong?

$\endgroup$
  • 2
    $\begingroup$ does NMaximize[{x + y, 0<=x<=1,0<=y<=1}, {x, y}, Integers] work? $\endgroup$ – kglr May 25 '18 at 11:17
  • 1
    $\begingroup$ also FindMaximum[{x + y,x<=1,y<=1, Element[{x,y},Integers]}, {x, y}] $\endgroup$ – kglr May 25 '18 at 11:21
  • $\begingroup$ @kglr yes, it works! Thanks. $\endgroup$ – Erel Segal-Halevi May 25 '18 at 11:22
  • 1
    $\begingroup$ Voting to close because I think the "elemc" message and the FindMaximum function page hint why OP's command does not work. Although, I might be wrong... $\endgroup$ – Anton Antonov May 25 '18 at 13:05
  • 1
    $\begingroup$ In Mathematica, and unlike in mathematics, {1,2} is not a set, but a list. $\endgroup$ – AccidentalFourierTransform May 25 '18 at 13:44
5
$\begingroup$
NMaximize[{x + y, 0<=x<=1,0<=y<=1}, {x, y}, Integers] (* or *)
FindMaximum[{x + y,x<=1,y<=1, Element[{x,y},Integers]}, {x, y}]

both give

{2., {x -> 1, y -> 1}}

$\endgroup$
  • $\begingroup$ Thanks. I still do not understand why my command did not work, but this solved my problem. $\endgroup$ – Erel Segal-Halevi May 26 '18 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.