I need to write a predicate that creates a minimum spanning tree of a weighted undirected graph, using Prim's Algorithm. How do I approach this problem?
The graph consists of multiple edge(v1, v2, length)
predicates.
A minimum spanning tree is the shortest path that connects all edges without cycles.
Prim's algorithm:
Pick one arbitrary node and add it to the visited list.
Choose the smallest edge that connects it to another node.
Add that node to the visited list.
Look at all the nodes in the visited list and pick the smallest edge connected to one of them.
Add that node to the visited list.
Continue like this.
If the smallest edge connects two nodes that are already in the visited list, do not pick it.
--
You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.
Visit this group at https://groups.google.com/group/swi-prolog.
For more options, visit https://groups.google.com/d/optout.
On May 1, 2018, at 20:28, Hannes Wiedenhofer <hon...@gmail.com> wrote:It doesn't seem that easy for me.