Browse Source

removed artificial translation function

Snej69420 6 months ago
parent
commit
7bf4efe501

+ 2 - 6
benchmarks/Agents/DelayedAtomic.jl

@@ -2,10 +2,6 @@ import DEVS2Agents: time_advance, internal_transition!, external_transition!, co
 
 @enum State Passive=1 Active=2
 
-struct A2A
-    activate::Int
-end
-
 function julia_stones(delay::Float64)
     val = 0.0
     for i in 1:Int(round(delay))
@@ -27,7 +23,7 @@ end
 end
 
 format_state(agent::DelayedAtomic) = "State.$(agent.state)"
-format_message(msg::A2A) = "$(msg.activate)"
+format_message(msg::Int) = "$(msg)"
 
 function time_advance(agent::DelayedAtomic, model)
     return agent.state == Active ? agent.prep_time : Inf
@@ -52,6 +48,6 @@ end
 
 function output!(agent::DelayedAtomic, model)
     if agent.has_out_port
-        send_message!(agent, model, :o_out, A2A(0))
+        send_message!(agent, model, :o_out, 0)
     end
 end

+ 2 - 6
benchmarks/Agents/Generator.jl

@@ -1,9 +1,5 @@
 import DEVS2Agents: time_advance, internal_transition!, output!, send_message!, format_state, format_message
 
-struct Generate
-    activate::Int
-end
-
 @agent struct Generator{I, O}(AtomicDEVS{I, O})
     output::Int = 1
     period::Float64 = 1.0
@@ -11,7 +7,7 @@ end
 end
 
 format_state(gen::Generator) = "Cycles Left $(gen.cycles)"
-format_message(msg::Generate) = "$(msg.activate)"
+format_message(msg::Int) = "$(msg)"
 
 function internal_transition!(gen::Generator, model)
     gen.cycles -= 1
@@ -23,6 +19,6 @@ end
 
 function output!(gen::Generator, model)
     if gen.cycles > 0
-        send_message!(gen, model, :o_out, Generate(gen.output))
+        send_message!(gen, model, :o_out, gen.output)
     end
 end

+ 24 - 26
benchmarks/Agents/Topologies.jl

@@ -1,7 +1,5 @@
 @enum Structure LI HI HO HOmod
 
-translate = (msg::A2A) -> (A2A(msg.activate))
-
 # Port Config
 function setup_ports!(top_model::CoupledDEVS, type::Structure)
     has_out_port = type in (HI, HO, HOmod)
@@ -26,14 +24,14 @@ function build_leaf_node(name::String, type::Structure, int_delay::Float64, ext_
 
     p_time = round(rand() + 1.0, digits=3)
     atom = add_submodel!(top_model, "A0", DelayedAtomic;
-        inbox=(; i_in=A2A[]),
-        out_ports=has_out_port ? (; o_out=A2A) : (;),
+        inbox=(; i_in=Int[]),
+        out_ports=has_out_port ? (; o_out=Int) : (;),
         int_delay=int_delay, ext_delay=ext_delay, prep_time=p_time,
         has_out_port=has_out_port, stats=stats)
 
-    connect!(top_model, self.i_in, atom.i_in; Z=translate)
+    connect!(top_model, self.i_in, atom.i_in)
     if has_out_port
-        connect!(top_model, atom.o_out, self.o_out; Z=translate)
+        connect!(top_model, atom.o_out, self.o_out)
     end
 
     return top_model
@@ -47,8 +45,8 @@ function build_atomics!(top_model::CoupledDEVS, depth::Int, width::Int, int_dela
         atomic_name = "A$(idx)"
 
         atom = add_submodel!(top_model, atomic_name, DelayedAtomic;
-            inbox=(; i_in=A2A[]),
-            out_ports=has_out_port ? (; o_out=A2A) : (;),
+            inbox=(; i_in=Int[]),
+            out_ports=has_out_port ? (; o_out=Int) : (;),
             int_delay=int_delay, ext_delay=ext_delay, prep_time=p_time,
             has_out_port=has_out_port, stats=stats)
 
@@ -60,16 +58,16 @@ end
 # Routing
 function route_LI!(top_model::CoupledDEVS, width_models::Vector{ModelRef})
     for atom in width_models
-        connect!(top_model, self.i_in, atom.i_in; Z=translate)
+        connect!(top_model, self.i_in, atom.i_in)
     end
 end
 
 function route_HI!(top_model::CoupledDEVS, width_models::Vector{ModelRef})
     for atom in width_models
-        connect!(top_model, self.i_in, atom.i_in; Z=translate)
+        connect!(top_model, self.i_in, atom.i_in)
     end
     for i in 1:(length(width_models) - 1)
-        connect!(top_model, width_models[i].o_out, width_models[i + 1].i_in; Z=translate)
+        connect!(top_model, width_models[i].o_out, width_models[i + 1].i_in)
     end
 end
 
@@ -78,15 +76,15 @@ function route_HO!(top_model::CoupledDEVS, width_models::Vector{ModelRef})
         curr_atom = width_models[i]
         next_atom = width_models[i + 1]
 
-        connect!(top_model, curr_atom.o_out, next_atom.i_in; Z=translate)
-        connect!(top_model, self.i_in2, curr_atom.i_in; Z=translate)
-        connect!(top_model, curr_atom.o_out, self.o_out2; Z=translate)
+        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 !isempty(width_models)
         last_atom = width_models[end]
-        connect!(top_model, self.i_in2, last_atom.i_in; Z=translate)
-        connect!(top_model, last_atom.o_out, self.o_out2; Z=translate)
+        connect!(top_model, self.i_in2, last_atom.i_in)
+        connect!(top_model, last_atom.o_out, self.o_out2)
     end
 end
 
@@ -107,8 +105,8 @@ function build_HOmod!(top_model::CoupledDEVS, child::ModelRef, depth::Int, width
             atomic_name = "A$(i)_$(j)"
 
             atom = add_submodel!(top_model, atomic_name, DelayedAtomic;
-                inbox=(; i_in=A2A[]),
-                out_ports=(; o_out=A2A),
+                inbox=(; i_in=Int[]),
+                out_ports=(; o_out=Int),
                 int_delay=int_delay, ext_delay=ext_delay, prep_time=1.0,
                 has_out_port=true, stats=stats)
 
@@ -117,29 +115,29 @@ function build_HOmod!(top_model::CoupledDEVS, child::ModelRef, depth::Int, width
     end
 
     for atom in atomics[0]
-        connect!(top_model, self.i_in2, atom.i_in; Z=translate)
+        connect!(top_model, self.i_in2, atom.i_in)
     end
     for i in 1:(width - 1)
         if !isempty(atomics[i])
-            connect!(top_model, self.i_in2, atomics[i][1].i_in; Z=translate)
+            connect!(top_model, self.i_in2, atomics[i][1].i_in)
         end
     end
 
     for atom in atomics[0]
-        connect!(top_model, atom.o_out, child.i_in2; Z=translate)
+        connect!(top_model, atom.o_out, child.i_in2)
     end
 
     if haskey(atomics, 1) && haskey(atomics, 0)
         for atom1 in atomics[1]
             for atom0 in atomics[0]
-                connect!(top_model, atom1.o_out, atom0.i_in; Z=translate)
+                connect!(top_model, atom1.o_out, atom0.i_in)
             end
         end
     end
 
     for i in 2:(width - 1)
         for j in 1:length(atomics[i])
-            connect!(top_model, atomics[i][j].o_out, atomics[i-1][j+1].i_in; Z=translate)
+            connect!(top_model, atomics[i][j].o_out, atomics[i-1][j+1].i_in)
         end
     end
 end
@@ -164,12 +162,12 @@ function build_devstone(type::Structure, name::String, depth::Int, width::Int, i
     child = add_submodel!(top_model, coupled_name, child_coupled)
 
     # Connect Parent to Child
-    connect!(top_model, self.i_in, child.i_in; Z=translate)
+    connect!(top_model, self.i_in, child.i_in)
     if type == HO
-        connect!(top_model, self.i_in, child.i_in2; Z=translate)
+        connect!(top_model, self.i_in, child.i_in2)
     end
     if has_out_port
-        connect!(top_model, child.o_out, self.o_out; Z=translate)
+        connect!(top_model, child.o_out, self.o_out)
     end
 
     # Sub-topology Generation & Routing

+ 4 - 5
benchmarks/Agents/main.jl

@@ -80,14 +80,13 @@ end
 function build_environment(type::Structure, devstone_model::CoupledDEVS, gen_period::Float64)
     env = CoupledDEVS("DEVStoneEnvironment")
     add_submodel!(env, :generator, Generator;
-        out_ports=(; o_out=Generate),
+        out_ports=(; o_out=Int),
         output = 6, period = gen_period, cycles = 1)
     add_submodel!(env, :devstone, devstone_model)
 
-    to_a2a = (msg::Generate) -> A2A(ceil(msg.activate * 1.5))
-    connect!(env, ModelRef(:generator).o_out, ModelRef(:devstone).i_in; Z=to_a2a)
+    connect!(env, ModelRef(:generator).o_out, ModelRef(:devstone).i_in)
     if type == HO || type == HOmod
-        connect!(env, ModelRef(:generator).o_out, ModelRef(:devstone).i_in2; Z=to_a2a)
+        connect!(env, ModelRef(:generator).o_out, ModelRef(:devstone).i_in2)
     end
     return env
 end
@@ -164,7 +163,7 @@ function run_single_simulation(topology_type::Structure, depth::Int, width::Int,
     end
     type_str = enum_to_string(topology_type)
 
-    GC.gc(true) # clear the heap before the next run
+    GC.gc() # clear the heap before the next run
     pp_proc = nothing
     if memory != ""
         my_pid = getpid()