26#include <unordered_map>
30#include <boost/graph/adjacency_list.hpp>
90 boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS,
VertexProperty,
177 std::vector<VertexDescriptor>& newlyAdded);
205 explicit Circuit(
const std::vector<Component_ptr>& components,
bool explore =
false);
238 [[nodiscard]] std::optional<VertexDescriptor>
245 [[nodiscard]]
const std::unordered_map<const Component*, VertexDescriptor>&
274 [[nodiscard]] std::vector<Bus>
getInputs()
const;
277 [[nodiscard]] std::vector<CircuitPort>
getInputPorts()
const;
287 [[nodiscard]] std::vector<Bus>
getOutputs()
const;
312 [[nodiscard]] std::vector<CircuitConnection>
getConnections()
const;
360 [[nodiscard]] std::vector<SimulationBlock>
splitCyclic()
const;
363 std::map<Component_weakPtr, unsigned int, std::owner_less<Component_weakPtr>>;
392 [[nodiscard]] std::string
serialize()
const;
Represents a digital circuit as a directed graph of components.
VertexDescriptor getOrAddVertex(const Component_ptr &component)
Gets or adds a vertex for a component.
static Circuit deserialize(const std::string &jsonStr, const ComponentRegistry ®, const CircuitResolver *resolver=nullptr)
Deserializes the core circuit model from a JSON string.
std::optional< VertexDescriptor > getVertexId(const Component *component) const
Gets the vertex ID for a component.
std::pair< std::vector< Bus >, std::vector< Bus > > getComponentIOs() const
Collects all unique input and output buses from every component in the circuit.
Circuit getBackwardsSubgraph(const Bus &targetOutput) const
Extracts the cone of influence (COI) for a target output bus.
std::vector< Component_weakPtr > getListenersForWire(uint64_t wireId) const
Gets all components listening to changes on a specific wire.
Component_ptr getComponentByVertexId(VertexDescriptor vertexId) const
Gets a component by its vertex ID.
std::vector< VertexDescriptor > topologicalOrder() const
Computes a valid execution order for all vertices in the circuit.
std::map< Component_weakPtr, unsigned int, std::owner_less< Component_weakPtr > > LevelMap
std::vector< CircuitPort > getOutputPorts() const
Gets named output ports using boundary names or deterministic fallbacks.
void buildTopologyMap()
Builds a reverse mapping from wires to components that use them.
const CircuitGraph & getGraph() const
Gets the underlying circuit graph.
const std::unordered_map< const Component *, VertexDescriptor > & getComponentToVertex() const
Gets all component-to-vertex mappings.
Circuit getForwardSubgraph(const Bus &sourceInput) const
Extracts the forward cone of influence for a source input bus.
std::vector< SimulationBlock > splitCyclic() const
Splits the circuit into simulation blocks separating cyclic from acyclic parts.
std::string serialize() const
Serializes the core circuit model to a JSON string.
std::vector< CircuitPort > interfacePorts(PortRole role) const
Circuit::LevelMap getLevelMap() const
Get a levelized map between the components and their level number.
std::vector< Bus > getOutputs() const
Gets all output buses of the circuit.
void addComponent(const Component_ptr &component)
Adds a component to the circuit recursively.
void addComponentRecursive(const Component_ptr &component, std::vector< VertexDescriptor > &newlyAdded)
Recursively adds a component and all connected components.
void rebuildEdges(VertexDescriptor v)
Rebuilds directed edges in the graph based on wire connections.
std::vector< CircuitPort > getInputPorts() const
Gets named input ports using boundary names or deterministic fallbacks.
std::unordered_map< uint64_t, std::vector< Component_ptr > > wireListeners
Maps wire IDs to components that listen to changes on that wire.
std::vector< Wire_ptr > ownedWires
Wires owned by this circuit (for deserialization).
CircuitGraph graph
The Boost graph representing the circuit topology.
Component_set getComponentsForBus(Bus b) const
Finds all components that are connected to a given bus.
std::vector< CircuitConnection > getConnections() const
Gets concrete output-to-input logical connections for routing.
void removeComponent(const Component_ptr &component)
Removes a component from the circuit.
std::vector< Component_ptr > ownedComponents
Components owned by this circuit (for deserialization).
std::unordered_map< const Component *, VertexDescriptor > componentToVertex
Maps components to their vertex descriptors in the graph.
std::vector< Bus > getInputs() const
Gets all input buses of the circuit.
Base class for all digital circuit components.
std::shared_ptr< Component > Component_ptr
boost::adjacency_list< boost::vecS, boost::vecS, boost::bidirectionalS, VertexProperty, EdgeProperty > CircuitGraph
Boost graph type representing the circuit topology.
boost::graph_traits< CircuitGraph >::vertex_descriptor VertexDescriptor
Descriptor type for vertices in the circuit graph.
std::set< Component_ptr, std::owner_less< Component_ptr > > Component_set
boost::graph_traits< CircuitGraph >::edge_descriptor EdgeDescriptor
Descriptor type for edges in the circuit graph.
PortRole
Declares whether a component represents a public circuit boundary port.
Directed logical connection between one component output bus and one input bus.
unsigned int sourceBusIndex
Output bus index on source.
Component_ptr target
Component that owns the input bus.
Bus bus
Logical bus carried by this connection.
Component_ptr source
Component that owns the output bus.
unsigned int targetBusIndex
Input bus index on target.
Named bus exposed by a circuit boundary component or topology fallback.
std::optional< VertexDescriptor > boundaryVertex
Represents a block of components for simulation execution.
std::vector< Component_weakPtr > executionOrder
Pre-computed execution order for acyclic blocks.
Circuit circuit
The sub-circuit containing the components in this block.
bool isCyclic
Whether this block contains cyclic dependencies.
Property stored in each edge of the circuit graph.
Bus bus
The bus of wires this edge represents.
Property stored in each vertex of the circuit graph.
Component_ptr component
The component this vertex represents.