|
|
@@ -190,7 +190,7 @@ class DEVStoneWrapper(CoupledDEVS, ABC):
|
|
|
result += f"\t{model.name}[shape=ellipse, label=\"{'A_' + '_'.join(model.name.split('_')[1:3])}\"];\n"
|
|
|
|
|
|
for connections in self.i_in.outline:
|
|
|
- result += f"\tCoupled_{self.depth}:i_in -> {str(connections).split('.')[2]}:{connections.name};\n"
|
|
|
+ result += f"\tCoupled_{self.depth}:i_in -> {str(connections).split('.')[-2]}:{connections.name};\n"
|
|
|
|
|
|
for model in self.models:
|
|
|
if not hasattr(model, "o_out"):
|
|
|
@@ -434,23 +434,28 @@ class dLI(DEVStoneWrapper):
|
|
|
"""
|
|
|
A LI model which grows in width
|
|
|
"""
|
|
|
- def __init__(self, name: str, depth: int, width: int, int_delay: float, ext_delay: float, prep_time=0, stats=False):
|
|
|
+ def __init__(self, name: str, depth: int, width: int, int_delay: float, ext_delay: float, generator_mode: str = "uniform", root=True, prep_time=0, stats=False):
|
|
|
super().__init__(name, depth, width, int_delay, ext_delay, add_atomic_out_ports=False, prep_time=prep_time,
|
|
|
stats=stats, mode="LI-Dynamic", dynamic=True)
|
|
|
|
|
|
+ self.root = root
|
|
|
for idx in range(1, len(self.component_set)):
|
|
|
assert isinstance(self.component_set[idx], AtomicDEVS)
|
|
|
self.connectPorts(self.i_in, self.component_set[idx].i_in)
|
|
|
|
|
|
self.current_width = 1
|
|
|
self.max_gen = width - 1 # dynamically generate atomic components until width is reached excludes the coupled model
|
|
|
- self.generator = self.addSubModel(DynamicGenerator(self.name + "_gen", repeat=self.max_gen))
|
|
|
+ if self.depth == 1:
|
|
|
+ self.generator = self.addSubModel(DynamicGenerator(self.name + "_gen", repeat=self.max_gen))
|
|
|
|
|
|
def gen_coupled(self):
|
|
|
return dLI("Coupled_%d" % (self.depth - 1), self.depth - 1, self.width, self.int_delay, self.ext_delay,
|
|
|
- prep_time=self.prep_time, stats=self.stats)
|
|
|
+ prep_time=self.prep_time, stats=self.stats, root=False)
|
|
|
|
|
|
def modelTransition(self, state):
|
|
|
+ if state.get("generate", True) and self.depth == 1:
|
|
|
+ return True
|
|
|
+
|
|
|
if state.get("generate", True) and self.depth > 1:
|
|
|
name = "Atomic_%d_%d" % (self.depth - 1, self.current_width) if self.depth > 1 else "Atomic_0_%d" % self.current_width
|
|
|
if self.stats:
|
|
|
@@ -464,7 +469,10 @@ class dLI(DEVStoneWrapper):
|
|
|
self.connectPorts(self.i_in, new_atom.i_in)
|
|
|
|
|
|
self.current_width += 1
|
|
|
- # print(f"{self.name}: added {new_atom.name} (width is now {self.width})")
|
|
|
+ # if self.current_width == self.width:
|
|
|
+ # self.dot(f"dLI_{self.depth}")
|
|
|
+ if not self.root:
|
|
|
+ return True
|
|
|
return False
|
|
|
return False
|
|
|
|
|
|
@@ -473,10 +481,11 @@ class dHI(DEVStoneWrapper):
|
|
|
"""
|
|
|
A HI model which grows in width
|
|
|
"""
|
|
|
- def __init__(self, name: str, depth: int, width: int, int_delay: float, ext_delay: float, prep_time=0, stats=False):
|
|
|
+ def __init__(self, name: str, depth: int, width: int, int_delay: float, ext_delay: float, generator_mode: str = "uniform", root=True, prep_time=0, stats=False):
|
|
|
super().__init__(name, depth, width, int_delay, ext_delay, add_atomic_out_ports=True, prep_time=prep_time,
|
|
|
stats=stats, mode="HI-Dynamic", dynamic=True)
|
|
|
|
|
|
+ self.root = root
|
|
|
if len(self.component_set) > 1:
|
|
|
assert isinstance(self.component_set[-1], AtomicDEVS)
|
|
|
self.connectPorts(self.i_in, self.component_set[-1].i_in)
|
|
|
@@ -488,13 +497,17 @@ class dHI(DEVStoneWrapper):
|
|
|
|
|
|
self.current_width = 1
|
|
|
self.max_gen = width - 1 # dynamically generate atomic components until width is reached excludes the coupled model
|
|
|
- self.generator = self.addSubModel(DynamicGenerator(self.name + "_gen", repeat=self.max_gen))
|
|
|
+ if self.depth == 1:
|
|
|
+ self.generator = self.addSubModel(DynamicGenerator(self.name + "_gen", repeat=self.max_gen))
|
|
|
|
|
|
def gen_coupled(self):
|
|
|
return dHI("Coupled_%d" % (self.depth - 1), self.depth - 1, self.width, self.int_delay, self.ext_delay,
|
|
|
- prep_time=self.prep_time, stats=self.stats)
|
|
|
+ prep_time=self.prep_time, stats=self.stats, root=False)
|
|
|
|
|
|
def modelTransition(self, state):
|
|
|
+ if state.get("generate", True) and self.depth == 1:
|
|
|
+ return True
|
|
|
+
|
|
|
if state.get("generate", True) and self.depth > 1:
|
|
|
name = "Atomic_%d_%d" % (self.depth - 1, self.current_width) if self.depth > 1 else "Atomic_0_%d" % self.current_width
|
|
|
if self.stats:
|
|
|
@@ -508,11 +521,13 @@ class dHI(DEVStoneWrapper):
|
|
|
self.connectPorts(self.i_in, new_atom.i_in)
|
|
|
if len(self.models) > 1:
|
|
|
prev = self.models[-2]
|
|
|
- print("last: ", prev.name)
|
|
|
+ # print("last: ", prev.name)
|
|
|
if isinstance(prev, AtomicDEVS) and hasattr(prev, "o_out"):
|
|
|
self.connectPorts(prev.o_out, new_atom.i_in)
|
|
|
|
|
|
self.current_width += 1
|
|
|
+ if not self.root:
|
|
|
+ return True
|
|
|
return False
|
|
|
return False
|
|
|
|