Skip to content
Snippets Groups Projects
Commit f8334097 authored by angloth's avatar angloth
Browse files

Add graph id generator and function for adding operation to SFG

parent bb7ec09a
No related branches found
No related tags found
1 merge request!2Integrated ID system, traversing and som signal tests
......@@ -10,15 +10,18 @@ class GraphIDGenerator:
"""
A class that generates Graph IDs for objects.
"""
_next_id_number: DefaultDict(str, int)
def __init__(self):
_next_id_number = defaultdict(lambda: 1) # Initalises every key element to 1
self._next_id_number = defaultdict(lambda: 1) # Initalises every key element to 1
def get_next_id(self, graph_id_type: str):
graph_id = GraphID(graph_id_type, _next_id_number[graph_id_type])
_next_id_number[graph_id_type] += 1
"""
Retrns the next graph id for a certain graph id type.
"""
graph_id = GraphID(graph_id_type, self._next_id_number[graph_id_type])
self._next_id_number[graph_id_type] += 1 # Increment the current number
return graph_id
......@@ -58,7 +61,3 @@ class GraphID:
Returns a new GraphID of the same type with an incremented id number.
"""
return GraphID(self.graph_id_type, self.graph_id_number + 1)
def is_id_in_use()
\ No newline at end of file
......@@ -7,12 +7,8 @@ from b_asic.operation import Operation
from b_asic.basic_operation import BasicOperation
from b_asic.signal import Signal, SignalSource, SignalDestination
from b_asic.simulation import SimulationState, OperationState
from typing import List, Dict
# Types
OperationId = NewType("OperationId", int)
SignalId = NewType("SignalId", int)
from typing import List, Dict, Union
from graph_id import GraphIDGenerator, GraphID
class SFG(BasicOperation):
......@@ -21,18 +17,18 @@ class SFG(BasicOperation):
TODO: More info.
"""
_operations: Dict[OperationID, Operation]
_signals: Dict[SignalID, Signal]
_graph_objects: Dict(GraphID, Union(Operation, Signal))
_graph_id_generator: GraphIDGenerator
def __init__(self, input_destinations: List[SignalDestination], output_sources: List[SignalSource]):
"""
Construct a SFG.
"""
super().__init__(identifier)
super().__init__()
# TODO: Allocate input/output ports with appropriate IDs.
self._operations = dict # Map Operation ID to Operation objects
self._signals = dict # Map Signal ID to Signal objects
self._graph_objects = dict # Map Operation ID to Operation objects
self._graph_id_generator = GraphIDGenerator()
# TODO: Traverse the graph between the inputs/outputs and add to self._operations.
# TODO: Connect ports with signals with appropriate IDs.
......@@ -40,6 +36,15 @@ class SFG(BasicOperation):
def evaluate(self, inputs: list) -> list:
return [] # TODO: Implement
def split(self) -> List[Operation]:
return self
def add_operation(self, operation: Operation) -> GraphID:
"""
Adds the entered operation to the SFG's dictionary of graph objects and
generates and returns a GraphID for it.
"""
graph_id = self._graph_id_generator.get_next_id("op")
self._graph_objects[graph_id] = operation
return graph_id
def _generate_id(self)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment