|
|
@@ -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
|