int mincut::check (graph& G) { if (!set_vars_executed) { return(GTL_ERROR); } if ((G.number_of_nodes() <= 1) || (!G.is_connected()) || (G.is_directed())) { return(GTL_ERROR); } return GTL_OK; }
__GTL_BEGIN_NAMESPACE pathfinder::pathfinder (const graph& G, edge st, node s) { node t = s.opposite (st); dfs_num.init (G, 0); low_num.init (G); tree.init (G, list<edge>()); back.init (G, list<edge>()); forward.init (G, list<edge>()); // // There is a problem with node/edge maps of iterators with Visual C++ // which I don´t fully understand at the moment. Anyway the init for the // maps below is only needed to allocate memory, which is done anyway, when // values are assigned to it. // #ifndef __GTL_MSVCC to_low.init (G); to_father.init (G); pos.init (G); #endif used.init (G,0); act_dfs_num = 1; new_nodes = G.number_of_nodes(); is_biconn = true; // // Do DFS with biconnectivity extensions. // dfs_num[t] = act_dfs_num++; low_num[t] = dfs_num[t]; new_nodes--; dfs_sub (s, t); if (new_nodes != 0) { is_biconn = false; } used[t] = used[s] = 1; }
void topsort::init_handler (graph& G) { top_numbers.init (G, 0); act_top_num = G.number_of_nodes(); }
int dijkstra::run(graph& G) { init(G); less_dist prd(&dist, &mark); bin_heap<node, less_dist> node_heap(prd, G.number_of_nodes()); mark[s] = grey; dist[s] = 0.0; node_heap.push(s); while (!node_heap.is_empty()) { // debug: // node_heap.print_data_container(); node cur_node = node_heap.top(); node_heap.pop(); // debug: // node_heap.print_data_container(); mark[cur_node] = white; if (cur_node == t) { // if @a t is set through #target we are ready return GTL_OK; } node::adj_edges_iterator adj_edge_it; node::adj_edges_iterator adj_edges_end = cur_node.adj_edges_end(); for (adj_edge_it = cur_node.adj_edges_begin(); adj_edge_it != adj_edges_end; ++adj_edge_it) { node op_node = (*adj_edge_it).opposite(cur_node); if (mark[op_node] == black) { mark[op_node] = grey; dist[op_node] = dist[cur_node] + weight[*adj_edge_it]; node_heap.push(op_node); // debug: // node_heap.print_data_container(); if (preds_set) { pred[op_node] = *adj_edge_it; } } else if (mark[op_node] == grey) { if (dist[op_node] > dist[cur_node] + weight[*adj_edge_it]) { dist[op_node] = dist[cur_node] + weight[*adj_edge_it]; node_heap.changeKey(op_node); // debug: // node_heap.print_data_container(); if (preds_set) { pred[op_node] = *adj_edge_it; } } } else // (mark[op_node] == white) { // nothing to do: shortest distance to op_node is already // computed } } } return GTL_OK; }