Skip to content

Commit

Permalink
can now parse custom value tables. refs #14258
Browse files Browse the repository at this point in the history
  • Loading branch information
namdre committed Feb 26, 2024
1 parent c2fe22d commit 79a7a5c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
33 changes: 33 additions & 0 deletions src/microsim/cfmodels/MSCFModel_Rail.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@

#include <iostream>
#include <utils/common/MsgHandler.h>
#include <utils/common/StringUtils.h>
#include <utils/common/StringTokenizer.h>
#include <utils/geom/GeomHelper.h>
#include <microsim/MSVehicle.h>
#include <microsim/lcmodels/MSAbstractLaneChangeModel.h>
Expand Down Expand Up @@ -72,10 +74,41 @@ MSCFModel_Rail::MSCFModel_Rail(const MSVehicleType* vtype) :
const_cast<MSVehicleType*>(vtype)->setMaxSpeed(myTrainParams.vmax);
const_cast<MSVehicleType*>(vtype)->setLength(myTrainParams.length);

// init curves
std::vector<double> speedTable = getValueTable(vtype, SUMO_ATTR_SPEED_TABLE);
std::vector<double> tractionTable = getValueTable(vtype, SUMO_ATTR_TRACTION_TABLE);
std::vector<double> resistanceTable = getValueTable(vtype, SUMO_ATTR_RESISTANCE_TABLE);
if (speedTable.size() > 0) {
if (speedTable.size() != tractionTable.size()) {
throw ProcessError(TLF("Mismatching size of speedTable and tractionTable for vType '%'.", vtype->getID()));
} else if (speedTable.size() != resistanceTable.size()) {
throw ProcessError(TLF("Mismatching size of speedTable and resistanceTable for vType '%'.", vtype->getID()));
}
myTrainParams.traction.clear();
myTrainParams.resistance.clear();
for (int i = 0; i < (int)speedTable.size(); i++) {
myTrainParams.traction[speedTable[i]] = tractionTable[i];
myTrainParams.resistance[speedTable[i]] = resistanceTable[i];
}
}
}

MSCFModel_Rail::~MSCFModel_Rail() { }


std::vector<double>
MSCFModel_Rail::getValueTable(const MSVehicleType* vtype, SumoXMLAttr attr) {
std::vector<double> result;
const std::string values = vtype->getParameter().getCFParamString(attr, "");
if (!values.empty()) {
for (std::string value : StringTokenizer(values).getVector()) {
result.push_back(StringUtils::toDouble(value));
}
}
return result;
}


double MSCFModel_Rail::followSpeed(const MSVehicle* const veh, double speed, double gap,
double /* predSpeed */, double /* predMaxDecel*/, const MSVehicle* const /*pred*/, const CalcReason /*usage*/) const {

Expand Down
2 changes: 2 additions & 0 deletions src/microsim/cfmodels/MSCFModel_Rail.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ class MSCFModel_Rail : public MSCFModel {

double getInterpolatedValueFromLookUpMap(double speed, const LookUpMap* lookUpMap) const;

std::vector<double> getValueTable(const MSVehicleType* vtype, SumoXMLAttr attr);


public:
double stopSpeed(const MSVehicle* const veh, const double speed, double gap, double decel, const CalcReason usage = CalcReason::CURRENT) const;
Expand Down
5 changes: 5 additions & 0 deletions src/utils/vehicle/SUMOVehicleParserHelper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1215,6 +1215,8 @@ SUMOVehicleParserHelper::parseCFMParams(SUMOVTypeParameter* into, const SumoXMLT
}
// add parsedCFMAttribute to cfParameter
into->cfParameter[it] = parsedCFMAttribute;
} else if (it == SUMO_ATTR_SPEED_TABLE || it == SUMO_ATTR_TRACTION_TABLE || it == SUMO_ATTR_RESISTANCE_TABLE) {
into->cfParameter[it] = parsedCFMAttribute;
} else if (it == SUMO_ATTR_CF_IDM_STEPPING) {
// declare a int in wich save CFM int attribute
double CFMDoubleAttribute = -1;
Expand Down Expand Up @@ -1395,6 +1397,9 @@ SUMOVehicleParserHelper::getAllowedCFModelAttrs() {
// Rail
std::set<SumoXMLAttr> railParams(genericParams);
railParams.insert(SUMO_ATTR_TRAIN_TYPE);
railParams.insert(SUMO_ATTR_SPEED_TABLE);
railParams.insert(SUMO_ATTR_TRACTION_TABLE);
railParams.insert(SUMO_ATTR_RESISTANCE_TABLE);
allowedCFModelAttrs[SUMO_TAG_CF_RAIL] = railParams;
allParams.insert(railParams.begin(), railParams.end());
// ACC
Expand Down
5 changes: 4 additions & 1 deletion src/utils/xml/SUMOXMLDefinitions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -644,7 +644,10 @@ StringBijection<int>::Entry SUMOXMLDefinitions::attrs[] = {
{ "speedControlMinGap", SUMO_ATTR_SC_MIN_GAP },
{ "applyDriverState", SUMO_ATTR_APPLYDRIVERSTATE },

{ "trainType", SUMO_ATTR_TRAIN_TYPE },
{ "trainType", SUMO_ATTR_TRAIN_TYPE },
{ "speedTable", SUMO_ATTR_SPEED_TABLE },
{ "tractionTable", SUMO_ATTR_TRACTION_TABLE },
{ "resistanceTable", SUMO_ATTR_RESISTANCE_TABLE },

{ "lcStrategic", SUMO_ATTR_LCA_STRATEGIC_PARAM },
{ "lcCooperative", SUMO_ATTR_LCA_COOPERATIVE_PARAM },
Expand Down
3 changes: 3 additions & 0 deletions src/utils/xml/SUMOXMLDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,9 @@ enum SumoXMLAttr {
/// @name Train model attributes
/// @{
SUMO_ATTR_TRAIN_TYPE, //used by: Rail
SUMO_ATTR_SPEED_TABLE, // list of speeds for traction and resistance value tables
SUMO_ATTR_TRACTION_TABLE, // list of traction values for the speeds table
SUMO_ATTR_RESISTANCE_TABLE, // list of resistance values for the speeds table
/// @}

/// @name Lane changing model attributes
Expand Down

0 comments on commit 79a7a5c

Please sign in to comment.