隐含的结论结果(Path Computations)

时间:2015-12-09 06:57:48

标签: prolog

enter image description here我希望在结果清晰显示时调用此谓词,而不是通过写入强制显示。

    :- dynamic oil/2.

    oil(town1,3).
    oil(town2,9).
    oil(town3,2).
    oil(town4,4).
    oil(town5,9).
    oil(town6,2).
    oil(town7,4).

    % пример: qwerty('town5').

    qwerty(Tree, V, W, T):- 
        capacity(V),
        oil(Tree,W),
        T = [well]
        get_oil(V, W, Tree, 0, T).

    %get_oil(V, 0, Tree, Length, WellPath):- writeln(V), writeln(Length), writeln(WellPath).
    get_oil(V, 0, Tree, Length, WellPath).       
    get_oil(V, W, Tree, Length, WellPath):- 
        W<V,    
        V2 is V-W,
        get_oil(V2, 0, Tree, Length, WellPath). 

    get_oil(V, W, Tree, Length, WellPath):- 
        W>=V,
        W2 is W-V, 
        capacity(V2),
        way(Tree,L),
        NewLength is Length+L*2,
        get_oil(V2, W2, Tree, NewLength, [Tree|[well|WellPath]]).

现在结果证明:     8? - qwerty(&#39; town5&#39;,H,D,P)。     H = 5,     D = 9,     P = [井]。     我希望收到:     H = 1,     D = 38,     P = [town5,井,井]。

0 个答案:

没有答案