48 #define JUNCTION_TAZ_MISSING_HELP "\nSet option '--junction-taz' or load a TAZ-file"
55 const bool emptyDestinationsAllowed,
56 const bool ignoreErrors,
57 const bool checkSchema) :
60 myActiveRouteRepeat(0),
61 myActiveRoutePeriod(0),
62 myActivePerson(nullptr),
63 myActiveContainerPlan(nullptr),
64 myActiveContainerPlanSize(0),
65 myTryRepair(tryRepair),
66 myEmptyDestinationsAllowed(emptyDestinationsAllowed),
69 myKeepVTypeDist(
OptionsCont::getOptions().getBool(
"keep-vtype-distributions")),
70 myMapMatchingDistance(
OptionsCont::getOptions().getFloat(
"mapmatch.distance")),
71 myMapMatchJunctions(
OptionsCont::getOptions().getBool(
"mapmatch.junctions")),
72 myCurrentVTypeDistribution(nullptr),
73 myCurrentAlternatives(nullptr),
85 const std::string element =
toString(tag);
97 const std::string tazType = useJunction ?
"junction" :
"taz";
100 if (fromTaz ==
nullptr) {
104 }
else if (fromTaz->getNumSuccessors() == 0 && tag !=
SUMO_TAG_PERSON) {
130 if (viaSink ==
nullptr) {
134 viaEdges.push_back(viaSink);
140 for (
const ROEdge* e : viaEdges) {
149 const std::string tazType = useJunction ?
"junction" :
"taz";
152 if (toTaz ==
nullptr) {
156 }
else if (toTaz->getNumPredecessors() == 0 && tag !=
SUMO_TAG_PERSON) {
185 if (type ==
nullptr) {
197 const std::string fromID = attrs.
get<std::string>(
SUMO_ATTR_FROM, pid.c_str(), ok);
199 if (from ==
nullptr) {
200 throw ProcessError(
"The from edge '" + fromID +
"' within a ride of person '" + pid +
"' is not known.");
202 }
else if (plan.empty()) {
203 throw ProcessError(
"The start edge for person '" + pid +
"' is not known.");
207 const std::string toID = attrs.
getOpt<std::string>(
SUMO_ATTR_TO, pid.c_str(), ok,
"");
212 throw ProcessError(
"The to edge '" + toID +
"' within a ride of person '" + pid +
"' is not known.");
214 }
else if (busStopID !=
"") {
216 if (stop ==
nullptr) {
224 stop ==
nullptr ? std::numeric_limits<double>::infinity() : stop->
endPos);
234 (*myActiveContainerPlan) << attrs;
238 (*myActiveContainerPlan) << attrs;
248 (*myActiveContainerPlan) << attrs;
279 while (st.hasNext()) {
280 const std::string typeID = st.next();
282 if (type ==
nullptr) {
344 WRITE_WARNINGF(
"No probability for route %, using default.", rid);
358 if (type !=
nullptr) {
425 const ROEdge* last =
nullptr;
428 if (last !=
nullptr) {
430 if (intern->isInternal() && intern->getSuccessors().size() == 1 && intern->getSuccessors().front() == roe) {
431 fullRoute.push_back(intern);
435 fullRoute.push_back(roe);
447 if (stop.until > 0) {
452 throw ProcessError(
"Cannot repeat stops with 'until' in route " + description +
" because no cycleTime is defined.");
509 if (ok && index < 0) {
519 const std::string routeID = st.
next();
521 if (route ==
nullptr) {
554 if (type ==
nullptr) {
568 if (route ==
nullptr) {
572 if (route->
getID()[0] !=
'!') {
654 copyPerson->
getPlan().push_back(item->clone());
741 (*myActiveContainerPlan) << attrs;
746 std::string errorSuffix;
765 if (busstop ==
nullptr) {
776 if (containerstop ==
nullptr) {
787 if (parkingarea ==
nullptr) {
799 if (ok && stop.
edge !=
"") {
801 if (edge ==
nullptr) {
805 }
else if (ok && stop.
lane !=
"") {
807 if (edge ==
nullptr) {
811 }
else if (!ok || (stop.
lane ==
"" && stop.
edge ==
"")) {
812 myErrorOutput->
inform(
"A stop must be placed on a bus stop, a container stop, a parking area, an edge or a lane" + errorSuffix);
866 const std::string& rid,
bool& ok) {
868 const std::string
id = st.next();
870 if (edge ==
nullptr) {
874 into.push_back(edge);
883 WRITE_ERROR(
"Cannot convert geo-positions because the network has no geo-reference");
888 if (type !=
nullptr) {
902 if (best ==
nullptr) {
908 if (best !=
nullptr) {
909 into.push_back(best);
912 into.push_back(best);
925 const float cmin[2] = {(float) b.
xmin(), (float) b.
ymin()};
926 const float cmax[2] = {(float) b.
xmax(), (float) b.
ymax()};
927 std::set<const Named*> lanes;
929 t->
Search(cmin, cmax, sv);
931 double minDist = std::numeric_limits<double>::max();
932 const ROLane* best =
nullptr;
933 for (
const Named* o : lanes) {
939 if (dist < minDist) {
944 if (best ==
nullptr) {
958 if (closestEdge ==
nullptr) {
969 if (fromSource ==
nullptr || fromSink ==
nullptr) {
973 if (toSource ==
nullptr || toSink ==
nullptr) {
980 if (fromCloser && fromPossible) {
982 return isFrom ? fromSource : fromSink;
983 }
else if (!fromCloser && toPossible) {
985 return isFrom ? toSource : toSink;
989 return isFrom ? fromSource : fromSink;
991 return isFrom ? toSource : toSink;
1001 double& departPos,
double& arrivalPos, std::string& busStopID,
1003 const std::string description =
"walk or personTrip of '" + personID +
"'.";
1005 WRITE_WARNING(
"The attribute departPos is no longer supported for walks, please use the person attribute, the arrivalPos of the previous step or explicit stops.");
1008 if (lastStage !=
nullptr) {
1013 if (busStopID !=
"") {
1015 if (bs ==
nullptr) {
1023 if (toEdge !=
nullptr) {
1030 throw ProcessError(
"No destination edge for " + description +
".");
1040 const ROEdge* from =
nullptr;
1041 const ROEdge* to =
nullptr;
1062 double departPos = 0;
1063 double arrivalPos = std::numeric_limits<double>::infinity();
1064 std::string busStopID;
1072 const std::string mode = st.next();
1073 if (mode ==
"car") {
1075 }
else if (mode ==
"taxi") {
1077 }
else if (mode ==
"bicycle") {
1079 }
else if (mode ==
"public") {
1088 myActivePerson->
addTrip(from, to, modeSet, types, departPos, arrivalPos, busStopID, walkFactor, group);
1102 const RORoute* route = routeDef !=
nullptr ? routeDef->getFirstRoute() :
nullptr;
1103 if (route ==
nullptr) {
1120 double departPos = 0.;
1121 double arrivalPos = std::numeric_limits<double>::infinity();
1123 WRITE_WARNING(
"The attribute departPos is no longer supported for walks, please use the person attribute, the arrivalPos of the previous step or explicit stops.");
1143 for (
ROLane* lane : edgeItem.second->getLanes()) {
1144 Boundary b = lane->getShape().getBoxBoundary();
1145 const float cmin[2] = {(float) b.
xmin(), (float) b.
ymin()};
1146 const float cmax[2] = {(float) b.
xmax(), (float) b.
ymax()};
#define WRITE_WARNINGF(...)
#define WRITE_WARNING(msg)
std::vector< const ROEdge * > ConstROEdgeVector
#define JUNCTION_TAZ_MISSING_HELP
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ SVC_IGNORING
vehicles ignoring classes
@ SVC_PASSENGER
vehicle is a passenger car (a "normal" car)
@ SVC_BICYCLE
vehicle is a bicycle
@ SVC_TAXI
vehicle is a taxi
@ SVC_BUS
vehicle is a bus
@ SVC_PEDESTRIAN
pedestrian
const double DEFAULT_VEH_PROB
const std::string DEFAULT_PEDTYPE_ID
const std::string DEFAULT_VTYPE_ID
int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
const int VEHPARS_TO_TAZ_SET
const int VEHPARS_FROM_TAZ_SET
@ DEPART_GIVEN
The time is given.
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_CONTAINER_STOP
A container stop.
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_STOP
stop for vehicles
@ SUMO_TAG_FLOW
a flow definitio nusing a from-to edges instead of a route (used by router)
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_TAG_TRIP
a single trip definition (used by router)
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_COLOR
A color information.
int gPrecision
the precision for floating point outputs
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
A class that stores a 2D geometrical boundary.
void add(double x, double y, double z=0)
Makes the boundary include the given coordinate.
double ymin() const
Returns minimum y-coordinate.
double xmin() const
Returns minimum x-coordinate.
Boundary & grow(double by)
extends the boundary by the given amount
double ymax() const
Returns maximum y-coordinate.
double xmax() const
Returns maximum x-coordinate.
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
bool x2cartesian_const(Position &from) const
Converts the given coordinate into a cartesian using the previous initialisation.
static MsgHandler * getErrorInstance()
Returns the instance to add errors to.
virtual void inform(std::string msg, bool addType=true)
adds a new error to the list
Allows to store the object; used as context while traveling the rtree in TraCI.
Base class for objects which have an id.
const std::string & getID() const
Returns the id.
A RT-tree for efficient storing of SUMO's Named objects.
void Insert(const float a_min[2], const float a_max[2], Named *const &a_data)
Insert entry.
int Search(const float a_min[2], const float a_max[2], const Named::StoringVisitor &c) const
Find all within search rectangle.
A storage for options typed value containers)
double getFloat(const std::string &name) const
Returns the double-value of the named option (only for Option_Float)
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
const StringVector & getStringVector(const std::string &name) const
Returns the list of string-value of the named option (only for Option_StringVector)
static OptionsCont & getOptions()
Retrieves the options.
An output device that encapsulates an ofstream.
std::string getString() const
Returns the current content as a string.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
A point in 2D or 3D with translation and scaling methods.
double distanceSquaredTo2D(const Position &p2) const
returns the square of the distance to another position (Only using x and y positions)
double distance2D(const Position &p, bool perpendicular=false) const
closest 2D-distance to point p (or -1 if perpendicular is true and the point is beyond this vector)
A basic edge for routing applications.
const ROEdge * getNormalBefore() const
if this edge is an internal edge, return its first normal predecessor, otherwise the edge itself
bool isInternal() const
return whether this edge is an internal edge
const RONode * getFromJunction() const
const ROEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
double getLength() const
Returns the length of the edge.
const ROEdgeVector & getPredecessors() const
Returns the edge at the given position from the list of incoming edges.
const RONode * getToJunction() const
A single lane the router may use.
ROEdge & getEdge() const
Returns the lane's edge.
const PositionVector & getShape() const
bool allowsVehicleClass(SUMOVehicleClass vclass) const
The router's network representation.
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
const SUMOVehicleParameter::Stop * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Retrieves a stopping place from the network.
ROEdge * getEdge(const std::string &name) const
Retrieves an edge from the network.
bool addRouteDef(RORouteDef *def)
virtual bool addVehicle(const std::string &id, ROVehicle *veh)
void addContainer(const SUMOTime depart, const std::string desc)
bool addPerson(ROPerson *person)
virtual bool addVehicleType(SUMOVTypeParameter *type)
Adds a read vehicle type definition to the network.
RORouteDef * getRouteDef(const std::string &name) const
Returns the named route definition.
bool addVTypeDistribution(const std::string &id, RandomDistributor< SUMOVTypeParameter * > *vehTypeDistribution)
Adds a vehicle type distribution.
bool addFlow(SUMOVehicleParameter *flow, const bool randomize)
const NamedObjectCont< ROEdge * > & getEdgeMap() const
Base class for nodes used by the router.
const Position & getPosition() const
Returns the position of the node.
Every person has a plan comprising of multiple planItems.
virtual double getDestinationPos() const =0
A person as used by router.
void addRide(const ROEdge *const from, const ROEdge *const to, const std::string &lines, double arrivalPos, const std::string &destStop, const std::string &group)
void addTrip(const ROEdge *const from, const ROEdge *const to, const SVCPermissions modeSet, const std::string &vTypes, const double departPos, const double arrivalPos, const std::string &busStop, double walkFactor, const std::string &group)
std::vector< PlanItem * > & getPlan()
void addWalk(const ConstROEdgeVector &edges, const double duration, const double speed, const double departPos, const double arrivalPos, const std::string &busStop)
void addStop(const SUMOVehicleParameter::Stop &stopPar, const ROEdge *const stopEdge)
const SUMOVehicleParameter & getParameter() const
Returns the definition of the vehicle / person parameter.
const SUMOVTypeParameter * getType() const
Returns the type of the routable.
Base class for a vehicle's route definition.
void addLoadedAlternative(RORoute *alternative)
Adds a single alternative loaded from the file An alternative may also be generated during DUA.
double getOverallProb() const
Returns the sum of the probablities of the contained routes.
void addAlternativeDef(const RORouteDef *alternative)
Adds an alternative loaded from the file.
RORouteDef * copy(const std::string &id, const SUMOTime stopOffset) const
Returns a deep copy of the route definition.
void closeTrip()
Ends the processing of a trip.
void closeRouteDistribution()
closes (ends) the building of a distribution
NamedRTree * myLaneTree
RTree for finding lanes.
void addStop(const SUMOSAXAttributes &attrs)
Processing of a stop.
const double myMapMatchingDistance
maximum distance when map-matching
std::string myCurrentVTypeDistributionID
The id of the currently parsed vehicle type distribution.
virtual ~RORouteHandler()
standard destructor
RORouteHandler(RONet &net, const std::string &file, const bool tryRepair, const bool emptyDestinationsAllowed, const bool ignoreErrors, const bool checkSchema)
standard constructor
void addTranship(const SUMOSAXAttributes &attrs)
Processing of a tranship.
void parseEdges(const std::string &desc, ConstROEdgeVector &into, const std::string &rid, bool &ok)
Parse edges from strings.
void closeVType()
Ends the processing of a vehicle type.
void addRide(const SUMOSAXAttributes &attrs)
Processing of a ride.
void addWalk(const SUMOSAXAttributes &attrs)
add a fully specified walk
RONet & myNet
The current route.
void addFlowPerson(SUMOTime depart, const std::string &baseID, int i)
Processing of a person from a personFlow.
NamedRTree * getLaneTree()
initialize lane-RTree
ConstROEdgeVector myActiveRoute
The current route.
const ROEdge * getJunctionTaz(const Position &pos, const ROEdge *closestEdge, SUMOVehicleClass vClass, bool isFrom)
find closest junction taz given the closest edge
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
const bool myTryRepair
Information whether routes shall be repaired.
OutputDevice_String * myActiveContainerPlan
The plan of the current container.
SUMOTime myActiveRoutePeriod
const SUMOTime myBegin
The begin time.
RandomDistributor< SUMOVTypeParameter * > * myCurrentVTypeDistribution
The currently parsed distribution of vehicle types (probability->vehicle type)
void closePersonFlow()
Ends the processing of a personFlow.
void closePerson()
Ends the processing of a person.
void openRouteDistribution(const SUMOSAXAttributes &attrs)
opens a route distribution for reading
int myActiveContainerPlanSize
The number of stages in myActiveContainerPlan.
const bool myKeepVTypeDist
whether to keep the the vtype distribution in output
void openRouteFlow(const SUMOSAXAttributes &attrs)
opens a route flow for reading
void openTrip(const SUMOSAXAttributes &attrs)
opens a trip for reading
void closeVehicle()
Ends the processing of a vehicle.
void addContainer(const SUMOSAXAttributes &attrs)
Processing of a container.
const bool myMapMatchJunctions
void addTransport(const SUMOSAXAttributes &attrs)
Processing of a transport.
void parseWalkPositions(const SUMOSAXAttributes &attrs, const std::string &personID, const ROEdge *fromEdge, const ROEdge *&toEdge, double &departPos, double &arrivalPos, std::string &busStopID, const ROPerson::PlanItem *const lastStage, bool &ok)
@ brief parse depart- and arrival positions of a walk
MsgHandler *const myErrorOutput
Depending on the "ignore-errors" option different outputs are used.
void closeRoute(const bool mayBeDisconnected=false)
closes (ends) the building of a route.
void closeFlow()
Ends the processing of a flow.
int myActiveRouteRepeat
number of repetitions of the active route
void closeContainer()
Ends the processing of a container.
void closeVehicleTypeDistribution()
closes (ends) the building of a distribution
void addPerson(const SUMOSAXAttributes &attrs)
Processing of a person.
void parseGeoEdges(const PositionVector &positions, bool geo, ConstROEdgeVector &into, const std::string &rid, bool isFrom, bool &ok)
Parse edges from coordinates.
RORouteDef * myCurrentAlternatives
The currently parsed route alternatives.
void openFlow(const SUMOSAXAttributes &attrs)
opens a flow for reading
void addPersonTrip(const SUMOSAXAttributes &attrs)
add a routing request for a walking or intermodal person
void openVehicleTypeDistribution(const SUMOSAXAttributes &attrs)
opens a type distribution for reading
ROPerson * myActivePerson
The plan of the current person.
const ROEdge * getClosestEdge(const Position &pos, double distance, SUMOVehicleClass vClass)
find closest edge within distance for the given position or nullptr
void openRoute(const SUMOSAXAttributes &attrs)
opens a route for reading
void parseFromViaTo(SumoXMLTag tag, const SUMOSAXAttributes &attrs, bool &ok)
Called for parsing from and to and the corresponding taz attributes.
A complete router's route.
const ConstROEdgeVector & getEdgeVector() const
Returns the list of edges this route consists of.
A vehicle as used by router.
static double rand(std::mt19937 *rng=nullptr)
Returns a random real number in [0, 1)
double getOverallProb() const
Return the sum of the probabilites assigned to the members.
bool add(T val, double prob, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
Parser for routes during their loading.
bool parseStop(SUMOVehicleParameter::Stop &stop, const SUMOSAXAttributes &attrs, std::string errorSuffix, MsgHandler *const errorOutput)
parses attributes common to all stops
std::vector< SUMOVehicleParameter::Stop > myActiveRouteStops
List of the stops on the parsed route.
void registerLastDepart()
save last depart (only to be used if vehicle is not discarded)
double myCurrentCosts
The currently parsed route costs.
std::string myActiveRouteID
The id of the current route.
SUMOVehicleParameter * myVehicleParameter
Parameter of the current vehicle, trip, person, container or flow.
const bool myHardFail
flag to enable or disable hard fails
SUMOVTypeParameter * myCurrentVType
The currently parsed vehicle type.
static StopPos checkStopPos(double &startPos, double &endPos, const double laneLength, const double minLength, const bool friendlyPos)
check start and end position of a stop
virtual void myStartElement(int element, const SUMOSAXAttributes &attrs)
Called on the opening of a tag;.
double myActiveRouteProbability
The probability of the current route.
int myInsertStopEdgesAt
where stop edges can be inserted into the current route (-1 means no insertion)
std::string myActiveRouteRefID
The id of the route the current route references to.
const RGBColor * myActiveRouteColor
The currently parsed route's color.
Encapsulated SAX-Attributes.
T getOpt(int attr, const char *objectid, bool &ok, T defaultValue, bool report=true) const
Tries to read given attribute assuming it is an int.
const std::vector< std::string > getStringVector(int attr) const
Tries to read given attribute assuming it is a string vector.
SUMOTime getOptSUMOTimeReporting(int attr, const char *objectid, bool &ok, SUMOTime defaultValue, bool report=true) const
Tries to read given attribute assuming it is a SUMOTime.
T get(int attr, const char *objectid, bool &ok, bool report=true) const
Tries to read given attribute assuming it is an int.
virtual bool hasAttribute(int id) const =0
Returns the information whether the named (by its enum-value) attribute is within the current list.
Structure representing possible vehicle parameter.
double defaultProbability
The probability when being added to a distribution without an explicit probability.
void cacheParamRestrictions(const std::vector< std::string > &restrictionKeys)
SUMOVehicleClass vehicleClass
The vehicle's class.
std::string id
The vehicle type's id.
Definition of vehicle stop (position and duration)
std::string edge
The edge to stop at (used only in NETEDIT)
std::string lane
The lane to stop at.
std::string parkingarea
(Optional) parking area if one is assigned to the stop
double startPos
The stopping position start.
double endPos
The stopping position end.
std::string busstop
(Optional) bus stop if one is assigned to the stop
std::string containerstop
(Optional) container stop if one is assigned to the stop
Structure representing possible vehicle parameter.
double repetitionProbability
The probability for emitting a vehicle per second.
std::string vtypeid
The vehicle's type id.
SUMOTime repetitionOffset
The time offset between vehicle reinsertions.
std::vector< std::string > via
List of the via-edges the vehicle must visit.
int repetitionsDone
The number of times the vehicle was already inserted.
SUMOTime repetitionEnd
The time at which the flow ends (only needed when using repetitionProbability)
double departPos
(optional) The position the vehicle shall depart from
std::string routeid
The vehicle's route id.
std::string id
The vehicle's id.
std::vector< Stop > stops
List of the stops the vehicle will make, TraCI may add entries here.
bool wasSet(int what) const
Returns whether the given parameter was set.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
static double parseWalkPos(SumoXMLAttr attr, const bool hardFail, const std::string &id, double maxPos, const std::string &val, std::mt19937 *rng=0)
parse departPos or arrivalPos for a walk
static std::string getEdgeIDFromLane(const std::string laneID)
return edge id when given the lane ID
bool hasNext()
returns the information whether further substrings exist
std::string next()
returns the next substring when it exists. Otherwise the behaviour is undefined