33 CEP::CEP(
VEHPHEMLightJSON::VEH*
Vehicle, std::vector<std::string>& headerLineFCvalues, std::vector<std::vector<double> >& matrixFCvalues, std::vector<std::string>& headerLinePollutants, std::vector<std::vector<double> >& matrixPollutants, std::vector<double>& idlingFCvalues, std::vector<double>& idlingPollutants) {
80 std::vector<std::string> FCvaluesIdentifier;
81 std::vector<std::vector<double> > normalizedFCvaluesMeasures;
82 for (
int i = 0; i < (int)headerLineFCvalues.size(); i++) {
83 FCvaluesIdentifier.push_back(headerLineFCvalues[i]);
84 normalizedFCvaluesMeasures.push_back(std::vector<double>());
88 std::vector<std::string> pollutantIdentifier;
89 std::vector<std::vector<double> > normalizedPollutantMeasures;
90 for (
int i = 0; i < (int)headerLinePollutants.size(); i++) {
91 pollutantIdentifier.push_back(headerLinePollutants[i]);
92 normalizedPollutantMeasures.push_back(std::vector<double>());
97 for (
int i = 0; i < (int)
Vehicle->getTransmissionData()->getTransm()[
"Speed"].size(); i++) {
111 int headerFCCount = (int)headerLineFCvalues.size();
112 for (
int i = 0; i < (int)matrixFCvalues.size(); i++) {
113 for (
int j = 0; j < (int)matrixFCvalues[i].size(); j++) {
114 if ((
int)matrixFCvalues[i].size() != headerFCCount + 1) {
122 normalizedFCvaluesMeasures[j - 1].push_back(matrixFCvalues[i][j]);
130 for (
int i = 0; i < (int)headerLineFCvalues.size(); i++) {
138 int headerCount = (int)headerLinePollutants.size();
139 for (
int i = 0; i < (int)matrixPollutants.size(); i++) {
140 for (
int j = 0; j < (int)matrixPollutants[i].size(); j++) {
141 if ((
int)matrixPollutants[i].size() != headerCount + 1) {
149 normalizedPollutantMeasures[j - 1].push_back(matrixPollutants[i][j]);
156 for (
int i = 0; i < (int)headerLinePollutants.size(); i++) {
161 _FleetMix = std::map<std::string, double>();
207 double CEP::GetEmission(
const std::string& pollutant,
double power,
double speed,
Helpers* VehicleClass,
const double drivingPower,
const double ratedPower) {
209 std::vector<double>* emissionCurve =
nullptr;
210 std::vector<double>* powerPattern =
nullptr;
219 VehicleClass->
setErrMsg(std::string(
"Emission pollutant or fuel value ") + pollutant + std::string(
" not found!"));
233 VehicleClass->
setErrMsg(std::string(
"Emission pollutant or fuel value ") + pollutant + std::string(
" not found!"));
237 double normalizingPower = ratedPower;
241 emissionMultiplier = ratedPower;
247 normalizingPower = drivingPower;
251 if (emissionCurve ==
nullptr || emissionCurve->empty()) {
252 VehicleClass->
setErrMsg(std::string(
"Empty emission curve for ") + pollutant + std::string(
" found!"));
255 if (emissionCurve->size() == 1) {
256 return emissionCurve->front() * emissionMultiplier;
260 if (power <= powerPattern->front() * normalizingPower) {
261 return emissionCurve->front() * emissionMultiplier;
265 if (power >= powerPattern->back() * normalizingPower) {
266 return emissionCurve->back() * emissionMultiplier;
270 return Interpolate(power, (*powerPattern)[lowerIndex] * normalizingPower, (*powerPattern)[upperIndex] * normalizingPower, (*emissionCurve)[lowerIndex], (*emissionCurve)[upperIndex]) * emissionMultiplier;
403 if (value <= pattern.front() * scale) {
409 if (value >= pattern.back() * scale) {
410 lowerIndex = (int)pattern.size() - 1;
411 upperIndex = (int)pattern.size() - 1;
416 int middleIndex = ((int)pattern.size() - 1) / 2;
417 upperIndex = (int)pattern.size() - 1;
420 while (upperIndex - lowerIndex > 1) {
421 if (pattern[middleIndex] * scale == value) {
422 lowerIndex = middleIndex;
423 upperIndex = middleIndex;
426 else if (pattern[middleIndex] * scale < value) {
427 lowerIndex = middleIndex;
428 middleIndex = (upperIndex - lowerIndex) / 2 + lowerIndex;
431 upperIndex = middleIndex;
432 middleIndex = (upperIndex - lowerIndex) / 2 + lowerIndex;