简体   繁体   中英

how to separate the values in min() predicate prolog

I have a predicate like

cheapest(X,Y,T):-
    findall([Ci,Cj],trip_cost(X,Y,[Ci,Cj]),K),
    aggregate_all(min(A,B), 
       member([B,A], K), 
       T).

It gives the result like

min(8,[a,b,m])

I want to make it work with predicate like

cheapest(X,Y,T,C):-
        findall([Ci,Cj],trip_cost(X,Y,[Ci,Cj]),K),
        aggregate_all(min(A,B), 
           member([B,A], K), 
           T).

and want result like

T=[a,b,m]
C=8
cheapest(X,Y,T,C):-
    cheapest(X,Y,min(C,T)).

I can't test it yet since there is no knowledgebase.

Or similar without the need of cheapest/3 :

cheapest(X,Y,T,C):-
    findall([Ci,Cj],trip_cost(X,Y,[Ci,Cj]),K),
    aggregate_all(min(A,B), 
       member([B,A], K), 
       TT),
    TT = min(C,T).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM