Mathematica Stack Exchange is a question and answer site for users of Mathematica. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have a set of constraints to which I require integer solutions. However, instead of needing all possible integer solutions (as obtained by using Solve[constraints,Variables,Integers]), I need any one solution only.

Here is a specific example:

variables = {
  Subscript[x, 11], Subscript[x, 12], Subscript[x, 13],
  Subscript[x, 14], Subscript[x, 15], Subscript[x, 16]
};

constraints = 
  273 + 4 Subscript[x, 11] + Subscript[x, 12] >= 0 &&
  -693 - 8 Subscript[x, 11] - 3 Subscript[x, 12] + Subscript[x, 13] >= 0 && 
  483 + 4 Subscript[x, 11] + 3 Subscript[x, 12] - 3 Subscript[x, 13] +
    Subscript[x, 14] >= 0 &&
  -Subscript[x, 12] + 3 Subscript[x, 13] - 3 Subscript[x, 14] + Subscript[x, 15] >= 0 &&
  -Subscript[x, 13] + 3 Subscript[x, 14] - 3 Subscript[x, 15] + 24 Subscript[x, 16] >= 0 &&
  -Subscript[x, 14] + 3 Subscript[x, 15] - 32 Subscript[x, 16] >= 0 &&
  -Subscript[x, 15] + 8 Subscript[x, 16] >= 0 &&
  Subscript[x, 16] >= 0 &&
  Subscript[x, 11] >= 0 &&
  462 + 11 Subscript[x, 11] + Subscript[x, 12] + Subscript[x, 13] + Subscript[x, 14] + 
    Subscript[x, 15] - 15 Subscript[x, 16] >= 0 &&
  2709 + 42 Subscript[x, 11] + 8 Subscript[x, 12] + 4 Subscript[x, 13] -
    4 Subscript[x, 15] + 40 Subscript[x, 16] >= 0 &&
  4536 + 54 Subscript[x, 11] + 18 Subscript[x, 12] - 2 Subscript[x, 13] - 
    6 Subscript[x, 14] + 6 Subscript[x, 15] - 45 Subscript[x, 16] >= 0 &&
  -1134 - 27 Subscript[x, 11] - 12 Subscript[x, 13] + 8 Subscript[x, 14] -
    4 Subscript[x, 15] + 24 Subscript[x, 16] >= 0 &&
  -6318 - 81 Subscript[x, 11] - 27 Subscript[x, 12] + 9 Subscript[x, 13] - 
    3 Subscript[x, 14] + Subscript[x, 15] - 5 Subscript[x, 16] >= 0 &&
  273 + 4 Subscript[x, 11] + Subscript[x, 12] == Subscript[x, 16] &&
  -693 - 8 Subscript[x, 11] - 3 Subscript[x, 12] + Subscript[x, 13] == Subscript[x, 11];

solutions = Solve[constraints, variables, Integers]

I get an output, but it is very long as there are many solutions. Consequently, the runtime is significant. Hence, I want to modify Solve[] as to stop evaluating after one solution has been found. I believe that would not run for as long as the general case.

Could anyone please help me?

share|improve this question
up vote 6 down vote accepted

This can be done using FindInstance:

solutions = FindInstance[constraints, variables, Integers]

(*
==> {{Subscript[x, 11] -> 5, Subscript[x, 12] -> -293, 
  Subscript[x, 13] -> -141, Subscript[x, 14] -> -47, 
  Subscript[x, 15] -> -6, Subscript[x, 16] -> 0}}
*)
share|improve this answer
    
Great !! Thanks a lot. – Pavithran Iyer Mar 4 '13 at 0:51

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.