35 _ceps = std::map<std::string, CEP*>();
44 if (!
Load(DataPath, Helper)) {
55 std::string emissionRep = Helper->
getgClass();
58 std::vector<std::vector<double> > matrixSpeedInertiaTable;
59 std::vector<std::vector<double> > normedTragTableSpeedInertiaTable;
60 std::vector<std::vector<double> > matrixFC;
61 std::vector<std::vector<double> > matrixPollutants;
62 std::vector<double> idlingValuesFC;
63 std::vector<double> idlingValuesPollutants;
64 std::vector<std::string> headerFC;
65 std::vector<std::string> headerPollutants;
68 double vehicleLoading;
69 double vehicleMassRot;
70 double crosssectionalArea;
78 std::vector<double> transmissionGearRatios;
81 double engineIdlingSpeed;
82 double engineRatedSpeed;
83 double effectiveWhellDiameter;
84 std::string vehicleMassType;
85 std::string vehicleFuelType;
91 if (!
ReadVehicleFile(DataPath, emissionRep, Helper, vehicleMass, vehicleLoading, vehicleMassRot, crosssectionalArea, cwValue, f0, f1, f2, f3, f4, axleRatio, auxPower, ratedPower, engineIdlingSpeed, engineRatedSpeed, effectiveWhellDiameter, transmissionGearRatios, vehicleMassType, vehicleFuelType, pNormV0, pNormP0, pNormV1, pNormP1, matrixSpeedInertiaTable, normedTragTableSpeedInertiaTable)) {
95 if (!
ReadEmissionData(
true, DataPath, emissionRep, Helper, headerFC, matrixFC, idlingValuesFC)) {
99 if (!
ReadEmissionData(
false, DataPath, emissionRep, Helper, headerPollutants, matrixPollutants, idlingValuesPollutants)) {
103 _ceps.insert(std::make_pair(Helper->
getgClass(),
new CEP(vehicleMassType ==
Constants::HeavyVehicle, vehicleMass, vehicleLoading, vehicleMassRot, crosssectionalArea, cwValue, f0, f1, f2, f3, f4, axleRatio, transmissionGearRatios, auxPower, ratedPower, engineIdlingSpeed, engineRatedSpeed, effectiveWhellDiameter, pNormV0, pNormP0, pNormV1, pNormP1, vehicleFuelType, matrixFC, headerPollutants, matrixPollutants, matrixSpeedInertiaTable, normedTragTableSpeedInertiaTable, idlingValuesFC.front(), idlingValuesPollutants)));
108 bool CEPHandler::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) {
122 engineIdlingSpeed = 0;
123 engineRatedSpeed = 0;
124 effectiveWheelDiameter = 0;
125 vehicleMassType =
"";
126 vehicleFuelType =
"";
131 transmissionGearRatios = std::vector<double>();
132 matrixSpeedInertiaTable = std::vector<std::vector<double> >();
133 normedDragTable = std::vector<std::vector<double> >();
139 std::ifstream vehicleReader;
140 for (std::vector<std::string>::const_iterator i = DataPath.begin(); i != DataPath.end(); i++) {
141 vehicleReader.open(((*i) + emissionClass +
".PHEMLight.veh").c_str());
142 if (vehicleReader.good()) {
146 if (!vehicleReader.good()) {
147 Helper->
setErrMsg(
"File does not exist! (" + emissionClass +
".PHEMLight.veh)");
154 while ((line =
ReadLine(vehicleReader)) !=
"" && dataCount <= 49) {
162 cell =
split(line,
',')[0];
165 if (dataCount == 1) {
170 if (dataCount == 2) {
175 if (dataCount == 3) {
180 if (dataCount == 4) {
185 if (dataCount == 7) {
190 if (dataCount == 9) {
195 if (dataCount == 10) {
200 if (dataCount == 11) {
205 if (dataCount == 12) {
210 if (dataCount == 14) {
215 if (dataCount == 15) {
220 if (dataCount == 16) {
225 if (dataCount == 17) {
230 if (dataCount == 18) {
235 if (dataCount == 21) {
240 if (dataCount == 22) {
241 effectiveWheelDiameter =
todouble(cell);
244 if (dataCount >= 23 && dataCount <= 40) {
245 transmissionGearRatios.push_back(
todouble(cell));
249 if (dataCount == 45) {
250 vehicleMassType = cell;
254 if (dataCount == 46) {
255 vehicleFuelType = cell;
259 if (dataCount == 47) {
264 if (dataCount == 48) {
269 if (dataCount == 49) {
274 if (dataCount == 50) {
287 while ((line =
ReadLine(vehicleReader)) !=
"") {
298 bool CEPHandler::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) {
301 header = std::vector<std::string>();
302 matrix = std::vector<std::vector<double> >();
303 idlingValues = std::vector<double>();
305 std::string pollutantExtension =
"";
307 pollutantExtension += std::string(
"_FC");
310 std::ifstream fileReader;
311 for (std::vector<std::string>::const_iterator i = DataPath.begin(); i != DataPath.end(); i++) {
312 fileReader.open(((*i) + emissionClass + pollutantExtension +
".csv").c_str());
313 if (fileReader.good()) {
317 if (!fileReader.good()) {
318 Helper->
setErrMsg(
"File does not exist! (" + emissionClass + pollutantExtension +
".csv)");
323 if ((line =
ReadLine(fileReader)) !=
"") {
324 std::vector<std::string> entries =
split(line,
',');
326 for (
int i = 1; i < (int)entries.size(); i++) {
327 header.push_back(entries[i]);
340 std::vector<std::string> stringIdlings =
split(line,
',');
341 stringIdlings.erase(stringIdlings.begin());
345 while ((line =
ReadLine(fileReader)) !=
"") {
352 std::vector<std::string> elems;
353 std::stringstream ss(s);
355 while (std::getline(ss, item, delim)) {
356 elems.push_back(item);
362 std::stringstream ss(s);
369 std::vector<double> result;
370 for (std::vector<std::string>::const_iterator i = s.begin(); i != s.end(); ++i) {
378 std::getline(s, line);
379 line.erase(line.find_last_not_of(
" \n\r\t") + 1);
std::vector< double > todoubleList(const std::vector< std::string > &s)
std::map< std::string, CEP * > _ceps
void setErrMsg(const std::string &value)
const std::string & getCommentPrefix() const
C++ TraCI client API implementation.
bool Load(const std::vector< std::string > &DataPath, Helpers *Helper)
static const std::string HeavyVehicle
std::string ReadLine(std::ifstream &s)
bool GetCEP(const std::vector< std::string > &DataPath, Helpers *Helper)
double todouble(const std::string &s)
std::vector< std::string > split(const std::string &s, char delim)
const std::map< std::string, CEP * > & getCEPS() const
const std::string & getgClass() const
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)
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)