aboutsummaryrefslogtreecommitdiffstats
path: root/planning/planning.cpp
diff options
context:
space:
mode:
authorSteinar H. Gunderson <sgunderson@bigfoot.com>2014-04-11 00:34:00 +0200
committerSteinar H. Gunderson <sgunderson@bigfoot.com>2014-04-11 00:34:00 +0200
commit5dc9e104240e1be919104fae8ffe59a296510e22 (patch)
tree02c2a9ea05934d909706b5d7c97a1e240a0f0af0 /planning/planning.cpp
parentd5779686e3f2c66f547ac7f6d4163b154006f688 (diff)
Use the C++11 range-based for loop for increased clarity.
Diffstat (limited to 'planning/planning.cpp')
-rw-r--r--planning/planning.cpp21
1 files changed, 6 insertions, 15 deletions
diff --git a/planning/planning.cpp b/planning/planning.cpp
index b188313..f51a60f 100644
--- a/planning/planning.cpp
+++ b/planning/planning.cpp
@@ -396,8 +396,7 @@ void Planner::find_mincost_maxflow(Graph *g)
int num_paths = 0;
for ( ;; ) {
// Reset Dijkstra state.
- for (unsigned i = 0; i < g->all_nodes.size(); ++i) {
- Node *n = g->all_nodes[i];
+ for (Node *n : g->all_nodes) {
n->cost_from_source = _INF;
n->seen = false;
n->prev_edge = NULL;
@@ -406,8 +405,7 @@ void Planner::find_mincost_maxflow(Graph *g)
for ( ;; ) {
Node *cheapest_unseen_node = NULL;
- for (unsigned i = 0; i < g->all_nodes.size(); ++i) {
- Node *n = g->all_nodes[i];
+ for (Node *n : g->all_nodes) {
if (n->seen || n->cost_from_source >= _INF) {
continue;
}
@@ -427,8 +425,7 @@ void Planner::find_mincost_maxflow(Graph *g)
cheapest_unseen_node->seen = true;
// Relax outgoing edges from this node.
- for (unsigned i = 0; i < cheapest_unseen_node->edges.size(); ++i) {
- Edge *e = cheapest_unseen_node->edges[i];
+ for (Edge *e : cheapest_unseen_node->edges) {
if (e->flow + 1 > e->capacity || e->reverse->flow - 1 > e->reverse->capacity) {
// Not feasible.
continue;
@@ -466,17 +463,11 @@ end:
int find_distro(const Graph &g, int switch_index)
{
for (unsigned j = 0; j < NUM_DISTRO; ++j) {
- Edge *flow_edge = NULL;
- for (unsigned k = 0; k < g.distro_nodes[j].edges.size(); ++k) {
- Edge *e = g.distro_nodes[j].edges[k];
- if (e->to == &g.switch_nodes[switch_index]) {
- flow_edge = e;
- break;
+ for (Edge *e : g.distro_nodes[j].edges) {
+ if (e->to == &g.switch_nodes[switch_index] && e->flow > 0) {
+ return j;
}
}
- if (flow_edge != NULL && flow_edge->flow > 0) {
- return j;
- }
}
return -1;
}