VeloGraphX
High-performance dynamic graph analytics in C++20
Loading...
Searching...
No Matches
execution_plan.hpp
Go to the documentation of this file.
1#pragma once
2#include <algorithm>
3#include <cstddef>
4#include <string>
5
6namespace velographx {
7
9
11 std::size_t changed_edges{0};
12 std::size_t total_edges{0};
13 std::size_t affected_vertices{0};
14 std::size_t total_vertices{0};
15 double frontier_growth{1.0};
19};
20
29
31 const double changed_fraction = e.total_edges == 0
32 ? 0.0
33 : static_cast<double>(e.changed_edges) /
34 static_cast<double>(e.total_edges);
35 const double affected_vertex_fraction = e.total_vertices == 0
36 ? 0.0
37 : static_cast<double>(e.affected_vertices) /
38 static_cast<double>(e.total_vertices);
39 const double observed_fraction = std::clamp(e.observed_affected_edge_fraction, 0.0, 1.0);
40 const double propagation = std::max(1.0, e.frontier_growth);
41
42 const double structural_fraction = std::clamp(
43 0.45 * changed_fraction * propagation +
44 0.35 * affected_vertex_fraction +
45 0.20 * observed_fraction,
46 0.0, 1.5);
47
48 const double speedup = std::max(0.1, e.historical_incremental_speedup);
49 const double repair_success = std::clamp(e.historical_repair_success_rate, 0.0, 1.0);
50 const double history_penalty = (1.0 / speedup) * (1.0 + (1.0 - repair_success));
51
52 const double full = static_cast<double>(e.total_edges) +
53 static_cast<double>(e.total_vertices);
54 const double inc = full * structural_fraction * history_penalty;
55 const double work_fraction = full == 0.0 ? 0.0 : inc / full;
56 const double confidence = std::clamp(
57 0.5 * repair_success +
58 0.3 * std::min(1.0, speedup / 2.0) +
59 0.2 * (1.0 - std::min(1.0, structural_fraction)),
60 0.0, 1.0);
61
62 if (inc < 0.65 * full && repair_success >= 0.5) {
63 return {ExecutionMode::incremental, inc, full, work_fraction, confidence,
64 "affected-work estimate and historical repair behavior favor incremental execution"};
65 }
66 return {ExecutionMode::full_recompute, inc, full, work_fraction, confidence,
67 "estimated propagation or historical repair risk favors full recomputation"};
68}
69
70inline std::string explain(const ExecutionPlan& p) {
71 return std::string("mode=") +
72 (p.mode == ExecutionMode::incremental ? "incremental" : "full_recompute") +
73 "; incremental_cost=" + std::to_string(p.incremental_cost) +
74 "; full_cost=" + std::to_string(p.full_cost) +
75 "; estimated_work_fraction=" + std::to_string(p.estimated_work_fraction) +
76 "; confidence=" + std::to_string(p.confidence) +
77 "; reason=" + p.reason;
78}
79} // namespace velographx
std::string explain(const ExecutionPlan &p)
ExecutionPlan choose_execution(const ExecutionEstimate &e)