4 using System.Collections.Generic;
20 private List<Record> inputRecords;
26 private List<Record> outputRecords;
31 private string pathToInputRecords;
36 private string pathToOutputRecords;
41 private int actionToGetTimeTo;
46 private int actionToPerform;
57 set { cellularTopologyParameters = value; }
65 public Sensor(
string pathToInputRecords,
string pathToOutputRecords)
67 this.pathToInputRecords = pathToInputRecords;
68 this.pathToOutputRecords = pathToOutputRecords;
74 internal void LoadInputRecords()
76 inputRecords =
new List<Record>();
77 outputRecords =
new List<Record>();
78 actionToGetTimeTo = 0;
80 foreach (
string[] lineItems
in new FileLineDataLoader(pathToInputRecords).GetLinesWithData())
82 inputRecords.Add(
new Record()
84 Time = TimeSpan.Parse(lineItems[0]),
85 Speed =
double.Parse(lineItems[1])
93 internal void SaveInputRecords()
95 using (StreamWriter sw =
new FileDataStore(pathToOutputRecords).GetStreamWriter())
97 foreach (Record record
in outputRecords)
99 sw.WriteLine(
string.Format(CultureInfo.InvariantCulture,
"{0} {1}", record.Time, record.Speed));
111 if (actionToGetTimeTo == inputRecords.Count)
113 return TimeSpan.MaxValue;
115 else if (actionToGetTimeTo == 0)
117 return inputRecords[actionToGetTimeTo++].Time;
121 return inputRecords[actionToGetTimeTo].Time - inputRecords[actionToGetTimeTo++ - 1].Time;
131 GenerateTicket(cellularTopologyParameters.FromKphSpeedToSimSpeed(inputRecords[actionToPerform++].Speed));
139 internal void AddOutputRecord(TimeSpan time,
int speed)
141 outputRecords.Add(
new Record()
144 Speed = cellularTopologyParameters.FromSimSpeedToKphSpeed(speed)
CellularTopologyParameters cellularTopologyParameters
Reference to simulation parameters.
override void PerformAction(Random random)
Generate new ticket from input records.
Represents generator of cars.
Class representing sensor.
Class for loading lines of data from text file.
override TimeSpan GetTimeToNextAction(Random random)
Returns time to generation of new ticket by getting time to the next input record.
Class containing parameters related to cellular topology.
Class for storing line data to text files.
Sensor(string pathToInputRecords, string pathToOutputRecords)
Initialize sensor with paths to files with input and output records.