gANDALF
gANDALF

Reputation: 238

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

Upvotes: 2

Views: 70

Answers (1)

Duda
Duda

Reputation: 3746

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).

Upvotes: 1

Related Questions