[英]How can I create list of results in prolog?
I did write a cost calculator, the costs can be more than one value of same inputs so I need to find minimum cost. 我确实写了一个成本计算器,成本可能超过相同输入的一个值,所以我需要找到最低成本。 The calculator is running corrently, but I couldn't do put into a list and find the minumum value of the list, how can I do it?
计算器正在正确运行,但是我无法放入列表中并找到列表的最小值,我该怎么办? This is my calculator,
这是我的计算器
cal(X,Y,CLIST) :- calcualtor(X,Y,C).
calcualtor(X,Y,C ) :- calculate_cost(X,Z,A), calcualtor(Z,Y,B),C is A+B.
calcualtor(X,Y,C) :- calculate_cost(X,Y,C).
When I call cal(A,B,X)
it gives X = 7
then when I press ";" 当我调用
cal(A,B,X)
它给出X = 7
然后按“;” it gives X = 5
then when I press ";" 它给出
X = 5
然后当我按“;” it gives X = 14
etc. 它给出
X = 14
等
I want to [7,5,14,..]
then find the min value of the list. 我想
[7,5,14,..]
然后找到列表的最小值。
Note: I can't use swi library functions 注意:我不能使用swi库函数
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.