Skip to content

Commit

Permalink
dynamic stationfinder device parameters ref #15622
Browse files Browse the repository at this point in the history
Signed-off-by: m-kro <m.barthauer@t-online.de>
  • Loading branch information
m-kro committed Oct 22, 2024
1 parent f23f7eb commit fa10582
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/microsim/devices/MSDevice_StationFinder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,13 @@ MSDevice_StationFinder::saveState(OutputDevice& out) const {
std::vector<std::string> internals;
internals.push_back(toString(myLastChargeCheck));
internals.push_back(toString(myUpdateSoC));
internals.push_back(toString(mySearchSoC));
internals.push_back(toString(myTargetSoC));
internals.push_back(toString(myWaitForCharge));
internals.push_back(toString(myRepeatInterval));
internals.push_back(toString(myRadius));
internals.push_back(toString(myLastSearch));
internals.push_back(toString(myReserveFactor));
internals.push_back(toString(mySearchState));
internals.push_back(toString(myArrivalAtChargingStation));
internals.push_back((myChargingStation == nullptr) ? "NULL" : myChargingStation->getID());
Expand All @@ -308,7 +314,13 @@ MSDevice_StationFinder::loadState(const SUMOSAXAttributes& attrs) {
std::istringstream bis(attrs.getString(SUMO_ATTR_STATE));
bis >> myLastChargeCheck;
bis >> myUpdateSoC;
bis >> mySearchSoC;
bis >> myTargetSoC;
bis >> myWaitForCharge;
bis >> myRepeatInterval;
bis >> myRadius;
bis >> myLastSearch;
bis >> myReserveFactor;
int searchState;
bis >> searchState;
mySearchState = (SearchState)searchState;
Expand Down Expand Up @@ -660,11 +672,49 @@ MSDevice_StationFinder::getParameter(const std::string& key) const {
return (myChargingStation == nullptr) ? "" : myChargingStation->getID();
} else if (key == "batteryNeed") {
return toString(estimateConsumption() * myReserveFactor);
} else if (key == "needToChargeLevel") {
return toString(myRadius);
} else if (key == "saturatedChargeLevel") {
return toString(myRadius);
} else if (key == "waitForCharge") {
return toString(myRadius);
} else if (key == "repeat") {
return toString(myRadius);
} else if (key == "radius") {
return toString(myRadius);
} else if (key == "reserveFactor") {
return toString(myRadius);
}
throw InvalidArgument(TLF("Parameter '%' is not supported for device of type '%'", key, deviceName()));
}


void
MSDevice_StationFinder::setParameter(const std::string& key, const std::string& value) {
double doubleValue;
try {
doubleValue = StringUtils::toDouble(value);
} catch (NumberFormatException&) {
throw InvalidArgument(TLF("Setting parameter '%' requires a number for device of type '%'", key, deviceName()));
}
if (key == "needToChargeLevel") {
mySearchSoC = MAX2(0., MIN2(1., doubleValue));
} else if (key == "saturatedChargeLevel") {
myTargetSoC = MAX2(0., MIN2(1., doubleValue));
} else if (key == "waitForCharge") {
myWaitForCharge = TIME2STEPS(MAX2(0., doubleValue));
} else if (key == "repeat") {
myRepeatInterval = TIME2STEPS(MAX2(0., doubleValue));
} else if (key == "radius") {
myRadius = MAX2(0., doubleValue);
} else if (key == "reserveFactor") {
myReserveFactor = MAX2(1., doubleValue);
} else {
throw InvalidArgument(TLF("Setting parameter '%' is not supported for device of type '%'", key, deviceName()));
}
}


bool
MSDevice_StationFinder::evaluateCustomComponents(SUMOVehicle& /* veh */, double /* brakeGap */, bool /* newDestination */,
MSStoppingPlace* alternative, double /* occupancy */, double /* prob */,
Expand Down
3 changes: 3 additions & 0 deletions src/microsim/devices/MSDevice_StationFinder.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,9 @@ class MSDevice_StationFinder : public MSVehicleDevice, MSStoppingPlaceRerouter {

std::string getParameter(const std::string& key) const override;

/// @brief try to set the given parameter for this device. Throw exception for unsupported key
void setParameter(const std::string& key, const std::string& value);

/** @brief Compute some custom target function components
*
* @param[in] veh the concerned vehicle
Expand Down

0 comments on commit fa10582

Please sign in to comment.