Changeset 10454 for branches/SimulationCore
- Timestamp:
- 02/13/14 17:28:30 (11 years ago)
- Location:
- branches/SimulationCore
- Files:
-
- 2 added
- 1 deleted
- 16 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SimulationCore/HeuristicLab.SimulationCore.Samples/3.3/GameOfLifeDiscreteEventSimulation.cs
r10450 r10454 6 6 using HeuristicLab.Optimization; 7 7 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 8 using HeuristicLab.Random; 8 9 9 10 namespace HeuristicLab.SimulationCore.Samples { 10 [Item("Game of Life (discrete event)", "A discrete event based implementation of the game of life simulation.")] 11 [Creatable("Simulations")] 12 public class GameOfLifeDiscreteEventSimulation : DiscreteEventSimulation<GameOfLifeModel> { 13 private GameOfLifeScenario Scenario { 14 get { return Problem as GameOfLifeScenario; } 15 set { Problem = value; } 16 } 17 18 private GameOfLifeDiscreteEventSimulation(GameOfLifeDiscreteEventSimulation original, Cloner cloner) 19 : base(original, cloner) { } 20 public GameOfLifeDiscreteEventSimulation() { 21 Scenario = new GameOfLifeScenario(); 22 InitialAction = new InitializeGameOfLifeBoardAction() { AliveRate = Scenario.AliveRateParameter.Value.Value }; 23 Activities = new IActivity<GameOfLifeModel>[] { new CurrentTimeMonitor() }; 24 Reporters = new IReporter<GameOfLifeModel>[] { new GameOfLifeStateReporter() }; 25 Initialize(); 26 } 27 28 private void Initialize() { 29 Scenario.WidthParameter.ValueChanged += ValueChanged; 30 if (Scenario.WidthParameter.Value != null) Scenario.WidthParameter.Value.ValueChanged += ParametersChanged; 31 Scenario.HeightParameter.ValueChanged += ValueChanged; 32 if (Scenario.HeightParameter.Value != null) Scenario.HeightParameter.Value.ValueChanged += ParametersChanged; 33 Scenario.AliveRateParameter.ValueChanged += ValueChanged; 34 if (Scenario.AliveRateParameter.Value != null) Scenario.AliveRateParameter.Value.ValueChanged += ParametersChanged; 35 } 36 37 38 private void ValueChanged(object sender, EventArgs e) { 39 if (Scenario.WidthParameter.Value != null) Scenario.WidthParameter.Value.ValueChanged += ParametersChanged; 40 if (Scenario.HeightParameter.Value != null) Scenario.HeightParameter.Value.ValueChanged += ParametersChanged; 41 if (Scenario.AliveRateParameter.Value != null) Scenario.AliveRateParameter.Value.ValueChanged += ParametersChanged; 42 ParametersChanged(sender, e); 43 } 44 45 private void ParametersChanged(object sender, EventArgs e) { 46 Model = new GameOfLifeModel(Scenario.WidthParameter.Value.Value, Scenario.HeightParameter.Value.Value); 47 ((InitializeGameOfLifeBoardAction)InitialAction).AliveRate = Scenario.AliveRateParameter.Value.Value; 48 } 49 50 protected override void OnPrepared() { 51 Model = new GameOfLifeModel(Scenario.WidthParameter.Value.Value, Scenario.HeightParameter.Value.Value); 52 base.OnPrepared(); 53 } 54 55 public override IDeepCloneable Clone(Cloner cloner) { 56 return new GameOfLifeDiscreteEventSimulation(this, cloner); 57 } 58 } 59 11 12 #region Model 60 13 [StorableClass] 61 14 public sealed class GameOfLifeModel : IModel { … … 79 32 } 80 33 } 81 82 [StorableClass] 83 sealed class CurrentTimeMonitor : Activity<GameOfLifeModel> { 84 public override IEnumerable<Guid> MonitoredActionIds { 85 get { return new[] { InitializeGameOfLifeBoardAction.Id, ModelTimeUpdateAction<GameOfLifeModel>.Id }; } 34 #endregion 35 36 #region Simulation 37 [Item("Game of Life (discrete event)", "A discrete event based implementation of the game of life simulation.")] 38 [Creatable("Simulations")] 39 public class GameOfLifeDiscreteEventSimulation : DiscreteEventSimulation<GameOfLifeModel> { 40 public override Type ProblemType { get { return typeof(GameOfLifeScenario); } } 41 42 private GameOfLifeScenario Scenario { 43 get { return (GameOfLifeScenario)base.Problem; } 44 set { base.Problem = value; } 45 } 46 47 private GameOfLifeDiscreteEventSimulation(GameOfLifeDiscreteEventSimulation original, Cloner cloner) 48 : base(original, cloner) { 49 RegisterScenarioEventHandlers(); 50 } 51 public GameOfLifeDiscreteEventSimulation() { 52 PrepareSimulation(); 53 Scenario = new GameOfLifeScenario(); 54 Parameterize(); 55 RegisterScenarioEventHandlers(); 56 } 57 58 public override IDeepCloneable Clone(Cloner cloner) { 59 return new GameOfLifeDiscreteEventSimulation(this, cloner); 60 } 61 62 [StorableHook(HookType.AfterDeserialization)] 63 private void AfterDeserialization() { 64 RegisterScenarioEventHandlers(); 65 } 66 67 private void PrepareSimulation() { 68 InitialAction = new InitializeGameOfLifeBoardAction(); 69 Activities = new IActivity<GameOfLifeModel>[] { new BoardActivity() }; 70 Reporters = new IReporter<GameOfLifeModel>[] { new GameOfLifeStateReporter() }; 71 } 72 73 private void RegisterScenarioEventHandlers() { 74 Scenario.WidthParameter.Value.ValueChanged += ParametersChanged; 75 Scenario.HeightParameter.Value.ValueChanged += ParametersChanged; 76 Scenario.AliveRateParameter.Value.ValueChanged += ParametersChanged; 77 } 78 79 protected override void OnProblemChanged() { 80 base.OnProblemChanged(); 81 Parameterize(); 82 RegisterScenarioEventHandlers(); 83 } 84 85 protected override void OnPrepared() { 86 base.OnPrepared(); 87 PrepareSimulation(); 88 } 89 90 private void ParametersChanged(object sender, EventArgs e) { 91 Parameterize(); 92 } 93 94 private void Parameterize() { 95 Model = new GameOfLifeModel(Scenario.WidthParameter.Value.Value, Scenario.HeightParameter.Value.Value); 96 ((InitializeGameOfLifeBoardAction)InitialAction).AliveRate = Scenario.AliveRateParameter.Value.Value; 97 } 98 } 99 #endregion 100 101 #region Activities 102 [StorableClass] 103 sealed class BoardActivity : Activity<GameOfLifeModel> { 104 public override IEnumerable<Type> MonitoredActions { 105 get { return new[] { typeof(InitializeGameOfLifeBoardAction), typeof(UpdateGameOfLifeBoardAction) }; } 86 106 } 87 107 88 108 [StorableConstructor] 89 private CurrentTimeMonitor(bool deserializing) : base(deserializing) { }90 private CurrentTimeMonitor(CurrentTimeMonitororiginal, Cloner cloner) : base(original, cloner) { }91 public CurrentTimeMonitor() : base(new SortedListEventQueue<GameOfLifeModel>()) { }109 private BoardActivity(bool deserializing) : base(deserializing) { } 110 private BoardActivity(BoardActivity original, Cloner cloner) : base(original, cloner) { } 111 public BoardActivity() : base(new SortedListEventQueue<GameOfLifeModel>()) { } 92 112 93 113 public override void ManageEvents(GameOfLifeModel model, IAction<GameOfLifeModel> lastAction) { 94 EventQueue.Push(new Event<GameOfLifeModel>(model.CurrentTime + 1, new UpdateGameOfLifeBoardAction())); 95 } 96 97 public override IDeepCloneable Clone(Cloner cloner) { 98 return new CurrentTimeMonitor(this, cloner); 99 } 100 } 101 114 EventQueue.Push(model.CurrentTime + 1, new UpdateGameOfLifeBoardAction()); 115 } 116 117 public override IDeepCloneable Clone(Cloner cloner) { 118 return new BoardActivity(this, cloner); 119 } 120 } 121 #endregion 122 123 #region Reporters 102 124 [StorableClass] 103 125 sealed class GameOfLifeStateReporter : Reporter<GameOfLifeModel> { … … 123 145 } 124 146 } 125 147 #endregion 148 149 #region Actions 126 150 [StorableClass] 127 151 sealed class InitializeGameOfLifeBoardAction : Action<GameOfLifeModel> { 128 public static readonly Guid Id = new Guid("a6d37f71-ccef-4c2a-b11b-793fda0f9f4f");129 public override Guid ActionId {130 get { return Id; }131 }132 133 152 [Storable] 134 153 public double AliveRate { get; set; } 135 154 136 [StorableConstructor]137 private InitializeGameOfLifeBoardAction(bool deserializing) : base(deserializing) { }138 155 private InitializeGameOfLifeBoardAction(InitializeGameOfLifeBoardAction original, Cloner cloner) 139 156 : base(original, cloner) { … … 145 162 146 163 public override void Execute(GameOfLifeModel model) { 147 var random = new Random();164 var random = new FastRandom(); 148 165 var rows = model.Grid.GetLength(0); 149 166 var cols = model.Grid.GetLength(1); … … 161 178 [StorableClass] 162 179 sealed class UpdateGameOfLifeBoardAction : Action<GameOfLifeModel> { 163 public static readonly Guid Id = new Guid("323bb2ef-bc66-488f-ac88-798b91565e62");164 public override Guid ActionId {165 get { return Id; }166 }167 168 [StorableConstructor]169 private UpdateGameOfLifeBoardAction(bool deserializing) : base(deserializing) { }170 180 private UpdateGameOfLifeBoardAction(UpdateGameOfLifeBoardAction original, Cloner cloner) : base(original, cloner) { } 171 181 public UpdateGameOfLifeBoardAction() { } … … 195 205 } 196 206 } 207 #endregion 197 208 } -
branches/SimulationCore/HeuristicLab.SimulationCore.Samples/3.3/GameOfLifeScenario.cs
r6624 r10454 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 25 using System.Text; 22 using HeuristicLab.Common; 26 23 using HeuristicLab.Core; 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;28 using HeuristicLab.Common;29 24 using HeuristicLab.Data; 30 25 using HeuristicLab.Parameters; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 27 32 28 namespace HeuristicLab.SimulationCore.Samples { 33 29 [Item("GameOfLifeScenario", "A game of life scenario.")] 34 30 [StorableClass] 35 public sealed class GameOfLifeScenario : Scenario {36 public ValueParameter<IntValue> WidthParameter {37 get { return ( ValueParameter<IntValue>)Parameters["Width"]; }31 public sealed class GameOfLifeScenario : Scenario { 32 public IFixedValueParameter<IntValue> WidthParameter { 33 get { return (IFixedValueParameter<IntValue>)Parameters["Width"]; } 38 34 } 39 public ValueParameter<IntValue> HeightParameter {40 get { return ( ValueParameter<IntValue>)Parameters["Height"]; }35 public IFixedValueParameter<IntValue> HeightParameter { 36 get { return (IFixedValueParameter<IntValue>)Parameters["Height"]; } 41 37 } 42 public ValueParameter<PercentValue> AliveRateParameter {43 get { return ( ValueParameter<PercentValue>)Parameters["AliveRate"]; }38 public IFixedValueParameter<PercentValue> AliveRateParameter { 39 get { return (IFixedValueParameter<PercentValue>)Parameters["AliveRate"]; } 44 40 } 45 41 46 42 public GameOfLifeScenario() 47 43 : base() { 48 Parameters.Add(new ValueParameter<IntValue>("Width", "The width value.", new IntValue(100)));49 Parameters.Add(new ValueParameter<IntValue>("Height", "The height value.", new IntValue(100)));50 Parameters.Add(new ValueParameter<PercentValue>("AliveRate", "The rate of the initialyy alive cells.", new PercentValue(0.5)));44 Parameters.Add(new FixedValueParameter<IntValue>("Width", "The width value.", new IntValue(100))); 45 Parameters.Add(new FixedValueParameter<IntValue>("Height", "The height value.", new IntValue(100))); 46 Parameters.Add(new FixedValueParameter<PercentValue>("AliveRate", "The rate of the initialyy alive cells.", new PercentValue(0.5))); 51 47 } 52 48 [StorableConstructor] -
branches/SimulationCore/HeuristicLab.SimulationCore.Samples/3.3/GameOfLifeSimulation.cs
r7204 r10454 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 25 using System.Text; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 24 using System.Threading; 25 using HeuristicLab.Analysis; 27 26 using HeuristicLab.Common; 28 27 using HeuristicLab.Core; 29 using HeuristicLab.Parameters;30 28 using HeuristicLab.Data; 31 29 using HeuristicLab.Optimization; 32 using System.Threading; 30 using HeuristicLab.Parameters; 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 32 using HeuristicLab.Random; 33 33 using HeuristicLab.SimulationCore.AgentBased; 34 using HeuristicLab.Analysis;35 34 36 35 namespace HeuristicLab.SimulationCore.Samples { … … 38 37 [Creatable("Simulations")] 39 38 [StorableClass] 40 public sealed class GameOfLifeSimulation : AgentBasedSimulation {39 public sealed class GameOfLifeSimulation : AgentBasedSimulation { 41 40 public override Type ProblemType { 42 41 get { return typeof(GameOfLifeScenario); } … … 48 47 } 49 48 } 50 49 51 50 public ValueParameter<IntValue> IterationsParameter { 52 51 get { return (ValueParameter<IntValue>)Parameters["Iterations"]; } 53 52 } 54 55 public GameOfLifeSimulation() : base() { 53 54 public GameOfLifeSimulation() 55 : base() { 56 56 Parameters.Add(new ValueParameter<IntValue>("Iterations", "The number of iterations.", new IntValue(100))); 57 57 … … 72 72 } 73 73 74 private GameOfLifeAgent GetAgent(int x, int y) { 74 private GameOfLifeAgent GetAgent(int x, int y) { 75 75 int width = Scenario.WidthParameter.Value.Value; 76 76 int height = Scenario.HeightParameter.Value.Value; … … 79 79 throw new Exception("invalid index"); 80 80 81 int index = x + y * width; 81 int index = x + y * width; 82 82 83 83 return Agents[index] as GameOfLifeAgent; … … 86 86 private void Initialize() { 87 87 if (Scenario != null) { 88 Scenario.WidthParameter.ValueChanged += new EventHandler(WidthParameter_ValueChanged); 89 if(Scenario.WidthParameter.Value != null) 90 Scenario.WidthParameter.Value.ValueChanged += new EventHandler(Width_ValueChanged); 91 Scenario.HeightParameter.ValueChanged += new EventHandler(HeightParameter_ValueChanged); 92 if (Scenario.HeightParameter.Value != null) 93 Scenario.HeightParameter.Value.ValueChanged += new EventHandler(Height_ValueChanged); 88 Scenario.WidthParameter.Value.ValueChanged += new EventHandler(Width_ValueChanged); 89 Scenario.HeightParameter.Value.ValueChanged += new EventHandler(Height_ValueChanged); 94 90 } 95 91 } … … 103 99 } 104 100 105 void HeightParameter_ValueChanged(object sender, EventArgs e) {106 CreateAgents();107 }108 109 void WidthParameter_ValueChanged(object sender, EventArgs e) {110 CreateAgents();111 }112 113 101 public IEnumerable<GameOfLifeAgent> GetNeighbors(GameOfLifeAgent agent) { 114 102 int width = Scenario.WidthParameter.Value.Value; 115 103 int height = Scenario.HeightParameter.Value.Value; 116 104 int index = Agents.IndexOf(agent); 117 105 118 106 List<GameOfLifeAgent> result = new List<GameOfLifeAgent>(); 119 107 … … 159 147 int height = Scenario.HeightParameter.Value.Value; 160 148 161 Random rand = newRandom();149 var rand = new FastRandom(); 162 150 163 151 for (int i = 0; i < width * height; i++) { … … 190 178 191 179 Results["Cells"].Value = cells; 192 180 193 181 IntValue currentIterations = (Results["CurrentIterations"].Value as IntValue); 194 182 currentIterations.Value++; … … 206 194 Results.Add(new Result("CurrentIterations", new IntValue(0))); 207 195 Results.Add(new Result("Cells", new HeatMap(width, height))); 208 } 196 } 209 197 210 198 for (int i = start; i < iterations; i++) { 211 199 cancellationToken.ThrowIfCancellationRequested(); 212 200 213 201 base.Step(); 214 UpdateResults(); 202 UpdateResults(); 215 203 } 216 204 } -
branches/SimulationCore/HeuristicLab.SimulationCore.Samples/3.3/HeuristicLab.SimulationCore.Samples-3.3.csproj
r10450 r10454 155 155 <Private>False</Private> 156 156 </Reference> 157 <Reference Include="HeuristicLab.Random-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL"> 158 <SpecificVersion>False</SpecificVersion> 159 <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Random-3.3.dll</HintPath> 160 </Reference> 157 161 <Reference Include="System" /> 158 162 <Reference Include="System.Core" /> … … 164 168 </ItemGroup> 165 169 <ItemGroup> 170 <Compile Include="CardGameSimulation.cs" /> 166 171 <Compile Include="GameOfLifeAgent.cs" /> 167 172 <Compile Include="GameOfLifeDiscreteEventSimulation.cs" /> -
branches/SimulationCore/HeuristicLab.SimulationCore.Tests/EventQueueTest.cs
r10450 r10454 32 32 public void EventQueueCreateTest() { 33 33 var queue = new SortedListEventQueue<IModel>(); 34 queue.Push( new Event<IModel>(5, new DummyAction()));34 queue.Push(5, new DummyAction()); 35 35 Assert.IsTrue(queue.Count == 1); 36 queue.Push( new Event<IModel>(2, new DummyAction()));36 queue.Push(2, new DummyAction()); 37 37 Assert.IsTrue(queue.Peek().Time == 2); 38 38 Assert.IsTrue(queue.Count == 2); 39 queue.Push( new Event<IModel>(3, new DummyAction()));39 queue.Push(3, new DummyAction()); 40 40 Assert.IsTrue(queue.Peek().Time == 2); 41 41 Assert.IsTrue(queue.Count == 3); 42 42 for (var i = 10; i < 50; i++) 43 queue.Push( new Event<IModel>(i, new DummyAction()));43 queue.Push(i, new DummyAction()); 44 44 Assert.IsTrue(queue.Peek().Time == 2); 45 45 Assert.IsTrue(queue.Count == 43); 46 queue.Push( new Event<IModel>(2, new DummyAction()));46 queue.Push(2, new DummyAction()); 47 47 } 48 48 } -
branches/SimulationCore/HeuristicLab.SimulationCore.sln
r10450 r10454 74 74 HideSolutionNode = FALSE 75 75 EndGlobalSection 76 GlobalSection(Performance) = preSolution77 HasPerformanceSessions = true78 EndGlobalSection79 76 EndGlobal -
branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/Action.cs
r10450 r10454 6 6 [StorableClass] 7 7 public abstract class Action<TModel> : IAction<TModel> where TModel : IModel { 8 public abstract Guid ActionId { get; }9 8 public IActivity<TModel> Mandate { get; protected set; } 10 9 -
branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/Activity.cs
r10450 r10454 15 15 } 16 16 17 public virtual IEnumerable< Guid> MonitoredActionIds {18 get { return new Guid[0]; }17 public virtual IEnumerable<Type> MonitoredActions { 18 get { return new Type[0]; } 19 19 } 20 20 -
branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/CompositeEventQueue.cs
r10450 r10454 41 41 } 42 42 43 public void Clear() { 44 foreach (var queue in queues) { 45 queue.Clear(); 46 } 47 } 48 43 49 [StorableConstructor] 44 50 private CompositeEventQueue(bool deserializing) : base(deserializing) { } -
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 } -
branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/Event.cs
r10450 r10454 11 11 12 12 #region Storable Properties 13 [Storable]14 13 // ReSharper disable UnusedMember.Local 15 14 // ReSharper disable UnusedParameter.Local 15 [Storable] 16 16 private double StorableTime { 17 17 get { return time; } -
branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/Interfaces/IAction.cs
r10450 r10454 1 using System; 2 using HeuristicLab.Common; 1 using HeuristicLab.Common; 3 2 4 3 namespace HeuristicLab.SimulationCore { 5 4 public interface IAction<TModel> : IDeepCloneable, IContent where TModel : IModel { 6 Guid ActionId { get; }7 5 IActivity<TModel> Mandate { get; } 8 6 -
branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/Interfaces/IActivity.cs
r10450 r10454 7 7 where TModel : IModel { 8 8 IEventQueue<TModel> EventQueue { get; } 9 IEnumerable< Guid> MonitoredActionIds { get; }9 IEnumerable<Type> MonitoredActions { get; } 10 10 11 11 void ManageEvents(TModel model, IAction<TModel> lastAction); -
branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/Interfaces/IEventQueue.cs
r10450 r10454 8 8 IEvent<TModel> Peek(); 9 9 IEvent<TModel> Pop(); 10 void Push( IEvent<TModel> @event);10 void Push(double time, IAction<TModel> action); 11 11 12 12 IEvent<TModel> ChangeTime(IEvent<TModel> @event, double newTime); -
branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/SortedListEventQueue.cs
r10450 r10454 26 26 } 27 27 28 public void Push(IEvent<TModel> @event) { 29 if (queue.ContainsKey(@event.Time)) 30 queue[@event.Time].Add(@event); 31 else queue.Add(@event.Time, new List<IEvent<TModel>>() { @event }); 28 public void Push(double time, IAction<TModel> action) { 29 PushEvent(time, action); 30 } 31 32 private IEvent<TModel> PushEvent(double time, IAction<TModel> action) { 33 IEvent<TModel> result = new Event<TModel>(time, action); 34 if (queue.ContainsKey(time)) 35 queue[time].Add(result); 36 else queue.Add(time, new List<IEvent<TModel>>() { result }); 37 return result; 32 38 } 33 39 34 40 public IEvent<TModel> ChangeTime(IEvent<TModel> @event, double newTime) { 35 41 Remove(@event); 36 var newEvent = new Event<TModel>(newTime, @event.Action); 37 Push(newEvent); 38 return newEvent; 42 return PushEvent(newTime, @event.Action); 39 43 } 40 44 -
branches/SimulationCore/HeuristicLab.SimulationCore/3.3/HeuristicLab.SimulationCore-3.3.csproj
r10450 r10454 159 159 <Compile Include="DiscreteEvent\Event.cs" /> 160 160 <Compile Include="DiscreteEvent\Interfaces\IReporter.cs" /> 161 <Compile Include="DiscreteEvent\Model TimeUpdateAction.cs" />161 <Compile Include="DiscreteEvent\Model.cs" /> 162 162 <Compile Include="DiscreteEvent\Reporter.cs" /> 163 163 <Compile Include="DiscreteEvent\SortedListEventQueue.cs" />
Note: See TracChangeset
for help on using the changeset viewer.