|
|
@@ -1,101 +1,94 @@
|
|
|
-module DEVStoneTopologies
|
|
|
- using ..Atomic
|
|
|
- using ..Coupled
|
|
|
- using ..BaseAtomic
|
|
|
|
|
|
- export build_devstone, Structure, LI, HI, HO
|
|
|
+@enum Structure LI HI HO
|
|
|
|
|
|
- @enum Structure LI HI HO
|
|
|
+function build_devstone(type::Structure, name::String, depth::Int, width::Int, int_delay::Float64, ext_delay::Float64, stats::Bool=false)
|
|
|
+ if depth < 1 || width < 1
|
|
|
+ error("Invalid depth or width")
|
|
|
+ end
|
|
|
|
|
|
- function build_devstone(type::Structure, name::String, depth::Int, width::Int, int_delay::Float64, ext_delay::Float64, stats::Bool=false)
|
|
|
- if depth < 1 || width < 1
|
|
|
- error("Invalid depth or width")
|
|
|
- end
|
|
|
+ top_model = CoupledDEVS(name)
|
|
|
+ has_out_port = type == HI || type == HO
|
|
|
+
|
|
|
+ add_in_port!(top_model, :i_in)
|
|
|
+ if has_out_port
|
|
|
+ add_out_port!(top_model, :o_out)
|
|
|
+ end
|
|
|
+ if type == HO
|
|
|
+ add_in_port!(top_model, :i_in2)
|
|
|
+ add_out_port!(top_model, :o_out2)
|
|
|
+ end
|
|
|
|
|
|
- top_model = CoupledDEVS(name)
|
|
|
- has_out_port = type == HI || type == HO
|
|
|
+ # Leaf
|
|
|
+ if depth == 1
|
|
|
+ p_time = round(rand() + 1.0, digits=3)
|
|
|
+ atom = add_submodel!(top_model, "Atomic_0_0", DelayedAtomic;
|
|
|
+ int_delay=int_delay, ext_delay=ext_delay, prep_time=p_time,
|
|
|
+ has_out_port, stats=stats)
|
|
|
|
|
|
- add_in_port!(top_model, :i_in)
|
|
|
+ connect!(top_model, self.i_in, atom.i_in)
|
|
|
if has_out_port
|
|
|
- add_out_port!(top_model, :o_out)
|
|
|
- end
|
|
|
- if type == HO
|
|
|
- add_in_port!(top_model, :i_in2)
|
|
|
- add_out_port!(top_model, :o_out2)
|
|
|
+ connect!(top_model, atom.o_out, self.o_out)
|
|
|
end
|
|
|
|
|
|
- # Leaf
|
|
|
- if depth == 1
|
|
|
- p_time = round(rand() + 1.0, digits=3)
|
|
|
- atom = add_submodel!(top_model, "Atomic_0_0", BaseAtomic.DelayedAtomic;
|
|
|
- int_delay=int_delay, ext_delay=ext_delay, prep_time=p_time,
|
|
|
- has_out_port, stats=stats)
|
|
|
+ return top_model
|
|
|
+ end
|
|
|
|
|
|
- connect!(top_model, self.i_in, atom.i_in)
|
|
|
- if has_out_port
|
|
|
- connect!(top_model, atom.o_out, self.o_out)
|
|
|
- end
|
|
|
+ child_name = "Coupled_$(depth - 1)"
|
|
|
+ child_coupled = build_devstone(type, child_name, depth - 1, width, int_delay, ext_delay, stats)
|
|
|
+ child = add_submodel!(top_model, child_name, child_coupled)
|
|
|
|
|
|
- return top_model
|
|
|
- end
|
|
|
+ connect!(top_model, self.i_in, child.i_in)
|
|
|
+ if type == HO
|
|
|
+ connect!(top_model, self.i_in, child.i_in2)
|
|
|
+ end
|
|
|
|
|
|
- child_name = "Coupled_$(depth - 1)"
|
|
|
- child_coupled = build_devstone(type, child_name, depth - 1, width, int_delay, ext_delay, stats)
|
|
|
- child = add_submodel!(top_model, child_name, child_coupled)
|
|
|
+ if has_out_port
|
|
|
+ connect!(top_model, child.o_out, self.o_out)
|
|
|
+ end
|
|
|
|
|
|
- connect!(top_model, self.i_in, child.i_in)
|
|
|
- if type == HO
|
|
|
- connect!(top_model, self.i_in, child.i_in2)
|
|
|
+ width_models = ModelRef[]
|
|
|
+ for idx in 0:(width - 2)
|
|
|
+ p_time = 1.0 - round(rand() * (0.5 / width) + (idx / width), digits=3)
|
|
|
+ atomic_name = "Atomic_$(depth - 1)_$(idx)"
|
|
|
+
|
|
|
+ atom = add_submodel!(top_model, atomic_name, DelayedAtomic;
|
|
|
+ int_delay=int_delay, ext_delay=ext_delay, prep_time=p_time,
|
|
|
+ has_out_port=has_out_port, stats=stats)
|
|
|
+
|
|
|
+ push!(width_models, atom)
|
|
|
+ end
|
|
|
+
|
|
|
+ if type == LI
|
|
|
+ for atom in width_models
|
|
|
+ connect!(top_model, self.i_in, atom.i_in)
|
|
|
end
|
|
|
|
|
|
- if has_out_port
|
|
|
- connect!(top_model, child.o_out, self.o_out)
|
|
|
+ elseif type == HI
|
|
|
+ for atom in width_models
|
|
|
+ connect!(top_model, self.i_in, atom.i_in)
|
|
|
end
|
|
|
|
|
|
- width_models = ModelRef[]
|
|
|
- for idx in 0:(width - 2)
|
|
|
- p_time = 1.0 - round(rand() * (0.5 / width) + (idx / width), digits=3)
|
|
|
- atomic_name = "Atomic_$(depth - 1)_$(idx)"
|
|
|
+ # Chain atomics
|
|
|
+ for i in 1:(length(width_models) - 1)
|
|
|
+ connect!(top_model, width_models[i].o_out, width_models[i + 1].i_in)
|
|
|
+ end
|
|
|
|
|
|
- atom = add_submodel!(top_model, atomic_name, BaseAtomic.DelayedAtomic;
|
|
|
- int_delay=int_delay, ext_delay=ext_delay, prep_time=p_time,
|
|
|
- has_out_port=has_out_port, stats=stats)
|
|
|
+ elseif type == HO
|
|
|
+ for i in 1:(length(width_models) - 1)
|
|
|
+ curr_atom = width_models[i]
|
|
|
+ next_atom = width_models[i + 1]
|
|
|
|
|
|
- push!(width_models, atom)
|
|
|
+ connect!(top_model, curr_atom.o_out, next_atom.i_in)
|
|
|
+ connect!(top_model, self.i_in2, curr_atom.i_in)
|
|
|
+ connect!(top_model, curr_atom.o_out, self.o_out2)
|
|
|
end
|
|
|
|
|
|
- if type == LI
|
|
|
- for atom in width_models
|
|
|
- connect!(top_model, self.i_in, atom.i_in)
|
|
|
- end
|
|
|
-
|
|
|
- elseif type == HI
|
|
|
- for atom in width_models
|
|
|
- connect!(top_model, self.i_in, atom.i_in)
|
|
|
- end
|
|
|
-
|
|
|
- # Chain atomics
|
|
|
- for i in 1:(length(width_models) - 1)
|
|
|
- connect!(top_model, width_models[i].o_out, width_models[i + 1].i_in)
|
|
|
- end
|
|
|
-
|
|
|
- elseif type == HO
|
|
|
- for i in 1:(length(width_models) - 1)
|
|
|
- curr_atom = width_models[i]
|
|
|
- next_atom = width_models[i + 1]
|
|
|
-
|
|
|
- connect!(top_model, curr_atom.o_out, next_atom.i_in)
|
|
|
- connect!(top_model, self.i_in2, curr_atom.i_in)
|
|
|
- connect!(top_model, curr_atom.o_out, self.o_out2)
|
|
|
- end
|
|
|
-
|
|
|
- if length(width_models) > 0
|
|
|
- last_atom = width_models[end]
|
|
|
- connect!(top_model, self.i_in2, last_atom.i_in)
|
|
|
- connect!(top_model, last_atom.o_out, self.o_out2)
|
|
|
- end
|
|
|
+ if length(width_models) > 0
|
|
|
+ last_atom = width_models[end]
|
|
|
+ connect!(top_model, self.i_in2, last_atom.i_in)
|
|
|
+ connect!(top_model, last_atom.o_out, self.o_out2)
|
|
|
end
|
|
|
-
|
|
|
- return top_model
|
|
|
end
|
|
|
+
|
|
|
+ return top_model
|
|
|
end
|