Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
MSStoppingPlaceRerouter.h
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2001-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
18// The MSStoppingPlaceRerouter provides an interface to structure the rerouting
19// to the best StoppingPlace according to the evaluation components and
20// associated weights.
21/****************************************************************************/
22#pragma once
23#include <config.h>
24#include <map>
25#include <functional>
27#include <utils/common/Named.h>
31#include <microsim/MSNet.h>
33
34class MSEdge;
35
44
45
47public:
49 typedef std::map<const MSStoppingPlace*, StoppingPlaceMemoryEntry, ComparatorIdLess> StoppingPlaceMap;
50
53
54 // Destructor
56
62 auto it = myMap.find(id);
63 if (it == myMap.end()) {
64 return false;
65 } else {
66 myMap.erase(it);
67 return true;
68 }
69 }
70
72 void clear() {
73 myMap.clear();
74 }
75
77 int size() const {
78 return (int)myMap.size();
79 }
80
82 void rememberBlockedStoppingPlace(const MSStoppingPlace* stoppingPlace, bool local) {
83 myMap[stoppingPlace].blockedAtTime = SIMSTEP;
84 if (local) {
85 myMap[stoppingPlace].blockedAtTimeLocal = SIMSTEP;
86 }
87 }
88
90 SUMOTime sawBlockedStoppingPlace(const MSStoppingPlace* stoppingPlace, bool local) const {
91 auto it = myMap.find(stoppingPlace);
92 if (it == myMap.end()) {
93 return -1;
94 } else {
95 return local ? it->second.blockedAtTimeLocal : it->second.blockedAtTime;
96 }
97 }
98
100 void rememberStoppingPlaceScore(const MSStoppingPlace* stoppingPlace, const std::string& score) {
101 myMap[stoppingPlace].score = score;
102 }
103
105 for (auto& item : myMap) {
106 item.second.score = "";
107 }
108 }
109
111 typename StoppingPlaceMap::const_iterator begin() const {
112 return myMap.begin();
113 }
114
116 typename StoppingPlaceMap::const_iterator end() const {
117 return myMap.end();
118 }
119
120private:
123
124};
125
126
128public:
129 typedef std::map<std::string, double> StoppingPlaceParamMap_t;
130 typedef std::map<std::string, bool> StoppingPlaceParamSwitchMap_t;
131 typedef std::map<MSStoppingPlace*, StoppingPlaceParamMap_t, ComparatorIdLess> StoppingPlaceMap_t;
132 typedef std::pair<MSStoppingPlace*, bool> StoppingPlaceVisible;
133
135 MSStoppingPlaceRerouter(SumoXMLTag stoppingType, std::string paramPrefix = "", bool checkValidity = false, bool checkVisibility = true, StoppingPlaceParamMap_t addEvalParams = {}, StoppingPlaceParamSwitchMap_t addInvertParams = {});
136
137 // Destructor
139
151 MSStoppingPlace* reroute(std::vector<StoppingPlaceVisible>& stoppingPlaceCandidates, const std::vector<double>& probs, SUMOVehicle& veh,
152 bool& newDestination, ConstMSEdgeVector& newRoute, StoppingPlaceParamMap_t& scores, const MSEdgeVector& closedEdges = {});
169 virtual bool evaluateDestination(SUMOVehicle& veh, double brakeGap, bool newDestination,
170 MSStoppingPlace* alternative, double occupancy, double prob,
172 std::map<MSStoppingPlace*, ConstMSEdgeVector>& newRoutes,
173 std::map<MSStoppingPlace*, ConstMSEdgeVector>& stoppingPlaceApproaches,
174 StoppingPlaceParamMap_t& maxValues,
175 StoppingPlaceParamMap_t& addInput);
176
192 virtual bool evaluateCustomComponents(SUMOVehicle& veh, double brakeGap, bool newDestination,
193 MSStoppingPlace* alternative, double occupancy, double prob,
195 ConstMSEdgeVector& newRoute,
196 ConstMSEdgeVector& stoppingPlaceApproach,
197 StoppingPlaceParamMap_t& maxValues,
198 StoppingPlaceParamMap_t& addInput);
199
201 virtual bool validComponentValues(StoppingPlaceParamMap_t& stoppingPlaceValues);
202
204 virtual bool useStoppingPlace(MSStoppingPlace* stoppingPlace);
205
207 virtual SUMOAbstractRouter<MSEdge, SUMOVehicle>& getRouter(SUMOVehicle& veh, const MSEdgeVector& prohibited = {});
208
210 virtual double getStoppingPlaceOccupancy(MSStoppingPlace* stoppingPlace) = 0;
211
213 virtual double getLastStepStoppingPlaceOccupancy(MSStoppingPlace* stoppingPlace) = 0;
214
216 virtual double getStoppingPlaceCapacity(MSStoppingPlace* stoppingPlace) = 0;
217
219 virtual void rememberBlockedStoppingPlace(SUMOVehicle& veh, const MSStoppingPlace* stoppingPlace, bool blocked) = 0;
220
222 virtual void rememberStoppingPlaceScore(SUMOVehicle& veh, MSStoppingPlace* place, const std::string& score) = 0;
223
225 virtual void resetStoppingPlaceScores(SUMOVehicle& veh) = 0;
226
228 virtual SUMOTime sawBlockedStoppingPlace(SUMOVehicle& veh, MSStoppingPlace* place, bool local) = 0;
229
232
234 virtual void setNumberStoppingPlaceReroutes(SUMOVehicle& veh, int value) = 0;
235
238
247 double getWeight(SUMOVehicle& veh, const std::string param, const double defaultWeight, const bool warn = false);
248
254 static void updateMaxValues(StoppingPlaceParamMap_t& stoppingPlaceValues, StoppingPlaceParamMap_t& maxValues);
255
265 static double getTargetValue(const StoppingPlaceParamMap_t& absValues, const StoppingPlaceParamMap_t& maxValues, const StoppingPlaceParamMap_t& weights, const StoppingPlaceParamSwitchMap_t& norm, const StoppingPlaceParamSwitchMap_t& invert);
266
267protected:
269 void readEvaluationWeights(SUMOVehicle& veh, StoppingPlaceParamMap_t& stoppingPlaceParams, StoppingPlaceParamMap_t& stoppingPlaceDefaults, StoppingPlaceParamMap_t& maxValues) {
270 for (StoppingPlaceParamMap_t::iterator it = stoppingPlaceParams.begin(); it != stoppingPlaceParams.end(); ++it) {
271 double value = getWeight(veh, it->first, stoppingPlaceDefaults[it->first]);
272 it->second = value;
273 if (value > maxValues[it->first]) {
274 maxValues[it->first] = value;
275 }
276 }
277 }
278
279private:
280
283
284protected:
286 const std::string myParamPrefix;
292};
long long int SUMOTime
Definition GUI.h:36
std::vector< const MSEdge * > ConstMSEdgeVector
Definition MSEdge.h:74
std::vector< MSEdge * > MSEdgeVector
Definition MSEdge.h:73
#define SIMSTEP
Definition SUMOTime.h:61
SumoXMLTag
Numbers representing SUMO-XML - element names.
A road/street connecting two junctions.
Definition MSEdge.h:77
A lane area vehicles can halt at.
virtual bool useStoppingPlace(MSStoppingPlace *stoppingPlace)
Whether the stopping place should be included in the search (can be used to add an additional filter)
virtual void rememberBlockedStoppingPlace(SUMOVehicle &veh, const MSStoppingPlace *stoppingPlace, bool blocked)=0
store the blocked stopping place in the vehicle
virtual SUMOTime sawBlockedStoppingPlace(SUMOVehicle &veh, MSStoppingPlace *place, bool local)=0
ask the vehicle when it has seen the stopping place
StoppingPlaceParamSwitchMap_t myNormParams
std::map< std::string, bool > StoppingPlaceParamSwitchMap_t
MSStoppingPlace * reroute(std::vector< StoppingPlaceVisible > &stoppingPlaceCandidates, const std::vector< double > &probs, SUMOVehicle &veh, bool &newDestination, ConstMSEdgeVector &newRoute, StoppingPlaceParamMap_t &scores, const MSEdgeVector &closedEdges={})
main method to trigger the rerouting to the "best" StoppingPlace according to the custom evaluation f...
std::map< std::string, double > StoppingPlaceParamMap_t
static void updateMaxValues(StoppingPlaceParamMap_t &stoppingPlaceValues, StoppingPlaceParamMap_t &maxValues)
keep track of the maximum values of each component
virtual SUMOAbstractRouter< MSEdge, SUMOVehicle > & getRouter(SUMOVehicle &veh, const MSEdgeVector &prohibited={})
Provide the router to use (MSNet::getRouterTT or MSRoutingEngine)
std::map< MSStoppingPlace *, StoppingPlaceParamMap_t, ComparatorIdLess > StoppingPlaceMap_t
virtual int getNumberStoppingPlaceReroutes(SUMOVehicle &veh)=0
ask how many times already the vehicle has been rerouted to another stopping place
virtual double getStoppingPlaceCapacity(MSStoppingPlace *stoppingPlace)=0
Return the number of places the StoppingPlace provides.
static double getTargetValue(const StoppingPlaceParamMap_t &absValues, const StoppingPlaceParamMap_t &maxValues, const StoppingPlaceParamMap_t &weights, const StoppingPlaceParamSwitchMap_t &norm, const StoppingPlaceParamSwitchMap_t &invert)
compute the scalar target function value by means of a linear combination of all components/weights a...
void readEvaluationWeights(SUMOVehicle &veh, StoppingPlaceParamMap_t &stoppingPlaceParams, StoppingPlaceParamMap_t &stoppingPlaceDefaults, StoppingPlaceParamMap_t &maxValues)
Ask the vehicle about the relevant rerouting parameters and initiate the maximum value data structure...
virtual double getStoppingPlaceOccupancy(MSStoppingPlace *stoppingPlace)=0
Return the number of occupied places of the StoppingPlace.
double getWeight(SUMOVehicle &veh, const std::string param, const double defaultWeight, const bool warn=false)
read the value of a stopping place search param, e.g. a component weight factor
virtual StoppingPlaceParamMap_t collectWeights(SUMOVehicle &veh)
read target function weights for this vehicle
virtual bool evaluateDestination(SUMOVehicle &veh, double brakeGap, bool newDestination, MSStoppingPlace *alternative, double occupancy, double prob, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, StoppingPlaceMap_t &stoppingPlaces, std::map< MSStoppingPlace *, ConstMSEdgeVector > &newRoutes, std::map< MSStoppingPlace *, ConstMSEdgeVector > &stoppingPlaceApproaches, StoppingPlaceParamMap_t &maxValues, StoppingPlaceParamMap_t &addInput)
compute the target function for a single alternative
StoppingPlaceParamMap_t myEvalParams
StoppingPlaceParamSwitchMap_t myInvertParams
virtual void rememberStoppingPlaceScore(SUMOVehicle &veh, MSStoppingPlace *place, const std::string &score)=0
store the stopping place score in the vehicle
virtual void resetStoppingPlaceScores(SUMOVehicle &veh)=0
forget all stopping place score for this vehicle
virtual void setNumberStoppingPlaceReroutes(SUMOVehicle &veh, int value)=0
update the number of reroutes for the vehicle
virtual bool validComponentValues(StoppingPlaceParamMap_t &stoppingPlaceValues)
Whether the stopping place should be discarded due to its results from the component evaluation (allo...
virtual bool evaluateCustomComponents(SUMOVehicle &veh, double brakeGap, bool newDestination, MSStoppingPlace *alternative, double occupancy, double prob, SUMOAbstractRouter< MSEdge, SUMOVehicle > &router, StoppingPlaceParamMap_t &stoppingPlaceValues, ConstMSEdgeVector &newRoute, ConstMSEdgeVector &stoppingPlaceApproach, StoppingPlaceParamMap_t &maxValues, StoppingPlaceParamMap_t &addInput)
Compute some custom target function components.
std::pair< MSStoppingPlace *, bool > StoppingPlaceVisible
virtual double getLastStepStoppingPlaceOccupancy(MSStoppingPlace *stoppingPlace)=0
Return the number of occupied places of the StoppingPlace from the previous time step.
MSStoppingPlaceRerouter()=delete
Constructor.
Representation of a vehicle.
Definition SUMOVehicle.h:62
int size() const
Returns the number of stored items within the container.
std::map< const MSStoppingPlace *, StoppingPlaceMemoryEntry, ComparatorIdLess > StoppingPlaceMap
Definition of the map containing all visited stopping places.
void clear()
Removes all data about evaluated StoppingPlace items.
SUMOTime sawBlockedStoppingPlace(const MSStoppingPlace *stoppingPlace, bool local) const
Get the time the StoppingPlace was confirmed to be blocked.
StoppingPlaceMap myMap
The map from StoppingPlace to single evaluation.
void rememberStoppingPlaceScore(const MSStoppingPlace *stoppingPlace, const std::string &score)
score only needed when running with gui
StoppingPlaceMap::const_iterator end() const
Returns a reference to the end iterator for the internal map.
void rememberBlockedStoppingPlace(const MSStoppingPlace *stoppingPlace, bool local)
Store the time the StoppingPlace was confirmed to be blocked.
bool remove(MSStoppingPlace *id)
Removes an item.
StoppingPlaceMap::const_iterator begin() const
Returns a reference to the begin iterator for the internal map.
store information for a single stopping place
std::string score
SUMOTime blockedAtTimeLocal
SUMOTime blockedAtTime
StoppingPlaceMemoryEntry()