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;
64 is_source = (
char *)
G_calloc(nnodes + 3,
sizeof(
char));
65 is_sink = (
char *)
G_calloc(nnodes + 3,
sizeof(
char));
66 if (!
queue || !prev || !is_source || !is_sink) {
71 for (i = 0; i < source_list->
n_values; i++)
72 is_source[source_list->
value[i]] = 1;
73 for (i = 0; i < sink_list->
n_values; i++)
74 is_sink[sink_list->
value[i]] = 1;
76 for (i = 0; i <= nlines; i++)
88 for (i = 0; i < source_list->
n_values; i++)
91 for (i = 1; i <= nnodes; i++) {
94 while (begin != end && found == -1) {
106 if (!is_source[to] && prev[to] ==
NULL &&
107 cap >
sign(
id) * flow[labs(
id)]) {
114 if (have_node_costs) {
132 sign(edge_id) * flow[labs(edge_id)];
133 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;
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++) {
201 visited[source_list->
value[i]] = 1;
205 while (begin != end) {
215 if (!visited[to] && cap >
sign(
id) * flow[labs(
id)]) {
225 for (i = 1; i <= nnodes; i++) {
239 if (!visited[to] && flow[edge_id] != 0) {
241 total_flow += abs(flow[labs(edge_id)]);
271 dglInt32_t opaqueset[16] = {360000, 0, 0, 0, 0, 0, 0, 0,
272 0, 0, 0, 0, 0, 0, 0, 0};
290 cost = node_costs[v];
294 if (cost > max_node_cost)
295 max_node_cost = cost;
296 dglAddEdge(out, 2 * v - 1, 2 * v, cost, edge_cnt);
309 cost = node_costs[v];
321 dglAddEdge(out, 2 * v, 2 * to - 1, max_node_cost + 1, edge_cnt);
void G_free(void *)
Free allocated memory.
void void void void G_fatal_error(const char *,...) __attribute__((format(printf
int Vect_list_append(struct ilist *, int)
Append new item to the end of list if not yet present.
int Vect_reset_list(struct ilist *)
Reset ilist structure.
int NetA_min_cut(dglGraph_s *graph, struct ilist *source_list, struct ilist *sink_list UNUSED, int *flow, struct ilist *cut)
Calculates minimum cut between source(s) and sink(s).
dglInt32_t sign(dglInt32_t x)
int NetA_flow(dglGraph_s *graph, struct ilist *source_list, struct ilist *sink_list, int *flow)
Get max flow from source to sink.
int NetA_split_vertices(dglGraph_s *in, dglGraph_s *out, int *node_costs)
Splits each vertex of in graph into two vertices.
#define UNUSED
A macro for an attribute, if attached to a variable, indicating that the variable is not used.
int n_values
Number of values in the list.
int * value
Array of values.
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 dglAddEdge(dglGraph_s *pGraph, dglInt32_t nHead, dglInt32_t nTail, dglInt32_t nCost, dglInt32_t nEdge)
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 dglEdgeGet_Id(dglGraph_s *pGraph, dglInt32_t *pnEdge)
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)
int dglInitialize(dglGraph_s *pGraph, dglByte_t Version, dglInt32_t NodeAttrSize, dglInt32_t EdgeAttrSize, dglInt32_t *pOpaqueSet)
int dglGet_EdgeCount(dglGraph_s *pgraph)
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)
int dglFlatten(dglGraph_s *pGraph)
dglInt32_t dglEdgeGet_Cost(dglGraph_s *pGraph, dglInt32_t *pnEdge)
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)