I have the following inequalities on 21 variables:
http://pastebin.com/raw.php?i=FTU970Em
When I run “Reduce[ineq,Integers]” on this, Mathematica hangs for a
long time.
That makes sense: there are MANY sets of values for x[1]..x[21] that
satisfy the inequalities.
All I really want is bounds for each variable (eg, “2 <= x[i] <= 7”
for each i).
How can I get this efficiently w/ Mathematica? Is there a better
program for this?
Note: this is part of the larger project:
Partially re-create Risk-like game based on incomplete log files
The entire hideous list of inequalities: http://pastebin.com/CyX9f70J
Running “Reduce[ineq,Integers]” on the above yields “false”, so I’ve
probably incorrectly translated:
http://conquerclub.barrycarter.info/ONEOFF/7460216.html
It’s late enough that there are probably a number of slick reductions, but this works…
ineq={...}; pivotAt[set_, j_] := Select[set, And[ Not[FreeQ[#, x[u_] /; u <= j]], FreeQ[#, x[u_] /; u > j] ] &] triangularize[set_] := Module[{left, i, new}, left = set; Reap[ For[i = 0, i <= 21, i++, new = pivotAt[left, i]; Sow[new]; left = Complement[left, new]; ]][[2, 1]] ] Module[{ tri, workingIntervals, partials, increment, i }, tri = triangularize[ineq]; workingIntervals[set_] := set /. { t_ <= c_ :> {t, Interval[{-\[Infinity], Max[c]}]}, t_ == c_ :> {t, Interval[{Min[c], Max[c]}]}, t_ >= c_ :> {t, Interval[{Max[c], \[Infinity]}]}}; partials = {}; increment[slice_] := Rule[#[[1, 1]], IntervalIntersection @@ #[[All, 2]]] &[ workingIntervals[slice /. partials ] ]; For[i = 1, i <= Length[tri], i++, partials = Join[partials, {increment[tri[[i]]]}]; ]; partials ]It’s permissive in that correlations between variables (“this high means that low”) are not accounted.
— EDIT —
The result of the above is, of course
{x[0] -> Interval[{3, 3}], x[1] -> Interval[{1, 3}], x[2] -> Interval[{1, 3}], x[3] -> Interval[{1, 3}], x[4] -> Interval[{1, 3}], x[5] -> Interval[{1, 6}], x[6] -> Interval[{1, 6}], x[7] -> Interval[{1, 6}], x[8] -> Interval[{1, 6}], x[9] -> Interval[{1, 6}], x[10] -> Interval[{1, 6}], x[11] -> Interval[{1, 6}], x[12] -> Interval[{1, 6}], x[13] -> Interval[{1, 6}], x[14] -> Interval[{1, 10}], x[15] -> Interval[{1, 10}], x[16] -> Interval[{1, 10}], x[17] -> Interval[{1, 16}], x[18] -> Interval[{1, 16}], x[19] -> Interval[{1, 16}], x[20] -> Interval[{1, 16}], x[21] -> Interval[{1, 1}]}