Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
    
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! –  belisarius Apr 29 '13 at 22:35

1 Answer 1

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

share|improve this answer
    
Thank you, the issue appears to be that the code here was using NMinimize as opposed to Minimize. –  user7181 Apr 29 '13 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})? –  user7181 Apr 29 '13 at 22:22
    
$$\text{Thank you}\\\text{for the}\\\text{helpful tip, beli}$$ –  wolfies Apr 30 '13 at 12:03

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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