4 using System.Collections.Generic;
5 using System.Collections.ObjectModel;
25 private string pathToInGPSFile =
"gpsin.txt";
30 private string pathToOutGPSFile =
"gpsout.txt";
35 private List<Record> outputRecords;
40 private List<Record> inputRecords;
45 private Dictionary<int, LocationAndDirection> carPreviousGPSInputLocations =
46 new Dictionary<int, LocationAndDirection>();
50 public ReadOnlyDictionary<int, LocationAndDirection> CarPreviousGPSInputLocations
52 get {
return new ReadOnlyDictionary<int, LocationAndDirection>(carPreviousGPSInputLocations); }
58 private Dictionary<int, LocationAndDirection> carCurrentGPSInputLocations =
59 new Dictionary<int, LocationAndDirection>();
63 public ReadOnlyDictionary<int, LocationAndDirection> CarCurrentGPSInputLocations
65 get {
return new ReadOnlyDictionary<int, LocationAndDirection>(carCurrentGPSInputLocations); }
71 private int gpsInputCarsCounter = 0;
77 private HashSet<int> carsInPreviousStepNotInCurrentStep =
new HashSet<int>();
91 this.carsManager = carsManager;
92 this.cellularTopologyParameters = cellularTopologyParameters;
99 internal void AddOutputRecord(
Record record)
101 outputRecords.Add(record);
108 internal void RecordCarsGPSLocations(TimeSpan currentModelTime)
112 AddOutputRecord(
new Record()
114 Point = frontCellWithCar.Value.Location +
115 new Vector(frontCellWithCar.Key.Outside * cellularTopologyParameters.
P1_CellLength, 0.0),
116 DirectionNormalizedVector = frontCellWithCar.Value.NormalizedDirectionVector,
118 CarHashCode = frontCellWithCar.Key.GetHashCode()
127 internal void ProcessInputGPSRecords(TimeSpan currentModelTime)
130 if (gpsInputCarsCounter < inputRecords.Count)
134 if (gpsInputCarsCounter == 0)
138 for (; gpsInputCarsCounter < inputRecords.Count &&
139 (record = inputRecords[gpsInputCarsCounter]).Time == currentModelTime;
140 gpsInputCarsCounter++)
148 HashSet<int> carsInCurrentStep = null;
151 for (
bool isFirstIteration =
true;
152 gpsInputCarsCounter < inputRecords.Count &&
153 (record = inputRecords[gpsInputCarsCounter]).Time ==
155 gpsInputCarsCounter++, isFirstIteration =
false)
157 if (isFirstIteration)
159 Dictionary<int, LocationAndDirection> helpDictionary = carPreviousGPSInputLocations;
160 carPreviousGPSInputLocations = carCurrentGPSInputLocations;
161 carCurrentGPSInputLocations = helpDictionary;
162 carsInCurrentStep =
new HashSet<int>();
164 if (carCurrentGPSInputLocations.ContainsKey(record.
CarHashCode))
174 carsInPreviousStepNotInCurrentStep.Remove(record.
CarHashCode);
179 foreach (
int carHashCode
in carsInPreviousStepNotInCurrentStep)
181 carCurrentGPSInputLocations.Remove(carHashCode);
185 if (carsInCurrentStep != null)
187 carsInPreviousStepNotInCurrentStep = carsInCurrentStep;
193 carPreviousGPSInputLocations.Clear();
194 carCurrentGPSInputLocations.Clear();
202 internal void ResetGPSInputRecordsInformationAndSaveInputRecords()
204 gpsInputCarsCounter = 0;
205 carPreviousGPSInputLocations.Clear();
206 carCurrentGPSInputLocations.Clear();
207 carsInPreviousStepNotInCurrentStep.Clear();
208 using (StreamWriter sw =
new FileDataStore(pathToOutGPSFile).GetStreamWriter())
210 foreach (
Record record
in outputRecords)
212 sw.WriteLine(
string.Format(CultureInfo.InvariantCulture,
"{0} {1} {2} {3}", record.
Point,
222 internal void LoadInputRecordsAndInitializeOutputRecords()
224 outputRecords =
new List<Record>();
225 inputRecords =
new List<Record>();
226 foreach (
string[] lineItems
in new FileLineDataLoader(pathToInGPSFile).GetLinesWithData())
228 inputRecords.Add(
new Record()
230 Point = Point.Parse(lineItems[0]),
231 DirectionNormalizedVector = Vector.Parse(lineItems[1]),
232 Time = TimeSpan.Parse(lineItems[2]),
233 CarHashCode =
int.Parse(lineItems[3])
Point Point
Car's location.
int CarHashCode
Car's hash code.
TimeSpan P2_SimulationStepInterval
Cell length parameter.
Manages GPS records for cellular topology.
TimeSpan Time
Time of the record.
Represents tuple containing location and normalized direction vector.
Class for loading lines of data from text file.
Class containing parameters related to cellular topology.
double P1_CellLength
Cell length parameter.
Class for storing line data to text files.
Vector DirectionNormalizedVector
Car's normalized direction vector.
Structure representing car's location in time.
ReadOnlyDictionary< Car, Cell > CellsWithCarInCurrentStep
Read only dictionary containing all cars with their first cells which they occupied after last transi...
Manages cars in cellular topology.