Changeset 10454 for branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/DiscreteEventSimulation.cs
- Timestamp:
- 02/13/14 17:28:30 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/DiscreteEventSimulation.cs
r10450 r10454 2 2 using System.Collections.Generic; 3 3 using System.Linq; 4 using System.Text; 4 5 using System.Threading; 5 6 using HeuristicLab.Common; … … 32 33 } 33 34 35 [StorableConstructor] 36 protected DiscreteEventSimulation(bool deserializing) : base(deserializing) { } 34 37 protected DiscreteEventSimulation(DiscreteEventSimulation<TModel> original, Cloner cloner) 35 38 : base(original, cloner) { … … 39 42 Model = cloner.Clone(original.Model); 40 43 } 41 42 44 protected DiscreteEventSimulation() { 43 45 Parameters.Add(new FixedValueParameter<DoubleValue>("MaximumTime", "The simulation stops after reaching this time.", new DoubleValue(1000))); 46 } 47 48 protected override void OnPrepared() { 49 base.OnPrepared(); 50 if (CompositeEventQueue != null) 51 CompositeEventQueue.Clear(); 44 52 } 45 53 … … 47 55 CompositeEventQueue = new CompositeEventQueue<TModel>(Activities.Select(x => x.EventQueue)); 48 56 49 var actionMonitor = new Dictionary<Guid, List<IActivity<TModel>>>(); 57 var log = new StringBuilder(); 58 59 var actionMonitor = new Dictionary<Type, List<IActivity<TModel>>>(); 50 60 foreach (var activity in Activities) { 51 foreach (var actionId in activity.MonitoredAction Ids) {61 foreach (var actionId in activity.MonitoredActions) { 52 62 if (!actionMonitor.ContainsKey(actionId)) actionMonitor[actionId] = new List<IActivity<TModel>>(); 53 63 actionMonitor[actionId].Add(activity); … … 55 65 } 56 66 57 if ( InitialAction != null) {67 if (CompositeEventQueue.Empty && InitialAction != null) { 58 68 InitialAction.Execute(Model); 59 69 CallActivities(actionMonitor, InitialAction); … … 62 72 while (!CompositeEventQueue.Empty && Model.CurrentTime < MaximumTime) { 63 73 var @event = CompositeEventQueue.Pop(); 74 if (@event.Time < Model.CurrentTime) continue; 75 log.AppendLine(@event.Action.GetType().Name); 76 Model.CurrentTime = @event.Time; 77 64 78 var nextEvent = CompositeEventQueue.Empty ? null : CompositeEventQueue.Peek(); 65 79 var action = @event.Action; 66 80 67 81 action.Execute(Model); 68 CallActivities(actionMonitor, action);69 82 70 if (@event.Time > Model.CurrentTime && (nextEvent == null || @event.Time < nextEvent.Time)) { 71 var timeUpdateAction = new ModelTimeUpdateAction<TModel>(null, @event.Time); 72 timeUpdateAction.Execute(Model); 73 74 if (actionMonitor.ContainsKey(timeUpdateAction.ActionId)) 75 foreach (var activity in actionMonitor[timeUpdateAction.ActionId]) 76 activity.ManageEvents(Model, timeUpdateAction); 77 83 if (nextEvent == null || @event.Time < nextEvent.Time) { 78 84 foreach (var reporter in Reporters) 79 85 reporter.UpdateReporting(Model, Results); 80 86 } 87 88 CallActivities(actionMonitor, action); 89 81 90 cancellationToken.ThrowIfCancellationRequested(); 82 91 }; 83 92 } 84 93 85 private void CallActivities(Dictionary<Guid, List<IActivity<TModel>>> actionMonitor, IAction<TModel> action) { 86 if (actionMonitor.ContainsKey(action.ActionId)) { 87 foreach (var activity in actionMonitor[action.ActionId]) 94 private void CallActivities(Dictionary<Type, List<IActivity<TModel>>> actionMonitor, IAction<TModel> action) { 95 if (actionMonitor.ContainsKey(action.GetType())) { 96 foreach (var activity in actionMonitor[action.GetType()]) 97 activity.ManageEvents(Model, action); 98 } 99 100 if (actionMonitor.ContainsKey(typeof(object))) { 101 foreach (var activity in actionMonitor[typeof(object)]) 88 102 activity.ManageEvents(Model, action); 89 103 }
Note: See TracChangeset
for help on using the changeset viewer.