Given the shopping trips planning problem as an abductive theory, we can perform planning as abductive queries. For example,
| ?- query([holds(have(banana), T), holds(have(milk), T), holds(have(drill), T), holds(balance=B, T), {B > 0.0}], (As, Cs, _)).
For this query there are multiple solutions (plans), some of which is not ground. For example,
B = 11.509999999999998, As = [happens(goto(hws),_A),happens(buy(drill,hws),_B),happens(goto(sm),_C), happens(buy(milk,sm),_D),happens(goto(sm),_E),happens(buy(banana,sm),_F)], Cs = [_E#<_F,_D#<_E,_C#<_D,_B#<_C,_A#<_B,_A#<_B,_A#<_B,0#<_A,_A in 0..8,_B#<_D|...], _F in 6..7, T in 7..8, _E in 5..6, _D in 4..5, _C in 3..4, _B in 2..3, _A in 1..2 ?
To obtain a solution with all finite domain variables to be grounded, you can use the labeling/2 predicate provided by library(clpfd). For example,
| ?- use_module(library(terms)). | ?- use_module(library(clpfd)). | ?- query([holds(have(banana), T), holds(have(milk), T), holds(have(drill), T), holds(balance=B, T), {B > 0.0}], (As, Cs, _)), term_variables(Cs, Vs), labeling([], Vs). B = 11.509999999999998, T = 7, As = [happens(goto(hws),1),happens(buy(drill,hws),2),happens(goto(sm),3), happens(buy(milk,sm),4),happens(goto(sm),5),happens(buy(banana,sm),6)], Cs = [5#<6,4#<5,3#<4,2#<3,1#<2,1#<2,1#<2,0#<1,1 in 0..8,2#<4|...], Vs = [6,7,5,4,3,2,1] ? yes \ ?-
In the above approach, a non-ground answer is computed first, and the finite domain variables in the answer is forced to be grounded using the finite domain solver. Thus, the inference process is not affected by this post-processing of answer. However, the abductive system has an option to force the finite domain variable to be grounded as soon as possible during the inference process, which can be turn on and off using enforce_labeling(true) and enforce_labeling(false). In some applications, by turning on such option the computation of queries can be speeded up (significantly). For example,
| ?- enforce_labeling(true). yes | ?- query([holds(have(banana), T), holds(have(milk), T), holds(have(drill), T), holds(balance=B, T), {B > 0.0}], (As, Cs, _)). B = 11.509999999999998, T = 6, As = [happens(goto(hws),4),happens(buy(drill,hws),5),happens(buy(milk,sm),3), happens(goto(sm),1),happens(buy(banana,sm),2)], Cs = [] ? yes | ?-
Jiefei Ma 2011-02-14