4
$\begingroup$

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?

$\endgroup$
7
$\begingroup$

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}}
*)
$\endgroup$
  • $\begingroup$ Great !! Thanks a lot. $\endgroup$ – Pavithran Iyer Mar 4 '13 at 0:51

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.