How can I use priority queue in SWI-Prolog? -
i trying implement a* algorithm in swi-prolog. have graph each state consists of following values (cost_so_far,heuristic,"doesn't matter","doesn't matter","doesn't matter") , want insert state priority queue according heuristic integer. how can this?
one easy way use key-value
pair list, has form:
[1-state(cost_so_far, ...), 2-state(...), 3-state(...)]
your integer value heuristic key, functor state (of whatever arity need) value. note conventional way of keeping list of pairs. can use matching them out, example, state @ head of queue be:
[heuristic-state(a, b, c)|queuerest]
you should use built-in keysort/2 sorting (very efficiently) every time have added new states @ top of queue.
Comments
Post a Comment