Explorar o código

one argument changed the whole game, removed phantom events and updated manual event scheduling

Snej69420 hai 4 meses
pai
achega
5b926a90c9
Modificáronse 2 ficheiros con 9 adicións e 17 borrados
  1. 8 16
      src/AtomicDEVS.jl
  2. 1 1
      src/CoupledDEVS.jl

+ 8 - 16
src/AtomicDEVS.jl

@@ -15,7 +15,6 @@ const Timer = TimerOutput()
 
     is_imminent::Bool = false
     is_receiving::Bool = false
-    is_phantom_pop::Bool = false
 end
 
 # DEVS Interface (To be extended by the modeler)
@@ -40,6 +39,11 @@ function simulate_devs!(model, duration::Float64=Inf)
 
         function stop_condition(model, step_number)
             queue = getfield(model, :event_queue)
+
+            total_events = length(queue)
+            inf_events = count(pair -> pair.second == Inf, queue.valtree)
+#             println("Total Events Scheduled: $total_events of which $inf_events are scheduled at infinity")
+
             isempty(queue) && return true
             next_time = first(queue)[2]
             return next_time > duration || next_time == Inf
@@ -131,7 +135,7 @@ end
 
     clear_inboxes!(a)
 
-    if a.id != triggering_agent_id && a.next_ta < Inf
+    if a.next_ta < Inf
         push!(model.requeue_buffer, a.id)
     end
 end
@@ -157,7 +161,7 @@ end
 
     clear_inboxes!(a)
 
-    if a.id != triggering_agent_id && a.next_ta < Inf
+    if a.next_ta < Inf
         push!(model.requeue_buffer, a.id)
     end
 end
@@ -225,10 +229,7 @@ function devs_step!(agent, model)
 
     target_time = agent.last_event_time + agent.next_ta
 
-    if abs(current_time - target_time) > 1e-9
-        agent.is_phantom_pop = true
-    else
-        agent.is_phantom_pop = false
+    if abs(current_time - target_time) <= 1e-9
         if !agent.is_imminent
             agent.is_imminent = true
             push!(model.imminent, agent.id)
@@ -254,15 +255,6 @@ function devs_step!(agent, model)
 end
 
 function engine_timing(agent, model)
-    if agent.is_phantom_pop
-        agent.is_phantom_pop = false
-        return Inf
-    end
-
-    if agent.is_imminent
-        return Inf # schedule new event at infinity until output phase is over
-    end
-
     if agent.next_ta < 0 # initialisation
         agent.next_ta = time_advance(agent, model)
     end

+ 1 - 1
src/CoupledDEVS.jl

@@ -334,7 +334,7 @@ function compile_devs(top_model::CoupledDEVS; logging::Union{Nothing, String}=no
             logging = logging,
             path_to_id = final_paths
         )
-        final_model = EventQueueABM(AgentUnion, (UniversalEvent, ); properties = final_props)
+        final_model = EventQueueABM(AgentUnion, (UniversalEvent, ); properties = final_props, autogenerate_after_action = false)
 #         @timeit Builder "Build Model" final_model = EventQueueABM(AgentUnion, (UniversalEvent, ); properties = final_props)
 
         typed_agents = Vector{AgentUnion}(final_agents)