41 #include <grass/dgl/graph.h>
56 int stack_size, components;
63 G_warning(
"Directed graph must be version 2 or 3 for "
64 "NetA_weakly_connected_components()");
76 for (i = 1; i <= nnodes; i++)
88 if (!component[cur_node_id]) {
89 stack[0] = cur_node_id;
91 component[cur_node_id] = ++components;
104 if (!component[to]) {
105 component[to] = components;
107 if (have_node_costs) {
114 stack[stack_size++] = to;
126 if (!component[to]) {
127 component[to] = components;
129 if (have_node_costs) {
136 stack[stack_size++] = to;
164 int stack_size, order_size, components;
171 G_warning(
"Directed graph must be version 2 or 3 for "
172 "NetA_strongly_connected_components()");
180 processed = (
int *)
G_calloc(nnodes + 1,
sizeof(
int));
181 if (!stack || !
order || !processed) {
186 for (i = 1; i <= nnodes; i++) {
200 if (!component[cur_node_id]) {
201 component[cur_node_id] = --components;
202 stack[0] = cur_node_id;
209 if (processed[node_id]) {
211 order[order_size++] = node_id;
214 processed[node_id] = 1;
224 if (!component[to]) {
225 component[to] = components;
227 if (have_node_costs) {
236 stack[stack_size++] = to;
251 int cur_comp = component[cur_node_id];
254 component[cur_node_id] = ++components;
255 stack[0] = cur_node_id;
270 if (component[to] == cur_comp) {
271 component[to] = components;
273 if (have_node_costs) {
280 stack[stack_size++] = to;
int order(int i_x, int i_y, int yNum)
int NetA_strongly_connected_components(dglGraph_s *graph, int *component)
Computes strongly connected components with Kosaraju's two-pass algorithm.
int NetA_weakly_connected_components(dglGraph_s *graph, int *component)
Computes weakly connected components.
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
void G_warning(const char *,...) __attribute__((format(printf
int dglGet_NodeAttrSize(dglGraph_s *pgraph)
dglInt32_t * dglNode_T_First(dglNodeTraverser_s *pT)
dglInt32_t * dglNodeGet_OutEdgeset(dglGraph_s *pGraph, dglInt32_t *pnNode)
int dglEdgeset_T_Initialize(dglEdgesetTraverser_s *pT, dglGraph_s *pGraph, dglInt32_t *pnEdgeset)
int dglNode_T_Initialize(dglNodeTraverser_s *pT, dglGraph_s *pGraph)
dglInt32_t * dglEdgeset_T_Next(dglEdgesetTraverser_s *pT)
dglInt32_t * dglEdgeGet_Tail(dglGraph_s *pGraph, dglInt32_t *pnEdge)
dglInt32_t * dglEdgeGet_Head(dglGraph_s *pGraph, dglInt32_t *pnEdge)
dglInt32_t * dglNodeGet_Attr(dglGraph_s *pGraph, dglInt32_t *pnNode)
dglInt32_t * dglNode_T_Next(dglNodeTraverser_s *pT)
int dglGet_NodeCount(dglGraph_s *pgraph)
void dglEdgeset_T_Release(dglEdgesetTraverser_s *pT UNUSED)
dglInt32_t * dglNodeGet_InEdgeset(dglGraph_s *pGraph, dglInt32_t *pnNode)
dglInt32_t * dglEdgeset_T_First(dglEdgesetTraverser_s *pT)
void dglNode_T_Release(dglNodeTraverser_s *pT)
dglInt32_t dglNodeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnNode)
dglInt32_t * dglGetNode(dglGraph_s *pGraph, dglInt32_t nNodeId)