I am trying to optimise and find the minimum Cost of a function. The program below uses findall/3
to iterate over all possible options of values which are generated from using the clpfd
library provided by SWI-Prolog.
There are several Cost
values that are generated using this program below which are gathered into a list. I know that in order to get the minimum value I can simply use the min_list/2
predicate available. However, what I want is that once the program finds a certain value, which is currently the minimum, while computing other options, if the value turns out to be greater than the minimum value, its not added the list.
So essentially, I want to optimise the program so that it simply accounts for the minimum value generated by the program.
optimise(input, arguments, Cost):-
findall(Cost, some_predicate(input, arguments, Cost), List).
some_predicate(input, arguments, Cost):-
Option in input..arguments, label(Option),
find_data(Option, Value),
find_cost(Value, Cost).
The above code has been modified so that it is condensed and but fulfils the purpose of the question.