For example, if it is unclear whether it is better to search a graph breadth-first or depth-first we can use:
search_graph(Grap, Path) :- first_solution(Path, [ breadth_first(Graph, Path), depth_first(Graph, Path) ], []).
Options include thread stack-sizes passed to
thread_create, as well as the options on_fail
and on_error
that specify what to do if a solver fails or triggers an error. By
default execution of all solvers is terminated and the result is
returned. Sometimes one may wish to continue. One such scenario is if
one of the solvers may run out of resources or one of the solvers is
known to be incomplete.
- on_fail(Action)
- If
stop
(default), terminate all threads and stop with the failure. Ifcontinue
, keep waiting. - on_error(Action)
- As above, re-throwing the error if an error appears.
- bug
- first_solution/3 cannot deal with non-determinism. There is no obvious way to fit non-determinism into it. If multiple solutions are needed wrap the solvers in findall/3.