-
-static bool graph_changed = true;
-
-/* Implementation of Kruskal's algorithm.
- Running time: O(EN)
- Please note that sorting on weight is already done by add_edge().
-*/
-
-void mst_kruskal(void)
-{
- avl_node_t *node, *next;
- edge_t *e;
- node_t *n;
- connection_t *c;
- int nodes = 0;
- int safe_edges = 0;
- bool skipped;
-
- cp();
-
- /* Clear MST status on connections */
-
- for(node = connection_tree->head; node; node = node->next) {
- c = node->data;
- c->status.mst = false;
- }
-
- /* Do we have something to do at all? */
-
- if(!edge_weight_tree->head)
- return;
-
- ifdebug(SCARY_THINGS) logger(LOG_DEBUG, "Running Kruskal's algorithm:");
-
- /* Clear visited status on nodes */
-
- for(node = node_tree->head; node; node = node->next) {
- n = node->data;
- n->status.visited = false;
- nodes++;
- }
-
- /* Starting point */
-
- for(node = edge_weight_tree->head; node; node = node->next) {
- e = node->data;
- if(e->from->status.reachable) {
- e->from->status.visited = true;
- break;
- }
- }
-
- /* Add safe edges */
-
- for(skipped = false, node = edge_weight_tree->head; node; node = next) {
- next = node->next;
- e = node->data;
-
- if(!e->reverse || e->from->status.visited == e->to->status.visited) {
- skipped = true;
- continue;
- }
-
- e->from->status.visited = true;
- e->to->status.visited = true;
-
- if(e->connection)
- e->connection->status.mst = true;
-
- if(e->reverse->connection)
- e->reverse->connection->status.mst = true;
-
- safe_edges++;
-
- ifdebug(SCARY_THINGS) logger(LOG_DEBUG, " Adding edge %s - %s weight %d", e->from->name,
- e->to->name, e->weight);
-
- if(skipped) {
- skipped = false;
- next = edge_weight_tree->head;
- continue;
- }
- }
-
- ifdebug(SCARY_THINGS) logger(LOG_DEBUG, "Done, counted %d nodes and %d safe edges.", nodes,
- safe_edges);
-}