HOME       UP       PREV       NEXT (Inertial and Transport Delay)  

Event Driven Simulation - Further Details

Create initial, empty event list:

val eventlist = ref [];
Constructor for a new event: insert at correct point in the sorted event list:
fun create_and_insert_event(time, net, value) =
    let fun ins e = case !e of
                (A as EMPTY) => e := EVENT(time, net, value, ref A)
              | (A as EVENT(t, n, v, e')) => if (t > time)
                   then e := EVENT(time, net, value, ref A)
                   else ins e'
        in ins eventlist
Main simulation: keep dispatching until event list empty:
fun dispatch_one_event() =
	if (!eventlist = EMPTY) then print("simulation finished - no more events\n")
	else let val EVENT(time, net, value, e') = !eventlist in
	( eventlist := !e';
	  tnow := time;
	  app execute_model (net_setvalue(net, value))
	) end

24: (C) 2008-11, DJ Greaves, University of Cambridge, Computer Laboratory.