6
$\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$
6
  • 2
    $\begingroup$ does NMaximize[{x + y, 0<=x<=1,0<=y<=1}, {x, y}, Integers] work? $\endgroup$
    – kglr
    May 25, 2018 at 11:17
  • 1
    $\begingroup$ also FindMaximum[{x + y,x<=1,y<=1, Element[{x,y},Integers]}, {x, y}] $\endgroup$
    – kglr
    May 25, 2018 at 11:21
  • $\begingroup$ @kglr yes, it works! Thanks. $\endgroup$ May 25, 2018 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$ May 25, 2018 at 13:05
  • 1
    $\begingroup$ In Mathematica, and unlike in mathematics, {1,2} is not a set, but a list. $\endgroup$ May 25, 2018 at 13:44

1 Answer 1

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$
1
  • 1
    $\begingroup$ Thanks. I still do not understand why my command did not work, but this solved my problem. $\endgroup$ May 26, 2018 at 17:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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