Icarus
Vehicle Simulation as a Transformable Computational Graph, built on Vulcan and Janus
Loading...
Searching...
No Matches
IntrospectionGraph.hpp
Go to the documentation of this file.
1#pragma once
2
17
19#include <nlohmann/json.hpp>
20#include <string>
21#include <vector>
22#include <yaml-cpp/yaml.h>
23
24namespace icarus {
25
29enum class EdgeKind {
32};
33
38 std::string source;
39 std::string target;
41};
42
72
74 std::vector<IntrospectionEdge> edges;
75
82 [[nodiscard]] nlohmann::json ToJSON() const {
83 nlohmann::json j = dictionary.ToJSONValue();
84 j["summary"]["total_edges"] = edges.size();
85
86 // Edges (NEW — additive)
87 j["edges"] = nlohmann::json::array();
88 for (const auto &edge : edges) {
89 nlohmann::json jedge;
90 jedge["source"] = edge.source;
91 jedge["target"] = edge.target;
92 jedge["kind"] = (edge.kind == EdgeKind::Route) ? "route" : "resolve";
93 j["edges"].push_back(jedge);
94 }
95
96 return j;
97 }
98
102 void ToJSONFile(const std::string &path) const {
103 detail::WriteToFile(path, [&](std::ofstream &file) { file << ToJSON().dump(2); });
104 }
105
109 void ToYAMLFile(const std::string &path) const {
110 YAML::Emitter out;
111 out << YAML::BeginMap;
112
113 // Summary
114 out << YAML::Key << "summary" << YAML::Value << YAML::BeginMap;
115 out << YAML::Key << "total_outputs" << YAML::Value << dictionary.total_outputs;
116 out << YAML::Key << "total_inputs" << YAML::Value << dictionary.total_inputs;
117 out << YAML::Key << "total_parameters" << YAML::Value << dictionary.total_parameters;
118 out << YAML::Key << "total_config" << YAML::Value << dictionary.total_config;
119 out << YAML::Key << "integrable_states" << YAML::Value << dictionary.integrable_states;
120 out << YAML::Key << "unwired_inputs" << YAML::Value << dictionary.unwired_inputs;
121 out << YAML::Key << "total_edges" << YAML::Value << edges.size();
122 out << YAML::EndMap;
123
124 dictionary.AppendComponentsToYAML(out);
125
126 // Edges
127 out << YAML::Key << "edges" << YAML::Value << YAML::BeginSeq;
128 for (const auto &edge : edges) {
129 out << YAML::BeginMap;
130 out << YAML::Key << "source" << YAML::Value << edge.source;
131 out << YAML::Key << "target" << YAML::Value << edge.target;
132 out << YAML::Key << "kind" << YAML::Value
133 << ((edge.kind == EdgeKind::Route) ? "route" : "resolve");
134 out << YAML::EndMap;
135 }
136 out << YAML::EndSeq;
137
138 out << YAML::EndMap;
139
140 detail::WriteToFile(path, [&](std::ofstream &file) { file << out.c_str(); });
141 }
142};
143
144} // namespace icarus
Complete catalog of simulation interface.
void WriteToFile(const std::string &path, WriteFunc write_content)
Helper to write content to a file with error handling.
Definition DataDictionary.hpp:27
Definition AggregationTypes.hpp:13
EdgeKind
Edge classification for the introspection graph.
Definition IntrospectionGraph.hpp:29
@ Resolve
Implicit dependency via Backplane::resolve() (source binding).
Definition IntrospectionGraph.hpp:31
@ Route
Explicit SignalRouter connection (input_path <- output_path).
Definition IntrospectionGraph.hpp:30
Complete catalog of simulation interface.
Definition DataDictionary.hpp:45
A single directed edge in the introspection graph.
Definition IntrospectionGraph.hpp:37
EdgeKind kind
Edge classification.
Definition IntrospectionGraph.hpp:40
std::string target
Target: signal path (routes) or component name (resolves).
Definition IntrospectionGraph.hpp:39
std::string source
Source signal path (e.g., "Rocket.Engine.force.x").
Definition IntrospectionGraph.hpp:38
Complete introspection graph: nodes (components) + typed edges.
Definition IntrospectionGraph.hpp:69
DataDictionary dictionary
The existing data dictionary (component nodes with signal lists).
Definition IntrospectionGraph.hpp:71
nlohmann::json ToJSON() const
Serialize the full graph to JSON.
Definition IntrospectionGraph.hpp:82
void ToYAMLFile(const std::string &path) const
Write the full graph to a YAML file.
Definition IntrospectionGraph.hpp:109
std::vector< IntrospectionEdge > edges
All topology edges (routes + resolves).
Definition IntrospectionGraph.hpp:74
void ToJSONFile(const std::string &path) const
Write the full graph to a JSON file.
Definition IntrospectionGraph.hpp:102