8 using System.Collections.Generic;
57 private bool firstSimulationStepPerformed;
63 private Mutex carsDictionariesMutex =
new Mutex();
68 public Mutex CarsDictionariesMutex {
get {
return carsDictionariesMutex; } }
73 private ulong simulationSteps = 0;
77 public ulong SimulationSteps {
get {
return simulationSteps; } }
82 private ulong simulationStepsToPause = ulong.MaxValue;
86 public ulong SimulationStepsToPause
88 get {
return simulationStepsToPause; }
89 set { simulationStepsToPause = value; }
95 private bool IsSimulationStepsToPauseReached
97 get {
return simulationSteps >= simulationStepsToPause; }
113 private const int CellularTopologySimulationPriority = 1;
118 public int Priority {
get {
return CellularTopologySimulationPriority; } }
123 public bool IsPauseScheduled {
get {
return IsSimulationStepsToPauseReached; } }
142 this.parameters = parameters;
147 InitializeSimulation(geometricTopology);
169 firstSimulationStepPerformed =
false;
170 List<ISimulationEventsGenerator> simulationEventsGenerators =
new List<ISimulationEventsGenerator>();
171 simulationEventsGenerators.Add(
this);
172 foreach (
Lane lane
in geometricTopology.
Lanes)
176 generatorsManager.InitializeGeneratorForSimulation(
184 generatorsManager.InitializeGeneratorForSimulation(sensor, simulationEventsGenerators);
189 simulation =
new Simulation(simulationEventsGenerators);
199 if (firstSimulationStepPerformed)
205 firstSimulationStepPerformed =
true;
206 return TimeSpan.Zero;
218 DateTime dateTimeNow = DateTime.Now;
220 carsDictionariesMutex.WaitOne();
222 OnNextTransitionFunctionStarted(dateTimeNow);
224 carsManager.SwapCarsPreviousAndCurrentDictionaries();
225 carsManager.ProcessCarsOutsideOfTopology();
227 carsManager.PerformTransitionForAllCars(random, simulation.
CurrentModelTime);
231 carsDictionariesMutex.ReleaseMutex();
233 carsManager.PrepareCarsForNextSimulationStep();
238 OnSimulationStepsChanged();
244 private void OnSimulationStepsChanged()
246 if (SimulationStepsChanged != null)
248 SimulationStepsChanged(
this, EventArgs.Empty);
255 private void ResetSimulationStepsToPause()
257 simulationStepsToPause = ulong.MaxValue;
264 private void ResetSimulationStepsToPauseIfReached()
266 if (IsSimulationStepsToPauseReached)
268 ResetSimulationStepsToPause();
275 private void RunOrStep()
277 ResetSimulationStepsToPauseIfReached();
280 generatorsManager.InitializeGenerators();
281 gpsRecordsManager.LoadInputRecordsAndInitializeOutputRecords();
289 public void Run(
int? seed = null)
292 simulation.Run(seed);
302 simulation.StepForward(seed);
312 firstSimulationStepPerformed =
false;
313 OnSimulationStepsChanged();
314 ResetSimulationStepsToPause();
315 carsManager.ClearCars();
316 generatorsManager.FinalizeGeneratorsWork();
317 gpsRecordsManager.ResetGPSInputRecordsInformationAndSaveInputRecords();
332 private void OnNextTransitionFunctionStarted(DateTime dateTimeEventArg)
334 if (NextTransitionFunctionStarted != null)
335 NextTransitionFunctionStarted(
this,
new DateTimeEventArgs() { DateTime = dateTimeEventArg });
342 protected virtual void Dispose(
bool disposing)
346 if (carsDictionariesMutex != null)
348 carsDictionariesMutex.Dispose();
349 carsDictionariesMutex = null;
351 if (simulation != null)
365 GC.SuppressFinalize(
this);
Class representing geometric topology of road network.
Class containing all simulator parameters.
void Run(int?seed=null)
Runs simulation. Seed to be used in the simulation.
TimeSpan P2_SimulationStepInterval
Cell length parameter.
Manages GPS records for cellular topology.
StartNode StartNode
Node on the input end of lane.
EventHandler< DateTimeEventArgs > NextTransitionFunctionStarted
Event informing that next transition function already started.
void Pause()
Pauses simulation.
Class representing sensor.
Class representing event arguments consisting of property containing time information.
CellularTopologyParameters CellularTopologyParameters
Reference to cellular topology parameters.
EventHandler SimulationStepsChanged
Event handler of change of number of simulation steps.
SimulationState
Current state of the simulation.
CellularTopology(GeometricTopology geometricTopology, Parameters parameters)
Constructor when the cellular topology is build and simulation is initialized.
Class for building cellular topology from geometric topology.
TimeSpan CurrentModelTime
Model time of last tick of simulation timer or last change of simulation run.
TimeSpan GetTimeToNextAction(Random random)
Method for getting the time to performing the next transition function.
Class containing parameters related to cellular topology.
Generator Generator
Generator connected to node.
ReadOnlyCollection< Lane > Lanes
Lanes in geometric topology. </summary
SimulationState SimulationState
Current simulation status of simulation.
Node on the lane which is not the start or end node.
void StepForward(int?seed=null)
Perform step in simulation. Seed to be used in the simulation.
TransitionFunctionParameters TransitionFunctionParameters
Reference to transition function parameters.
void PerformAction(Random random)
Method for performing transition function.
ReadOnlyCollection< InnerNode > InnerNodes
Inner nodes on the lane.
Class representing cellular topology.
Manages generators and sensors in topology.
void Stop()
Stops simulation.
Class controlling performing simulation actions by simulation calendar.
virtual void Dispose(bool disposing)
Dispose disposable fields.
void Dispose()
Disposes cellular topology resources.
Every class which performs some repeating action should implement this interface
Manages cars in cellular topology.
virtual void Dispose(bool disposing)
Dispose disposable fields.
bool ContainsGenerator
Determines whether the node contains generator.