From f358dfd25fc7969ca26a19a60e9d02bc61820e27 Mon Sep 17 00:00:00 2001 From: Elazar Gershuni Date: Tue, 3 Dec 2024 00:38:48 +0200 Subject: [PATCH] GraphOps: refactor lambda objects, encapsulate private shortcut populating delta in dijkstra_recover Signed-off-by: Elazar Gershuni --- src/crab/split_dbm.cpp | 2 +- src/crab_utils/graph_ops.hpp | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/src/crab/split_dbm.cpp b/src/crab/split_dbm.cpp index ba9dd6f4..dbd7e237 100644 --- a/src/crab/split_dbm.cpp +++ b/src/crab/split_dbm.cpp @@ -508,7 +508,7 @@ SplitDBM SplitDBM::operator|(const SplitDBM& o) const& { bool is_closed; graph_t g_rx(GraphOps::meet(gx, g_ix_ry, is_closed)); if (!is_closed) { - GraphOps::apply_delta(g_rx, GraphOps::close_after_meet(SubGraph(g_rx, 0),index_to_call(pot_rx), gx, g_ix_ry)); + GraphOps::apply_delta(g_rx, GraphOps::close_after_meet(SubGraph(g_rx, 0), index_to_call(pot_rx), gx, g_ix_ry)); } graph_t g_rx_iy; diff --git a/src/crab_utils/graph_ops.hpp b/src/crab_utils/graph_ops.hpp index b46de622..8fc5aafd 100644 --- a/src/crab_utils/graph_ops.hpp +++ b/src/crab_utils/graph_ops.hpp @@ -845,9 +845,8 @@ class GraphOps { // P is some vector-alike holding a valid system of potentials. // Don't need to clear/initialize template - static void chrome_dijkstra(const G& g, const PotentialFunction& p, - std::vector>& colour_succs, vert_id src, - std::vector>& out) { + static void chrome_dijkstra(const G& g, const PotentialFunction& p, std::vector>& colour_succs, + vert_id src, std::vector>& out) { const size_t sz = g.size(); if (sz == 0) { return; @@ -913,7 +912,7 @@ class GraphOps { // GKG: Factor out common elements of this & the previous algorithm. template static void dijkstra_recover(const G& g, const PotentialFunction& p, const S& is_stable, vert_id src, - std::vector>& out) { + edge_vector& delta) { const size_t sz = g.size(); if (sz == 0) { return; @@ -949,7 +948,7 @@ class GraphOps { Weight es_val = es_cost - p(src); auto w = g.lookup(src, es); if (!w || *w > es_val) { - out.emplace_back(es, es_val); + delta.emplace_back(src, es, es_val); } } if (vert_marks->at(es) == V_STABLE) { @@ -1043,14 +1042,9 @@ class GraphOps { edge_marks->at(v) = is_stable[v] ? V_STABLE : V_UNSTABLE; } edge_vector delta; - std::vector> aux; for (vert_id v : g.verts()) { if (!edge_marks->at(v)) { - aux.clear(); - dijkstra_recover(g, p, edge_marks->begin(), v, aux); - for (const auto& [vid, wt] : aux) { - delta.emplace_back(v, vid, wt); - } + dijkstra_recover(g, p, *edge_marks, v, delta); } } return delta;