Ejemplo n.º 1
0
 private static void Main(string[] args)
 {
     const int seed             = 1;
     IRandom   random           = new RandomGenerator(seed);
     var       eventsList       = new EventsList();
     var       nextEventChooser = new NextEventChooserStrategySmallestTimestamp();
     var       clock            = new Clock();
 }
        public Event Choose(EventsList eventsList, double currentClockTime)
        {
            var lastExecutedEvent = eventsList.GetLastReturnedEvent();

            if (lastExecutedEvent != null && lastExecutedEvent.DependantEvent != null)
            {
                var nextEventToExecute = lastExecutedEvent.DependantEvent;
                eventsList.RemoveEvent(nextEventToExecute);
                eventsList.SetLastExecutedEvent(nextEventToExecute);

                return(nextEventToExecute);
            }
            else
            {
                INextEventChooserStrategy smallestTimestampStrategy = new NextEventChooserStrategySmallestTimestamp();

                var nextEventToExecute = smallestTimestampStrategy.Choose(eventsList, currentClockTime);
                eventsList.SetLastExecutedEvent(nextEventToExecute);

                return(nextEventToExecute);
            }
        }