3using System.Collections.Generic;
6using System.Threading.Tasks;
8using System.Globalization;
12 public class CEPHandler
21 _ceps =
new Dictionary<string, CEP>();
30 private Dictionary<string, CEP>
_ceps;
31 public Dictionary<string, CEP>
CEPS
42 private Dictionary<string, Dictionary<string, double>>
_fleetShares;
43 public Dictionary<string, Dictionary<string, double>>
FleetShares
62 if (!
Load(DataPath, Helper))
79 List<CEP> weightedCEPS =
new List<CEP>();
83 foreach (
string aggVehClass
in FleetShares[AggClass].Keys)
89 if (!
CEPS.ContainsKey(aggVehClass) && !
Load(DataPath, Helper))
93 weightedCEPS.Add(
CEPS[aggVehClass] *
FleetShares[AggClass][aggVehClass]);
98 Helper.gClass = AggClass;
102 Helper.ErrMsg =
"The aggregated vehicle class (" + AggClass +
") is not available in the FleetShare file!";
108 Helper.ErrMsg =
"The aggregated vehicle class (" + AggClass +
") is a unknown class!";
126 string emissionRep = Helper.
gClass.ToString();
129 List<List<double>> matrixSpeedInertiaTable;
130 List<List<double>> normedTragTableSpeedInertiaTable;
131 List<List<double>> matrixFC;
132 List<List<double>> matrixPollutants;
133 List<double> idlingValuesFC;
134 List<double> idlingValuesPollutants;
135 List<string> headerFC;
136 List<string> headerPollutants;
139 double vehicleLoading;
140 double vehicleMassRot;
141 double crosssectionalArea;
149 List<double> transmissionGearRatios;
152 double engineIdlingSpeed;
153 double engineRatedSpeed;
154 double effectiveWhellDiameter;
155 string vehicleMassType;
156 string vehicleFuelType;
168 out crosssectionalArea,
178 out engineIdlingSpeed,
179 out engineRatedSpeed,
180 out effectiveWhellDiameter,
181 out transmissionGearRatios,
188 out matrixSpeedInertiaTable,
189 out normedTragTableSpeedInertiaTable))
192 if (!
ReadEmissionData(
true, DataPath, emissionRep, Helper, out headerFC, out matrixFC, out idlingValuesFC))
195 if (!
ReadEmissionData(
false, DataPath, emissionRep, Helper, out headerPollutants, out matrixPollutants, out idlingValuesPollutants))
210 transmissionGearRatios,
215 effectiveWhellDiameter,
224 matrixSpeedInertiaTable,
225 normedTragTableSpeedInertiaTable,
226 idlingValuesFC.First(),
227 idlingValuesPollutants));
233 #region ReadVehicleFile
235 string emissionClass,
237 out
double vehicleMass,
238 out
double vehicleLoading,
239 out
double vehicleMassRot,
240 out
double crossArea,
247 out
double axleRatio,
249 out
double ratedPower,
250 out
double engineIdlingSpeed,
251 out
double engineRatedSpeed,
252 out
double effectiveWheelDiameter,
253 out List<double> transmissionGearRatios,
254 out
string vehicleMassType,
255 out
string vehicleFuelType,
260 out List<List<double>> matrixSpeedInertiaTable,
261 out List<List<double>> normedDragTable)
276 engineIdlingSpeed = 0;
277 engineRatedSpeed = 0;
278 effectiveWheelDiameter = 0;
279 vehicleMassType =
"";
280 vehicleFuelType =
"";
285 transmissionGearRatios =
new List<double>();
286 matrixSpeedInertiaTable =
new List<List<double>>();
287 normedDragTable =
new List<List<double>>();
293 string path = DataPath +
@"\" + emissionClass +
".PHEMLight.veh";
294 if (!File.Exists(@path))
296 Helper.ErrMsg =
"File do not exist! (" + path +
")";
299 StreamReader vehicleReader = File.OpenText(@path);
304 while ((line =
ReadLine(vehicleReader)) !=
null && dataCount <= 49)
315 cell =
split(line,
',')[0];
379 effectiveWheelDiameter =
todouble(cell);
381 if (dataCount >= 23 && dataCount <= 40)
382 transmissionGearRatios.Add(
todouble(cell));
386 vehicleMassType = cell;
390 vehicleFuelType = cell;
417 while ((line =
ReadLine(vehicleReader)) !=
null)
425 vehicleReader.Close();
430 #region ReadEmissionData
433 string emissionClass,
435 out List<string> header,
436 out List<List<double>> matrix,
437 out List<double> idlingValues)
441 header =
new List<string>();
442 matrix =
new List<List<double>>();
443 idlingValues =
new List<double>();
445 string pollutantExtension =
"";
447 pollutantExtension +=
"_FC";
449 string path = DataPath +
@"\" + emissionClass + pollutantExtension +
".csv";
450 if (!File.Exists(path))
452 Helper.ErrMsg =
"File do not exist! (" + path +
")";
455 StreamReader fileReader = File.OpenText(@path);
458 if ((line =
ReadLine(fileReader)) !=
null)
460 List<string> entries =
split(line,
',');
462 for (
int i = 1; i < entries.Count; i++)
464 header.Add(entries[i]);
477 List<string> stringIdlings =
split(line,
',').ToList();
478 stringIdlings.RemoveAt(0);
482 while ((line =
ReadLine(fileReader)) !=
null)
492 #region ReadFleetShares
493 public bool ReadFleetShares(
string DataPath, Helpers Helper)
497 string path = DataPath +
@"\FleetShares.csv";
498 if (!File.Exists(@path))
500 Helper.ErrMsg =
"FleetShares file does not exist! (" + path +
")";
503 StreamReader shareReader = File.OpenText(@path);
505 _fleetShares =
new Dictionary<string, Dictionary<string, double>>();
507 while ((line =
ReadLine(shareReader)) !=
null)
509 if (line.Substring(0, 1) == Helper.CommentPrefix)
512 List<string> splitLine =
split(line,
',');
513 string aggregateClass = splitLine[0];
516 FleetShares.Add(aggregateClass,
new Dictionary<string, double>());
518 string subClass = splitLine[1];
520 if (!
FleetShares[aggregateClass].ContainsKey(subClass))
534 private List<string>
split(
string s,
char delim)
536 return s.Split(delim).ToList();
542 return double.Parse(s, CultureInfo.InvariantCulture);
548 return s.Select(p =>
todouble(p)).Cast<
double>().ToList();
552 private string ReadLine(StreamReader s)
std::map< std::string, CEP * > _ceps
std::vector< std::string > split(const std::string &s, char delim)
bool Load(const std::vector< std::string > &DataPath, Helpers *Helper)
Dictionary< string, CEP > CEPS
Dictionary< string, Dictionary< string, double > > _fleetShares
bool ReadVehicleFile(string DataPath, string emissionClass, Helpers Helper, out double vehicleMass, out double vehicleLoading, out double vehicleMassRot, out double crossArea, out double cWValue, out double f0, out double f1, out double f2, out double f3, out double f4, out double axleRatio, out double auxPower, out double ratedPower, out double engineIdlingSpeed, out double engineRatedSpeed, out double effectiveWheelDiameter, out List< double > transmissionGearRatios, out string vehicleMassType, out string vehicleFuelType, out double pNormV0, out double pNormP0, out double pNormV1, out double pNormP1, out List< List< double > > matrixSpeedInertiaTable, out List< List< double > > normedDragTable)
bool GetFleetCEP(string DataPath, string AggClass, Helpers Helper)
bool Load(string DataPath, Helpers Helper)
bool ReadEmissionData(bool readFC, const std::vector< std::string > &DataPath, const std::string &emissionClass, Helpers *Helper, std::vector< std::string > &header, std::vector< std::vector< double > > &matrix, std::vector< double > &idlingValues)
double todouble(const std::string &s)
std::string ReadLine(std::ifstream &s)
Dictionary< string, CEP > _ceps
std::vector< double > todoubleList(const std::vector< std::string > &s)
Dictionary< string, Dictionary< string, double > > FleetShares
bool GetCEP(string DataPath, Helpers Helper)
bool ReadVehicleFile(const std::vector< std::string > &DataPath, const std::string &emissionClass, Helpers *Helper, double &vehicleMass, double &vehicleLoading, double &vehicleMassRot, double &crossArea, double &cWValue, double &f0, double &f1, double &f2, double &f3, double &f4, double &axleRatio, double &auxPower, double &ratedPower, double &engineIdlingSpeed, double &engineRatedSpeed, double &effectiveWheelDiameter, std::vector< double > &transmissionGearRatios, std::string &vehicleMassType, std::string &vehicleFuelType, double &pNormV0, double &pNormP0, double &pNormV1, double &pNormP1, std::vector< std::vector< double > > &matrixSpeedInertiaTable, std::vector< std::vector< double > > &normedDragTable)
static CEP AddRangeCeps(CEP[] cps, Helpers Helper)
static string[] AGGREGATED_VEHICLECLASSES
static const std::string HeavyVehicle
bool setclass(const std::string &VEH)