[GRASS-SVN] r68007 - grass/trunk/lib/vector/neta

svn_grass at osgeo.org svn_grass at osgeo.org
Sat Mar 5 14:32:01 PST 2016


Author: mmetz
Date: 2016-03-05 14:32:01 -0800 (Sat, 05 Mar 2016)
New Revision: 68007

Modified:
   grass/trunk/lib/vector/neta/flow.c
Log:
netalib: consider closed nodes

Modified: grass/trunk/lib/vector/neta/flow.c
===================================================================
--- grass/trunk/lib/vector/neta/flow.c	2016-03-05 22:27:31 UTC (rev 68006)
+++ grass/trunk/lib/vector/neta/flow.c	2016-03-05 22:32:01 UTC (rev 68007)
@@ -33,7 +33,7 @@
    \brief Get max flow from source to sink.
 
    Array flow stores flow for each edge. Negative flow corresponds to a
-   flow in opposite direction The function assumes that the edge costs
+   flow in opposite direction. The function assumes that the edge costs
    correspond to edge capacities.
 
    \param graph input graph
@@ -53,6 +53,8 @@
     dglInt32_t **prev;
     char *is_source, *is_sink;
     int begin, end, total_flow;
+    int have_node_costs;
+    dglInt32_t ncost;
 
     nnodes = dglGet_NodeCount(graph);
     nlines = dglGet_EdgeCount(graph) / 2;	/*each line corresponds to two edges. One in each direction */
@@ -73,6 +75,9 @@
     for (i = 0; i <= nlines; i++)
 	flow[i] = 0;
 
+    ncost = 0;
+    have_node_costs = dglGet_NodeAttrSize(graph);
+
     total_flow = 0;
     while (1) {
 	dglInt32_t node, edge_id, min_residue;
@@ -104,7 +109,13 @@
 			found = to;
 			break;
 		    }
-		    queue[end++] = to;
+		    /* do not go through closed nodes */
+		    if (have_node_costs) {
+			memcpy(&ncost, dglNodeGet_Attr(graph, dglEdgeGet_Tail(graph, edge)),
+			       sizeof(ncost));
+		    }
+		    if (ncost >= 0)
+			queue[end++] = to;
 		}
 	    }
 	    dglEdgeset_T_Release(&et);
@@ -280,6 +291,9 @@
 
 	if (node_costs)
 	    cost = node_costs[v];
+	/* skip closed nodes */
+	if (cost < 0)
+	    continue;
 	if (cost > max_node_cost)
 	    max_node_cost = cost;
 	dglAddEdge(out, 2 * v - 1, 2 * v, cost, edge_cnt);
@@ -292,7 +306,14 @@
 	dglEdgesetTraverser_s et;
 	dglInt32_t *edge;
 	dglInt32_t v = dglNodeGet_Id(in, cur_node);
+	dglInt32_t cost = 1;
 
+	if (node_costs)
+	    cost = node_costs[v];
+	/* skip closed nodes */
+	if (cost < 0)
+	    continue;
+
 	dglEdgeset_T_Initialize(&et, in, dglNodeGet_OutEdgeset(in, cur_node));
 	for (edge = dglEdgeset_T_First(&et); edge;
 	     edge = dglEdgeset_T_Next(&et)) {



More information about the grass-commit mailing list