HOME       UP       PREV       NEXT (Modelling Zero-Delay Components)  

Event Driven Simulation Kernel Continued

Constructor for a new event: insert at correct point in the sorted event list:
fun event(time, net, value) =
    let fun a 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 a e'
        in a 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 example_models (net_setvalue(net, value))
	) end

(C) 2008-10, DJ Greaves, University of Cambridge, Computer Laboratory.