22 #include <grass/dgl/graph.h> 48 struct ilist *sink_list,
int *flow)
50 int nnodes, nlines, i;
54 char *is_source, *is_sink;
55 int begin, end, total_flow;
63 is_source = (
char *)
G_calloc(nnodes + 3,
sizeof(
char));
64 is_sink = (
char *)
G_calloc(nnodes + 3,
sizeof(
char));
65 if (!queue || !prev || !is_source || !is_sink) {
70 for (i = 0; i < source_list->
n_values; i++)
71 is_source[source_list->
value[i]] = 1;
72 for (i = 0; i < sink_list->
n_values; i++)
73 is_sink[sink_list->
value[i]] = 1;
75 for (i = 0; i <= nlines; i++)
87 for (i = 0; i < source_list->
n_values; i++)
88 queue[end++] = source_list->
value[i];
90 for (i = 1; i <= nnodes; i++) {
93 while (begin != end && found == -1) {
105 if (!is_source[to] && prev[to] ==
NULL &&
106 cap >
sign(
id) * flow[labs(
id)]) {
113 if (have_node_costs) {
130 prev[node]) -
sign(edge_id) * flow[labs(edge_id)];
131 while (!is_source[node]) {
138 sign(edge_id) * flow[labs(edge_id)];
139 if (residue < min_residue)
140 min_residue = residue;
143 total_flow += min_residue;
146 while (!is_source[node]) {
148 flow[labs(edge_id)] +=
sign(edge_id) * min_residue;
178 struct ilist *sink_list,
int *flow,
struct ilist *cut)
184 int begin, end, total_flow;
188 visited = (
char *)
G_calloc(nnodes + 3,
sizeof(
char));
189 if (!queue || !visited) {
194 total_flow = begin = end = 0;
196 for (i = 1; i <= nnodes; i++)
199 for (i = 0; i < source_list->
n_values; i++) {
200 queue[end++] = source_list->
value[i];
201 visited[source_list->
value[i]] = 1;
205 while (begin != end) {
217 if (!visited[to] && cap >
sign(
id) * flow[labs(
id)]) {
226 for (i = 1; i <= nnodes; i++) {
240 if (!visited[to] && flow[edge_id] != 0) {
242 total_flow += abs(flow[labs(edge_id)]);
273 { 360000, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };
293 cost = node_costs[v];
297 if (cost > max_node_cost)
298 max_node_cost = cost;
299 dglAddEdge(out, 2 * v - 1, 2 * v, cost, edge_cnt);
312 cost = node_costs[v];
324 dglAddEdge(out, 2 * v, 2 * to - 1, max_node_cost + 1, edge_cnt);
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
dglInt32_t * dglGetNode(dglGraph_s *pGraph, dglInt32_t nNodeId)
int Vect_reset_list(struct ilist *)
Reset ilist structure.
dglInt32_t dglNodeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnNode)
void dglNode_T_Release(dglNodeTraverser_s *pT)
dglInt32_t dglEdgeGet_Cost(dglGraph_s *pGraph, dglInt32_t *pnEdge)
int n_values
Number of values in the list.
void G_free(void *)
Free allocated memory.
dglInt32_t * dglEdgeGet_Head(dglGraph_s *pGraph, dglInt32_t *pnEdge)
int NetA_flow(dglGraph_s *graph, struct ilist *source_list, struct ilist *sink_list, int *flow)
Get max flow from source to sink.
int dglGet_NodeCount(dglGraph_s *pgraph)
dglInt32_t * dglEdgeGet_Tail(dglGraph_s *pGraph, dglInt32_t *pnEdge)
int NetA_split_vertices(dglGraph_s *in, dglGraph_s *out, int *node_costs)
Splits each vertex of in graph into two vertices.
int dglInitialize(dglGraph_s *pGraph, dglByte_t Version, dglInt32_t NodeAttrSize, dglInt32_t EdgeAttrSize, dglInt32_t *pOpaqueSet)
dglInt32_t * dglNode_T_First(dglNodeTraverser_s *pT)
dglInt32_t * dglEdgeset_T_First(dglEdgesetTraverser_s *pT)
void dglEdgeset_T_Release(dglEdgesetTraverser_s *pT)
int dglAddEdge(dglGraph_s *pGraph, dglInt32_t nHead, dglInt32_t nTail, dglInt32_t nCost, dglInt32_t nEdge)
int Vect_list_append(struct ilist *, int)
Append new item to the end of list if not yet present.
int NetA_min_cut(dglGraph_s *graph, struct ilist *source_list, struct ilist *sink_list, int *flow, struct ilist *cut)
Calculates minimum cut between source(s) and sink(s).
dglInt32_t * dglNodeGet_Attr(dglGraph_s *pGraph, dglInt32_t *pnNode)
int dglGet_EdgeCount(dglGraph_s *pgraph)
int * value
Array of values.
dglInt32_t sign(dglInt32_t x)
int dglNode_T_Initialize(dglNodeTraverser_s *pT, dglGraph_s *pGraph)
dglInt32_t * dglEdgeset_T_Next(dglEdgesetTraverser_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)
dglInt32_t * dglNode_T_Next(dglNodeTraverser_s *pT)
int dglFlatten(dglGraph_s *pGraph)
dglInt32_t dglEdgeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnEdge)
int dglGet_NodeAttrSize(dglGraph_s *pgraph)