Jumping off of @kglr's answer (pre-edit of the integer method), one can use FindInstance with RandomSeeding->Automatic to accomplish exactly the OP's updated task. I am not sure if you can get more efficient than this, as it takes negligible time on my PC for the production of a list of 10 Integer sets using RandomSeeding->Automatic. I suppose it would depend on your precise use case if this is efficient enough.
vars /. FindInstance[vars ∈ ir, vars, Integers, 10, RandomSeeding -> Automatic]
{{1, 4, 1, 1, 9}, {0, 3, 2, 1, 8}, {3, 0, 3, 1, 0}, {4, 1, 1, 3,
9}, {5, 0, 2, 3, 1}, {4, 1, 1, 1, 4}, {0, 0, 2, 3, 0}, {5, 3, 2, 3,
0}, {2, 1, 1, 2, 15}, {5, 0, 1, 2, 8}}
Here, I use 10 for the number of produced sets as not defining it, i.e., leaving it as 1, only produces the same solution each time.
vars /. FindInstance[vars ∈ ir, vars, Integers, RandomSeeding -> Automatic]
{{0, 0, 1, 1, 0}}
kglr's method is faster:
(vars /. FindInstance[vars ∈ ir, vars, Integers, 10,
RandomSeeding -> Automatic]) // feasibleQ @@@ # & // AbsoluteTiming
(integertuples =
Tuples@MapThread[{Ceiling@#, Floor@#2} &,
Transpose@RegionBounds[ir]];
feasibleQ = Function[Evaluate@vars, Evaluate@constraints];
integerfeasible = Select[Apply[feasibleQ]]@integertuples;
RandomChoice[integerfeasible, 10]) // feasibleQ @@@ # & // AbsoluteTiming
{0.350308, {True, True, True, True, True, True, True, True, True,
True}}
{0.0725979, {True, True, True, True, True, True, True, True, True,
True}}
Both methods yield appropriate results, however.
With an updated definition of integertuples
integertuples = Tuples@MapThread[Range[Ceiling@#, Floor@#2] &, Transpose@RegionBounds[ir]];
Timing increases slightly
{0.215071, {True, True, True, True, True, True, True, True, True,
True}}
However, if one is timing these appropriately by not computing integertuples again each time upon evaluation, one gets
RandomChoice[oldintegerfeasible, 10] // feasibleQ @@@ # & // AbsoluteTiming
RandomChoice[integerfeasible, 10] // feasibleQ @@@ # & // AbsoluteTiming
{0.0000818, {True, True, True, True, True, True, True, True, True,
True}}
{0.0000852, {True, True, True, True, True, True, True, True, True,
True}}
Illustrating comparable timings between versions of kglr's integertuples (definition shown above is oldintegertuples with oldintegerfeasible in comparison to kglr's correction using Range, which gives all solutions held within the cuboid.)
Element[vars, Integers]into the constraints does not work). – kglr Feb 06 '20 at 08:58FindInstancewith your definition ofImplicitRegionand posted it as an answer, not sure what way is better, but your answer surely is (& more complete, too, what with a definedtestQn what-not) :D – CA Trevillian Feb 06 '20 at 09:30