18 #include <grass/gis.h>
19 #include <grass/Vect.h>
20 #include <grass/glocale.h>
21 #include <grass/dgl/graph.h>
37 int stack_size, components;
44 visited = (
int *)G_calloc(nnodes + 1,
sizeof(
int));
45 if (!stack || !visited) {
56 if (!visited[node_id]) {
60 component[node_id] = ++components;
75 component[to] = components;
76 stack[stack_size++] = to;
101 int *visited, *processed;
102 int stack_size, order_size, components;
110 visited = (
int *)G_calloc(nnodes + 1,
sizeof(
int));
111 processed = (
int *)G_calloc(nnodes + 1,
sizeof(
int));
112 if (!stack || !visited || !order || !processed) {
123 component[node_id] = 0;
124 if (!visited[node_id]) {
125 visited[node_id] = 1;
131 dglInt32_t cur_node_id = stack[stack_size - 1];
133 if (processed[cur_node_id]) {
135 order[order_size++] = cur_node_id;
138 processed[cur_node_id] = 1;
151 stack[stack_size++] = to;
164 if (component[node_id])
167 component[node_id] = components;
185 if (!component[to]) {
186 component[to] = components;
187 stack[stack_size++] = to;
dglInt32_t * dglEdgeGet_Tail(dglGraph_s *pGraph, dglInt32_t *pnEdge)
dglInt32_t dglNodeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnNode)
void G_free(void *buf)
Free allocated memory.
int NetA_weakly_connected_components(dglGraph_s *graph, int *component)
Computes weekly connected components.
int NetA_strongly_connected_components(dglGraph_s *graph, int *component)
Computes strongly connected components.
int dglEdgeset_T_Initialize(dglEdgesetTraverser_s *pT, dglGraph_s *pGraph, dglInt32_t *pnEdgeset)
int dglNode_T_Initialize(dglNodeTraverser_s *pT, dglGraph_s *pGraph)
void dglNode_T_Release(dglNodeTraverser_s *pT)
dglInt32_t dglEdgeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnEdge)
void dglEdgeset_T_Release(dglEdgesetTraverser_s *pT)
dglInt32_t * dglEdgeset_T_First(dglEdgesetTraverser_s *pT)
dglInt32_t * dglGetNode(dglGraph_s *pGraph, dglInt32_t nNodeId)
dglInt32_t * dglNode_T_First(dglNodeTraverser_s *pT)
dglInt32_t * dglNodeGet_OutEdgeset(dglGraph_s *pGraph, dglInt32_t *pnNode)
int dglGet_NodeCount(dglGraph_s *pgraph)
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
dglInt32_t * dglNode_T_Next(dglNodeTraverser_s *pT)
dglInt32_t * dglEdgeset_T_Next(dglEdgesetTraverser_s *pT)