NeoGraph 0.16.0
A C++20 Graph Agent Engine Library — LangGraph for C++
Loading...
Searching...
No Matches
evolution.h
Go to the documentation of this file.
1
34#pragma once
35
36#include <neograph/api.h>
40
41#include <functional>
42#include <optional>
43#include <random>
44#include <string>
45#include <vector>
46
47namespace neograph::graph {
48
49// =========================================================================
50// 1. Mutation operators
51// =========================================================================
52
54struct NEOGRAPH_API MutationResult {
57 std::optional<json> core;
60 std::string description;
61};
62
66using MutationOp = std::function<MutationResult(const json& core, std::mt19937& rng)>;
67
69enum class MutationKind : uint8_t {
79};
80
83NEOGRAPH_API std::vector<MutationOp> all_operators();
84
85// =========================================================================
86// 2. Task + Scorer
87// =========================================================================
88
93struct NEOGRAPH_API Task {
95 std::string name;
101 json input;
109 int expected_super_steps = 0;
110};
111
113struct NEOGRAPH_API Score {
117 double cost = -1.0;
119 std::string summary;
121 bool correct = false;
123 bool compiled = false;
124 bool validated = false;
125 bool executed = false;
126};
127
130NEOGRAPH_API Score evaluate(const json& core, const Task& task,
131 const NodeContext& ctx);
132
133// =========================================================================
134// 3. Generation / Selection loop
135// =========================================================================
136
138struct NEOGRAPH_API EvolutionConfig {
140 int offspring_per_gen = 20;
142 int survivors_per_gen = 5;
144 int max_generations = 10;
146 uint64_t seed = 42;
150 bool run_evaluation = false;
151};
152
154struct NEOGRAPH_API Individual {
156 json core;
158 int generation = 0;
160 int parent_index = -1;
165};
166
168struct NEOGRAPH_API EvolutionResult {
170 std::vector<Individual> population;
174 int total_offspring = 0;
175 int compile_passed = 0;
179 int execute_passed = 0;
180};
181
184 const json& seed_core,
185 const Task& task,
186 const EvolutionConfig& config = EvolutionConfig{});
187
190NEOGRAPH_API json to_json(const EvolutionResult& result);
191
192} // namespace neograph::graph
NEOGRAPH_API export/import macro for shared-library builds.
MutationKind
Catalog of built-in mutation operators, returned by all_operators().
Definition evolution.h:69
@ TOGGLE_BARRIER
Toggle a barrier on/off for a fan-in node (add or remove the barrier spec).
@ TOGGLE_CONDITIONAL_EDGE
Add or remove a conditional_edges entry on a node.
@ ADD_EDGE
Add a new edge from a node to another reachable node.
@ REMOVE_EDGE
Remove an existing plain edge.
NEOGRAPH_API Score evaluate(const json &core, const Task &task, const NodeContext &ctx)
Scorer function: compile-gate + run + compare against task.
std::function< MutationResult(const json &core, std::mt19937 &rng)> MutationOp
Mutation operator: deterministic function (input core + rng) → result.
Definition evolution.h:66
NEOGRAPH_API std::vector< MutationOp > all_operators()
Return a vector of one operator per MutationKind.
NEOGRAPH_API EvolutionResult evolve(const json &seed_core, const Task &task, const EvolutionConfig &config=EvolutionConfig{})
Run the evolution loop.
JSON → declarative topology parsing and runtime node linking.
Graph engine type definitions: channels, edges, nodes, events, and control flow.
Parameters for one evolution generation.
Definition evolution.h:138
Result of one evolution run.
Definition evolution.h:168
Individual best
Best individual (lowest cost).
Definition evolution.h:172
std::vector< Individual > population
All individuals across all generations (in birth order).
Definition evolution.h:170
One individual in the population.
Definition evolution.h:154
std::string mutation_description
Mutation that produced this individual.
Definition evolution.h:162
Score score
Score from the most recent evaluation. Negative = not evaluated.
Definition evolution.h:164
json core
Strict Core topology JSON (the canonical interchange lockfile).
Definition evolution.h:156
Result of applying a single mutation.
Definition evolution.h:54
std::string description
Human-readable description of what this mutation did (for logging and genealogy).
Definition evolution.h:60
std::optional< json > core
The mutated core topology JSON.
Definition evolution.h:57
Dependency injection context passed to nodes during construction.
Definition types.h:753
Score of a single graph run against a task.
Definition evolution.h:113
std::string summary
Human-readable summary.
Definition evolution.h:119
A task is a fixed-input → expected-output contract that a compiled graph should satisfy.
Definition evolution.h:93
json reference_core
The graph definition (core topology JSON) that solves this task.
Definition evolution.h:99
json expected_output
Expected channel values after execution.
Definition evolution.h:106
std::string name
Name of the task (for logging/reporting).
Definition evolution.h:95
json input
Input state to feed into the graph.
Definition evolution.h:101
Static semantic analysis over declarative or compiled topology.