% Given a number of satisfiable inequalites, this program % returns an integer solution, if any. % Sample usage: % % ?- X + 2 * Y <= 7, 2*X - Y<=3, X>=0, Y>=0, intsoln([X,Y]). % % X=2 % Y=2 % % *** Retry? % % The program will generate all possible integer solutions. % intsoln([]). intsoln([X|R]) :- dump([X],[n],C), b(C,X), intsoln(R). b(C,X) :- get_integer_ub(C,U), !, c(U,X). b(C,X) :- get_integer_lb(C,L), !, d(L,X). b(_,X) :- d(0,X). b(_,X) :- c(-1,X). c(U,X) :- floor(U,X). c(U,X) :- c(U,X+1). d(L,X) :- floor(-L,-X). d(L,X) :- d(L,X-1). get_integer_ub([quote(n<=B)|_], B) :- !. get_integer_ub([quote(n