|
|
@@ -36,13 +36,13 @@ end
|
|
|
|
|
|
mutable struct CoupledDEVS
|
|
|
name::Symbol
|
|
|
- in_ports::Set{Symbol}
|
|
|
- out_ports::Set{Symbol}
|
|
|
+ in_ports::Dict{Symbol, Type}
|
|
|
+ out_ports::Dict{Symbol, Type}
|
|
|
atomics::Dict{Symbol, Tuple{Type, NamedTuple}}
|
|
|
coupled::Dict{Symbol, CoupledDEVS}
|
|
|
couplings::Vector{Tuple{Symbol, Symbol, Symbol, Symbol}}
|
|
|
end
|
|
|
-CoupledDEVS(name::Symbol) = CoupledDEVS(name, Set(), Set(), Dict(), Dict(), [])
|
|
|
+CoupledDEVS(name::Symbol) = CoupledDEVS(name, Dict{Symbol, Type}(), Dict{Symbol, Type}(), Dict(), Dict(), [])
|
|
|
CoupledDEVS(name::String) = CoupledDEVS(Symbol(name))
|
|
|
self = ModelRef(:self)
|
|
|
|
|
|
@@ -57,15 +57,16 @@ function add_submodel!(parent::CoupledDEVS, name::Symbol, child::CoupledDEVS)
|
|
|
end
|
|
|
add_submodel!(parent::CoupledDEVS, name::String, obj::Any; kwargs...) = add_submodel!(parent, Symbol(name), obj; kwargs...)
|
|
|
|
|
|
-function add_in_port!(node::CoupledDEVS, port::Symbol)
|
|
|
- push!(node.in_ports, port)
|
|
|
+function add_in_port!(node::CoupledDEVS, port::Symbol, port_type::Type=Any)
|
|
|
+ node.in_ports[port] = port_type
|
|
|
end
|
|
|
|
|
|
-function add_out_port!(node::CoupledDEVS, port::Symbol)
|
|
|
- push!(node.out_ports, port)
|
|
|
+function add_out_port!(node::CoupledDEVS, port::Symbol, port_type::Type=Any)
|
|
|
+ node.out_ports[port] = port_type
|
|
|
end
|
|
|
-add_in_port!(node::CoupledDEVS, port::String) = add_in_port!(node, Symbol(port))
|
|
|
-add_out_port!(node::CoupledDEVS, port::String) = add_out_port!(node, Symbol(port))
|
|
|
+
|
|
|
+add_in_port!(node::CoupledDEVS, port::String, port_type::Type=Any) = add_in_port!(node, Symbol(port), port_type)
|
|
|
+add_out_port!(node::CoupledDEVS, port::String, port_type::Type=Any) = add_out_port!(node, Symbol(port), port_type)
|
|
|
|
|
|
function connect!(parent::CoupledDEVS, source::PortRef, target::PortRef; Z::Function=identity)
|
|
|
push!(parent.couplings, (source.model_name, source.port_name, target.model_name, target.port_name))
|
|
|
@@ -78,17 +79,17 @@ function identify_port(node::CoupledDEVS, model::Symbol, port::Symbol, atomic_in
|
|
|
port_type = nothing
|
|
|
|
|
|
if is_parent
|
|
|
- if port in node.in_ports
|
|
|
+ if haskey(node.in_ports, port)
|
|
|
port_type = INPUT
|
|
|
- elseif port in node.out_ports
|
|
|
+ elseif haskey(node.out_ports, port)
|
|
|
port_type = OUTPUT
|
|
|
end
|
|
|
|
|
|
elseif is_coupled
|
|
|
sub_coupled = node.coupled[model]
|
|
|
- if port in sub_coupled.in_ports
|
|
|
+ if haskey(sub_coupled.in_ports, port)
|
|
|
port_type = INPUT
|
|
|
- elseif port in sub_coupled.out_ports
|
|
|
+ elseif haskey(sub_coupled.out_ports, port)
|
|
|
port_type = OUTPUT
|
|
|
end
|
|
|
else
|
|
|
@@ -155,7 +156,7 @@ function instantiate_tree!(node::CoupledDEVS, current_path::String, path_to_id::
|
|
|
current_id[] += 1
|
|
|
|
|
|
local_atomic_in[name] = Set(keys(agent.inbox))
|
|
|
- local_atomic_out[name] = agent.out_ports
|
|
|
+ local_atomic_out[name] = Set(keys(agent.out_ports))
|
|
|
end
|
|
|
|
|
|
for (name, child) in node.coupled
|
|
|
@@ -227,7 +228,7 @@ function resolve_direct_couplings!(model, top_model::CoupledDEVS)
|
|
|
source_id = model.path_to_id[atomic_path]
|
|
|
atomic_agent = model[source_id]
|
|
|
|
|
|
- for out_port in atomic_agent.out_ports
|
|
|
+ for out_port in keys(atomic_agent.out_ports)
|
|
|
start_key = (atomic_path, out_port)
|
|
|
targets = Tuple{Int, Symbol}[]
|
|
|
|