# List comparison in constraints for Minimize

I am trying to solve an optimization problem, a simplified version of which is as follows:

x = Table[Symbol["x" <> ToString[i]], {i, 7}];
A = {3, 2, 5, 1, 7, 9, 6};
Minimize[{A.x,
And @@ Thread[0 <= x <= 1] &&
Plus @@ x == 3 &&
x \[Element] Integers &&
x != {1, 1, 0, 1, 0, 0, 0}
}, x]

Here, the sought-after solution is for x. The issue is that the solution when all but the last constraint (x != {1, 1, 0, 1, 0, 0, 0}) are used is exactly {1, 1, 0, 1, 0, 0, 0}. When I introduce the last constraint, there is no effect - I still obtain the same solution, although that constraint should remove that particular solution and output the next best one. If I replace the last constraint with x == {0, 1, 1, 1, 0, 0, 0}, then the output solution is exactly {0, 1, 1, 1, 0, 0, 0}, so the comparison seems to be evaluated, but for some reason, the inequality given by x != {1, 1, 0, 1, 0, 0, 0} does not evaluate to False, although it should. Any thoughts on this would be appreciated.sov

• Welcome to Mathematica.SE! I suggest the following: 0) Change your username to something meaningful! 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Read the faq! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Also, please remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! Commented Apr 29, 2013 at 22:35

Your code works here (Mathematica v 9):

x = Table[Symbol[StringJoin["x", ToString[i]]], {i, 7}];
A = {3, 2, 5, 1, 7, 9, 6};
Minimize[{A.x, (Apply[And, Thread[0 <= x <= 1]]) && (Apply[Plus, x] ==3) &&
(x \[Element] Integers) && (x != {1, 1, 0, 1, 0, 0, 0})}, x]
(* {8, {x1 -> 0, x2 -> 1, x3 -> 1, x4 -> 1, x5 -> 0, x6 -> 0, x7 -> 0}} *)

But I would rather do something like:

Sort[{A.#, #} & /@ Permutations[{1, 1, 1, 0, 0, 0, 0}]]

or

SortBy[Subsets[{3, 2, 5, 1, 7, 9, 6}, {3}], Tr@# &]

to get all results ordered at once

• Thank you, the issue appears to be that the code here was using NMinimize as opposed to Minimize. Commented Apr 29, 2013 at 22:05
• Another issue, however, is that Minimize no longer seems to work if A is a matrix of real numbers (e.g., A = {3.1, 2.1, 5.1, 1.1, 7.1, 9.1, 6.1})? Commented Apr 29, 2013 at 22:22
• $$\text{Thank you}\\\text{for the}\\\text{helpful tip, beli}$$ Commented Apr 30, 2013 at 12:03