Skip to content

Commit

Permalink
GraphOps: refactor lambda objects, encapsulate private
Browse files Browse the repository at this point in the history
shortcut populating delta in dijkstra_recover

Signed-off-by: Elazar Gershuni <[email protected]>
  • Loading branch information
elazarg committed Dec 2, 2024
1 parent 9f415e8 commit f358dfd
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/crab/split_dbm.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
16 changes: 5 additions & 11 deletions src/crab_utils/graph_ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -845,9 +845,8 @@ class GraphOps {
// P is some vector-alike holding a valid system of potentials.
// Don't need to clear/initialize
template <class G>
static void chrome_dijkstra(const G& g, const PotentialFunction& p,
std::vector<std::vector<vert_id>>& colour_succs, vert_id src,
std::vector<std::tuple<vert_id, Weight>>& out) {
static void chrome_dijkstra(const G& g, const PotentialFunction& p, std::vector<std::vector<vert_id>>& colour_succs,
vert_id src, std::vector<std::tuple<vert_id, Weight>>& out) {
const size_t sz = g.size();
if (sz == 0) {
return;
Expand Down Expand Up @@ -913,7 +912,7 @@ class GraphOps {
// GKG: Factor out common elements of this & the previous algorithm.
template <class G, class S>
static void dijkstra_recover(const G& g, const PotentialFunction& p, const S& is_stable, vert_id src,
std::vector<std::tuple<vert_id, Weight>>& out) {
edge_vector& delta) {
const size_t sz = g.size();
if (sz == 0) {
return;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -1043,14 +1042,9 @@ class GraphOps {
edge_marks->at(v) = is_stable[v] ? V_STABLE : V_UNSTABLE;
}
edge_vector delta;
std::vector<std::tuple<vert_id, Weight>> 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;
Expand Down

0 comments on commit f358dfd

Please sign in to comment.