Changeset 10454


Ignore:
Timestamp:
02/13/14 17:28:30 (6 years ago)
Author:
abeham
Message:

#1610: updated core, implemented card game sample

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  
    66using HeuristicLab.Optimization;
    77using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     8using HeuristicLab.Random;
    89
    910namespace 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
    6013  [StorableClass]
    6114  public sealed class GameOfLifeModel : IModel {
     
    7932    }
    8033  }
    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) }; }
    86106    }
    87107
    88108    [StorableConstructor]
    89     private CurrentTimeMonitor(bool deserializing) : base(deserializing) { }
    90     private CurrentTimeMonitor(CurrentTimeMonitor original, 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>()) { }
    92112
    93113    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
    102124  [StorableClass]
    103125  sealed class GameOfLifeStateReporter : Reporter<GameOfLifeModel> {
     
    123145    }
    124146  }
    125 
     147  #endregion
     148
     149  #region Actions
    126150  [StorableClass]
    127151  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 
    133152    [Storable]
    134153    public double AliveRate { get; set; }
    135154
    136     [StorableConstructor]
    137     private InitializeGameOfLifeBoardAction(bool deserializing) : base(deserializing) { }
    138155    private InitializeGameOfLifeBoardAction(InitializeGameOfLifeBoardAction original, Cloner cloner)
    139156      : base(original, cloner) {
     
    145162
    146163    public override void Execute(GameOfLifeModel model) {
    147       var random = new Random();
     164      var random = new FastRandom();
    148165      var rows = model.Grid.GetLength(0);
    149166      var cols = model.Grid.GetLength(1);
     
    161178  [StorableClass]
    162179  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) { }
    170180    private UpdateGameOfLifeBoardAction(UpdateGameOfLifeBoardAction original, Cloner cloner) : base(original, cloner) { }
    171181    public UpdateGameOfLifeBoardAction() { }
     
    195205    }
    196206  }
     207  #endregion
    197208}
  • branches/SimulationCore/HeuristicLab.SimulationCore.Samples/3.3/GameOfLifeScenario.cs

    r6624 r10454  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
     22using HeuristicLab.Common;
    2623using HeuristicLab.Core;
    27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    28 using HeuristicLab.Common;
    2924using HeuristicLab.Data;
    3025using HeuristicLab.Parameters;
     26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3127
    3228namespace HeuristicLab.SimulationCore.Samples {
    3329  [Item("GameOfLifeScenario", "A game of life scenario.")]
    3430  [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"]; }
    3834    }
    39     public ValueParameter<IntValue> HeightParameter {
    40       get { return (ValueParameter<IntValue>)Parameters["Height"]; }
     35    public IFixedValueParameter<IntValue> HeightParameter {
     36      get { return (IFixedValueParameter<IntValue>)Parameters["Height"]; }
    4137    }
    42     public ValueParameter<PercentValue> AliveRateParameter {
    43       get { return (ValueParameter<PercentValue>)Parameters["AliveRate"]; }
     38    public IFixedValueParameter<PercentValue> AliveRateParameter {
     39      get { return (IFixedValueParameter<PercentValue>)Parameters["AliveRate"]; }
    4440    }
    4541
    4642    public GameOfLifeScenario()
    4743      : 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)));
    5147    }
    5248    [StorableConstructor]
  • branches/SimulationCore/HeuristicLab.SimulationCore.Samples/3.3/GameOfLifeSimulation.cs

    r7204 r10454  
    2222using System;
    2323using System.Collections.Generic;
    24 using System.Linq;
    25 using System.Text;
    26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     24using System.Threading;
     25using HeuristicLab.Analysis;
    2726using HeuristicLab.Common;
    2827using HeuristicLab.Core;
    29 using HeuristicLab.Parameters;
    3028using HeuristicLab.Data;
    3129using HeuristicLab.Optimization;
    32 using System.Threading;
     30using HeuristicLab.Parameters;
     31using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     32using HeuristicLab.Random;
    3333using HeuristicLab.SimulationCore.AgentBased;
    34 using HeuristicLab.Analysis;
    3534
    3635namespace HeuristicLab.SimulationCore.Samples {
     
    3837  [Creatable("Simulations")]
    3938  [StorableClass]
    40   public sealed class GameOfLifeSimulation: AgentBasedSimulation {
     39  public sealed class GameOfLifeSimulation : AgentBasedSimulation {
    4140    public override Type ProblemType {
    4241      get { return typeof(GameOfLifeScenario); }
     
    4847      }
    4948    }
    50    
     49
    5150    public ValueParameter<IntValue> IterationsParameter {
    5251      get { return (ValueParameter<IntValue>)Parameters["Iterations"]; }
    5352    }
    54    
    55     public GameOfLifeSimulation() : base() {
     53
     54    public GameOfLifeSimulation()
     55      : base() {
    5656      Parameters.Add(new ValueParameter<IntValue>("Iterations", "The number of iterations.", new IntValue(100)));
    5757
     
    7272    }
    7373
    74     private GameOfLifeAgent GetAgent(int x, int y) {     
     74    private GameOfLifeAgent GetAgent(int x, int y) {
    7575      int width = Scenario.WidthParameter.Value.Value;
    7676      int height = Scenario.HeightParameter.Value.Value;
     
    7979        throw new Exception("invalid index");
    8080
    81       int index = x + y * width; 
     81      int index = x + y * width;
    8282
    8383      return Agents[index] as GameOfLifeAgent;
     
    8686    private void Initialize() {
    8787      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);
    9490      }
    9591    }
     
    10399    }
    104100
    105     void HeightParameter_ValueChanged(object sender, EventArgs e) {
    106       CreateAgents();
    107     }
    108 
    109     void WidthParameter_ValueChanged(object sender, EventArgs e) {
    110       CreateAgents();
    111     }
    112 
    113101    public IEnumerable<GameOfLifeAgent> GetNeighbors(GameOfLifeAgent agent) {
    114102      int width = Scenario.WidthParameter.Value.Value;
    115103      int height = Scenario.HeightParameter.Value.Value;
    116104      int index = Agents.IndexOf(agent);
    117      
     105
    118106      List<GameOfLifeAgent> result = new List<GameOfLifeAgent>();
    119107
     
    159147      int height = Scenario.HeightParameter.Value.Value;
    160148
    161       Random rand = new Random();
     149      var rand = new FastRandom();
    162150
    163151      for (int i = 0; i < width * height; i++) {
     
    190178
    191179      Results["Cells"].Value = cells;
    192      
     180
    193181      IntValue currentIterations = (Results["CurrentIterations"].Value as IntValue);
    194182      currentIterations.Value++;
     
    206194        Results.Add(new Result("CurrentIterations", new IntValue(0)));
    207195        Results.Add(new Result("Cells", new HeatMap(width, height)));
    208       }     
     196      }
    209197
    210198      for (int i = start; i < iterations; i++) {
    211199        cancellationToken.ThrowIfCancellationRequested();
    212        
     200
    213201        base.Step();
    214         UpdateResults();       
     202        UpdateResults();
    215203      }
    216204    }
  • branches/SimulationCore/HeuristicLab.SimulationCore.Samples/3.3/HeuristicLab.SimulationCore.Samples-3.3.csproj

    r10450 r10454  
    155155      <Private>False</Private>
    156156    </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>
    157161    <Reference Include="System" />
    158162    <Reference Include="System.Core" />
     
    164168  </ItemGroup>
    165169  <ItemGroup>
     170    <Compile Include="CardGameSimulation.cs" />
    166171    <Compile Include="GameOfLifeAgent.cs" />
    167172    <Compile Include="GameOfLifeDiscreteEventSimulation.cs" />
  • branches/SimulationCore/HeuristicLab.SimulationCore.Tests/EventQueueTest.cs

    r10450 r10454  
    3232    public void EventQueueCreateTest() {
    3333      var queue = new SortedListEventQueue<IModel>();
    34       queue.Push(new Event<IModel>(5, new DummyAction()));
     34      queue.Push(5, new DummyAction());
    3535      Assert.IsTrue(queue.Count == 1);
    36       queue.Push(new Event<IModel>(2, new DummyAction()));
     36      queue.Push(2, new DummyAction());
    3737      Assert.IsTrue(queue.Peek().Time == 2);
    3838      Assert.IsTrue(queue.Count == 2);
    39       queue.Push(new Event<IModel>(3, new DummyAction()));
     39      queue.Push(3, new DummyAction());
    4040      Assert.IsTrue(queue.Peek().Time == 2);
    4141      Assert.IsTrue(queue.Count == 3);
    4242      for (var i = 10; i < 50; i++)
    43         queue.Push(new Event<IModel>(i, new DummyAction()));
     43        queue.Push(i, new DummyAction());
    4444      Assert.IsTrue(queue.Peek().Time == 2);
    4545      Assert.IsTrue(queue.Count == 43);
    46       queue.Push(new Event<IModel>(2, new DummyAction()));
     46      queue.Push(2, new DummyAction());
    4747    }
    4848  }
  • branches/SimulationCore/HeuristicLab.SimulationCore.sln

    r10450 r10454  
    7474    HideSolutionNode = FALSE
    7575  EndGlobalSection
    76   GlobalSection(Performance) = preSolution
    77     HasPerformanceSessions = true
    78   EndGlobalSection
    7976EndGlobal
  • branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/Action.cs

    r10450 r10454  
    66  [StorableClass]
    77  public abstract class Action<TModel> : IAction<TModel> where TModel : IModel {
    8     public abstract Guid ActionId { get; }
    98    public IActivity<TModel> Mandate { get; protected set; }
    109
  • branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/Activity.cs

    r10450 r10454  
    1515    }
    1616
    17     public virtual IEnumerable<Guid> MonitoredActionIds {
    18       get { return new Guid[0]; }
     17    public virtual IEnumerable<Type> MonitoredActions {
     18      get { return new Type[0]; }
    1919    }
    2020
  • branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/CompositeEventQueue.cs

    r10450 r10454  
    4141    }
    4242
     43    public void Clear() {
     44      foreach (var queue in queues) {
     45        queue.Clear();
     46      }
     47    }
     48
    4349    [StorableConstructor]
    4450    private CompositeEventQueue(bool deserializing) : base(deserializing) { }
  • branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/DiscreteEventSimulation.cs

    r10450 r10454  
    22using System.Collections.Generic;
    33using System.Linq;
     4using System.Text;
    45using System.Threading;
    56using HeuristicLab.Common;
     
    3233    }
    3334
     35    [StorableConstructor]
     36    protected DiscreteEventSimulation(bool deserializing) : base(deserializing) { }
    3437    protected DiscreteEventSimulation(DiscreteEventSimulation<TModel> original, Cloner cloner)
    3538      : base(original, cloner) {
     
    3942      Model = cloner.Clone(original.Model);
    4043    }
    41 
    4244    protected DiscreteEventSimulation() {
    4345      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();
    4452    }
    4553
     
    4755      CompositeEventQueue = new CompositeEventQueue<TModel>(Activities.Select(x => x.EventQueue));
    4856
    49       var actionMonitor = new Dictionary<Guid, List<IActivity<TModel>>>();
     57      var log = new StringBuilder();
     58
     59      var actionMonitor = new Dictionary<Type, List<IActivity<TModel>>>();
    5060      foreach (var activity in Activities) {
    51         foreach (var actionId in activity.MonitoredActionIds) {
     61        foreach (var actionId in activity.MonitoredActions) {
    5262          if (!actionMonitor.ContainsKey(actionId)) actionMonitor[actionId] = new List<IActivity<TModel>>();
    5363          actionMonitor[actionId].Add(activity);
     
    5565      }
    5666
    57       if (InitialAction != null) {
     67      if (CompositeEventQueue.Empty && InitialAction != null) {
    5868        InitialAction.Execute(Model);
    5969        CallActivities(actionMonitor, InitialAction);
     
    6272      while (!CompositeEventQueue.Empty && Model.CurrentTime < MaximumTime) {
    6373        var @event = CompositeEventQueue.Pop();
     74        if (@event.Time < Model.CurrentTime) continue;
     75        log.AppendLine(@event.Action.GetType().Name);
     76        Model.CurrentTime = @event.Time;
     77
    6478        var nextEvent = CompositeEventQueue.Empty ? null : CompositeEventQueue.Peek();
    6579        var action = @event.Action;
    6680
    6781        action.Execute(Model);
    68         CallActivities(actionMonitor, action);
    6982
    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) {
    7884          foreach (var reporter in Reporters)
    7985            reporter.UpdateReporting(Model, Results);
    8086        }
     87
     88        CallActivities(actionMonitor, action);
     89
    8190        cancellationToken.ThrowIfCancellationRequested();
    8291      };
    8392    }
    8493
    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)])
    88102          activity.ManageEvents(Model, action);
    89103      }
  • branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/Event.cs

    r10450 r10454  
    1111
    1212    #region Storable Properties
    13     [Storable]
    1413    // ReSharper disable UnusedMember.Local
    1514    // ReSharper disable UnusedParameter.Local
     15    [Storable]
    1616    private double StorableTime {
    1717      get { return time; }
  • branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/Interfaces/IAction.cs

    r10450 r10454  
    1 using System;
    2 using HeuristicLab.Common;
     1using HeuristicLab.Common;
    32
    43namespace HeuristicLab.SimulationCore {
    54  public interface IAction<TModel> : IDeepCloneable, IContent where TModel : IModel {
    6     Guid ActionId { get; }
    75    IActivity<TModel> Mandate { get; }
    86
  • branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/Interfaces/IActivity.cs

    r10450 r10454  
    77    where TModel : IModel {
    88    IEventQueue<TModel> EventQueue { get; }
    9     IEnumerable<Guid> MonitoredActionIds { get; }
     9    IEnumerable<Type> MonitoredActions { get; }
    1010
    1111    void ManageEvents(TModel model, IAction<TModel> lastAction);
  • branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/Interfaces/IEventQueue.cs

    r10450 r10454  
    88    IEvent<TModel> Peek();
    99    IEvent<TModel> Pop();
    10     void Push(IEvent<TModel> @event);
     10    void Push(double time, IAction<TModel> action);
    1111
    1212    IEvent<TModel> ChangeTime(IEvent<TModel> @event, double newTime);
  • branches/SimulationCore/HeuristicLab.SimulationCore/3.3/DiscreteEvent/SortedListEventQueue.cs

    r10450 r10454  
    2626    }
    2727
    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;
    3238    }
    3339
    3440    public IEvent<TModel> ChangeTime(IEvent<TModel> @event, double newTime) {
    3541      Remove(@event);
    36       var newEvent = new Event<TModel>(newTime, @event.Action);
    37       Push(newEvent);
    38       return newEvent;
     42      return PushEvent(newTime, @event.Action);
    3943    }
    4044
  • branches/SimulationCore/HeuristicLab.SimulationCore/3.3/HeuristicLab.SimulationCore-3.3.csproj

    r10450 r10454  
    159159    <Compile Include="DiscreteEvent\Event.cs" />
    160160    <Compile Include="DiscreteEvent\Interfaces\IReporter.cs" />
    161     <Compile Include="DiscreteEvent\ModelTimeUpdateAction.cs" />
     161    <Compile Include="DiscreteEvent\Model.cs" />
    162162    <Compile Include="DiscreteEvent\Reporter.cs" />
    163163    <Compile Include="DiscreteEvent\SortedListEventQueue.cs" />
Note: See TracChangeset for help on using the changeset viewer.