65 const std::string& vTypes,
66 const double departPos,
const std::string& stopOrigin,
67 const double arrivalPos,
const std::string& busStop,
68 double walkFactor,
const std::string& group) {
69 PersonTrip* trip =
new PersonTrip(from, to, modeSet, departPos, stopOrigin, arrivalPos, busStop, walkFactor, group);
82 if (type ==
nullptr) {
84 throw InvalidArgument(
"The vehicle type '" + pars.
vtypeid +
"' in a trip for person '" +
id +
"' is not known.");
101 pars.
id =
id +
"_b0";
113 plan.push_back(trip);
119 double arrivalPos,
const std::string& destStop,
const std::string& group) {
121 plan.back()->addTripItem(
new Ride(-1, from, to, lines, group, -1., arrivalPos, -1., destStop));
126ROPerson::addWalk(std::vector<PlanItem*>& plan,
const ConstROEdgeVector& edges,
const double duration,
const double speed,
const double departPos,
const double arrivalPos,
const std::string& busStop) {
127 if (plan.empty() || plan.back()->isStop()) {
128 plan.push_back(
new PersonTrip(edges.back(), busStop));
130 plan.back()->addTripItem(
new Walk(-1, edges, -1., duration, speed, departPos, arrivalPos, busStop));
136 plan.push_back(
new Stop(stopPar, stopEdge));
143 std::string comment =
"";
144 if ((extended || options.
getBool(
"write-costs")) &&
myCost >= 0.) {
147 if (
from !=
nullptr) {
158 comment =
" <!-- " + name +
" -->";
160 }
else if (
arrPos != 0 &&
arrPos != std::numeric_limits<double>::infinity()) {
176 if (options.
getBool(
"exit-times")) {
189 stopDesc.write(os,
false);
190 std::string comment =
"";
191 for (std::string sID : stopDesc.getStoppingPlaceIDs()) {
194 comment += name +
" ";
198 comment =
" <!-- " + comment +
" -->";
207 std::string comment =
"";
208 if ((extended || options.
getBool(
"write-costs")) && myCost >= 0.) {
218 if (options.
getBool(
"exit-times")) {
221 if (!exitTimes.empty()) {
225 if (options.
getBool(
"route-length")) {
227 for (
const ROEdge* roe : edges) {
228 length += roe->getLength();
232 if (destStop !=
"") {
237 comment =
" <!-- " + name +
" -->";
239 }
else if (arr != 0 && arr != std::numeric_limits<double>::infinity()) {
247 PersonTrip* result =
new PersonTrip(from, to, modes, dep, stopOrigin, arr, stopDest, walkFactor, group);
248 for (
auto* item : myTripItems) {
258 veh->
saveAsXML(os, typeos, asAlternatives, options);
265 if ((asTrip || extended) && from !=
nullptr) {
266 const bool writeGeoTrip = asTrip && options.
getBool(
"write-trips.geo");
269 Position fromPos = from->getLanes()[0]->getShape().positionAtOffset2D(getDepartPos());
282 Position toPos = to->getLanes()[0]->getShape().positionAtOffset2D(
MIN2(getArrivalPos(), to->getLanes()[0]->getShape().length2D()));
294 std::vector<std::string> allowedModes;
296 allowedModes.push_back(
"public");
299 allowedModes.push_back(
"car");
302 allowedModes.push_back(
"taxi");
305 allowedModes.push_back(
"bicycle");
307 if (allowedModes.size() > 0) {
311 if (dep != 0 && dep != std::numeric_limits<double>::infinity()) {
314 if (arr != 0 && arr != std::numeric_limits<double>::infinity()) {
318 if (getStopDest() !=
"") {
321 if (walkFactor != 1) {
324 if (extended && myTripItems.size() != 0) {
325 std::vector<double> costs;
326 for (
const TripItem*
const tripItem : myTripItems) {
327 costs.push_back(tripItem->getCost());
333 for (
const TripItem*
const it : myTripItems) {
334 it->saveAsXML(os, extended, options);
342 for (
TripItem* tItem : myTripItems) {
343 result += tItem->getDuration();
351 std::vector<TripItem*>& resultItems,
MsgHandler*
const errorHandler) {
353 std::vector<ROIntermodalRouter::TripItem> result;
358 bool carUsed =
false;
361 const int lastIndex = (int)result.size() - 1;
363 if (!item.edges.empty()) {
364 if (item.line ==
"") {
369 const ROEdge* first = item.edges.front();
378 const ROEdge* last = item.edges.back();
385 if (&item == &result.back() && trip->
getStopDest() ==
"") {
386 resultItems.push_back(
new Walk(start, item.edges, item.cost, item.exitTimes, depPos, arrPos));
388 resultItems.push_back(
new Walk(start, item.edges, item.cost, item.exitTimes, depPos, arrPos, item.destStop));
390 }
else if (veh !=
nullptr && item.line == veh->
getID()) {
391 double cost = item.cost;
393 std::shared_ptr<RORoute> route = std::make_shared<RORoute>(veh->
getID() +
"_RouteDef", item.edges);
394 route->setProbability(1);
397 }
else if (resultItems.empty()) {
402 double arrPos = index == lastIndex ? trip->
getArrivalPos(
false) : item.arrivalPos;
403 resultItems.push_back(
new Ride(start, item.edges.front(), item.edges.back(), veh->
getID(), trip->
getGroup(), cost, arrPos, item.length, item.destStop));
408 resultItems.push_back(
new Ride(start, origin,
nullptr, line, trip->
getGroup(), item.cost, item.arrivalPos, item.length, item.destStop, item.intended,
TIME2STEPS(item.depart)));
414 if (result.empty()) {
415 errorHandler->
informf(
TL(
"No route for trip in person '%'."),
getID());
428 if (it->needsRouting()) {
430 const std::vector<ROVehicle*>& vehicles = trip->
getVehicles();
431 std::vector<TripItem*> resultItems;
432 std::vector<TripItem*> best;
434 if (vehicles.empty()) {
437 double bestCost = std::numeric_limits<double>::infinity();
438 for (
const ROVehicle*
const v : vehicles) {
439 const bool carUsed =
computeIntermodal(time, provider, trip, v, resultItems, errorHandler);
441 for (
const TripItem*
const tripIt : resultItems) {
442 cost += tripIt->getCost();
444 if (cost < bestCost) {
446 bestVeh = carUsed ? v :
nullptr;
447 best.swap(resultItems);
449 for (
const TripItem*
const tripIt : resultItems) {
461 WRITE_WARNINGF(
"Person '%' is configured to use public transport but no schedules are loaded.",
getID());
464 }
else if (!it->isStop()) {
468 const Walk*
const walk =
dynamic_cast<const Walk*
>(tIt);
469 if (walk ==
nullptr || walk->
getEdges().empty()) {
473 for (
const ROEdge*
const e : edges) {
474 if (!e->isTazConnector() && (e->getPermissions() & svc) == 0) {
475 errorHandler->
informf(
TL(
"Person '%' is not allowed to walk on edge '%'."),
getID(), e->getID());
479 if (edges.size() > 1) {
480 const ROEdge* failPrev =
nullptr;
481 const ROEdge* failNext =
nullptr;
482 auto canWalk = [&](
bool startForward) ->
bool {
483 const RONode* junction = startForward ? edges.front()->getToJunction() : edges.front()->getFromJunction();
484 for (
size_t i = 1; i < edges.size(); ++i) {
485 const ROEdge*
const prev = edges[i - 1];
486 const ROEdge*
const cur = edges[i];
489 }
else if (junction !=
nullptr && cur->
getFromJunction() == junction) {
491 }
else if (junction !=
nullptr && cur->
getToJunction() == junction) {
494 if (failPrev ==
nullptr) {
503 if (!canWalk(
true) && !canWalk(
false)) {
504 errorHandler->
informf(
TL(
"Invalid walk route for person '%' (edge '%' is not connected to edge '%')."),
522 const std::string& arrEdgeID = edges.back()->getID();
533 errorHandler->
informf(
TL(
"Bus stop '%' is not connected to arrival edge '%' for person '%' walking from edge '%'."),
541 time += it->getDuration();
557 const bool writeTrip = options.
exists(
"write-trips") && options.
getBool(
"write-trips");
561 it->saveVehicles(os, typeos, asAlternatives, options);
575 if (cloneIndex == 0) {
581 p.
write(os, options, tag);
585 it->saveAsXML(os, asAlternatives, writeTrip, options);
#define WRITE_WARNINGF(...)
std::vector< const ROEdge * > ConstROEdgeVector
SUMOTime string2time(const std::string &r)
convert string to SUMOTime
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
constexpr SUMOTime TIME2STEPS(double x)
long long int SVCPermissions
bitset where each bit declares whether a certain SVC may use this edge/lane
const std::string DEFAULT_TAXITYPE_ID
const std::string DEFAULT_VTYPE_ID
SUMOVehicleClass
Definition of vehicle classes to differ between different lane usage and authority types.
@ 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 std::string DEFAULT_BIKETYPE_ID
@ GIVEN
The position is given.
const std::string LINE_ANY
const long long int VEHPARS_DEPARTPOS_SET
const long long int VEHPARS_VTYPE_SET
@ TRIGGERED
The departure is person triggered.
SumoXMLTag
Numbers representing SUMO-XML - element names.
@ SUMO_TAG_CHARGING_STATION
A Charging Station.
@ SUMO_TAG_CONTAINER_STOP
A container stop.
@ SUMO_TAG_BUS_STOP
A bus stop.
@ SUMO_TAG_PARKING_AREA
A parking area.
@ SUMO_TAG_TRAIN_STOP
A train stop (alias for bus stop)
@ SUMO_TAG_OVERHEAD_WIRE_SEGMENT
An overhead wire segment.
@ SUMO_ATTR_EDGES
the edges of a route
int gPrecision
the precision for floating point outputs
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
static const GeoConvHelper & getFinal()
the coordinate transformation for writing the location element and for tracking the original coordina...
void cartesian2geo(Position &cartesian) const
Converts the given cartesian (shifted) position to its geo (lat/long) representation.
void informf(const std::string &format, T value, Targs... Fargs)
adds a new formatted message
const std::string & getID() const
Returns the id.
A storage for options typed value containers)
std::string getString(const std::string &name) const
Returns the string-value of the named option (only for Option_String)
bool exists(const std::string &name) const
Returns the information whether the named option is known.
bool getBool(const std::string &name) const
Returns the boolean-value of the named option (only for Option_Bool)
static OptionsCont & getOptions()
Retrieves the options.
Static storage of an output device and its base (abstract) implementation.
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const ATTR_TYPE &attr, const T &val, const bool isNull=false, const bool escape=false)
writes a named attribute
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setPrecision(int precision=gPrecision)
Sets the precision or resets it to default.
A point in 2D or 3D with translation and scaling methods.
A basic edge for routing applications.
const RONode * getToJunction() const
bool isTazConnector() const
const RONode * getFromJunction() const
const ROEdgeVector & getPredecessors() const
Returns the edge at the given position from the list of incoming edges.
const ROEdgeVector & getSuccessors(SUMOVehicleClass vClass=SVC_IGNORING) const
Returns the following edges, restricted by vClass.
double getLength() const
Returns the length of the edge.
The router's network representation.
SUMOVTypeParameter * getVehicleTypeSecure(const std::string &id)
Retrieves the named vehicle type.
static RONet * getInstance()
Returns the pointer to the unique instance of RONet (singleton).
bool knowsVehicle(const std::string &id) const
returns whether a vehicle with the given id was already loaded
double getMaxTraveltime() const
const std::string getStoppingPlaceElement(const std::string &id) const
return the element name for the given stopping place id
const SUMOVehicleParameter::Stop * getStoppingPlace(const std::string &id, const SumoXMLTag category) const
Retrieves a stopping place from the network.
const std::string getStoppingPlaceName(const std::string &id) const
return the name for the given stopping place id
Base class for nodes used by the router.
A planItem can be a Trip which contains multiple tripItems.
double getDepartPos(bool replaceDefault=true) const
void saveVehicles(OutputDevice &os, OutputDevice *const typeos, bool asAlternatives, OptionsCont &options) const
const std::string & getStopOrigin() const
SVCPermissions getModes() const
const std::string & getStopDest() const
double getWalkFactor() const
const ROEdge * getDestination() const
SUMOTime getDuration() const
return duration sum of all trip items
double getArrivalPos(bool replaceDefault=true) const
std::vector< ROVehicle * > & getVehicles()
const std::string & getGroup() const
void saveAsXML(OutputDevice &os, const bool extended, const bool asTrip, OptionsCont &options) const
const ROEdge * getOrigin() const
const std::vector< TripItem * > & getTripItems() const
std::vector< TripItem * > myTripItems
the fully specified trips
void setItems(std::vector< TripItem * > &newItems, const ROVehicle *const veh)
void addVehicle(ROVehicle *veh)
void updateModes(SVCPermissions additionalModes)
Every person has a plan comprising of multiple planItems.
static const std::string UNDEFINED_STOPPING_PLACE
A ride is part of a trip, e.g., go from here to here by car or bus.
const std::string destStop
const std::string intended
void saveAsXML(OutputDevice &os, const bool extended, OptionsCont &options) const
A planItem can be a Stop.
void saveAsXML(OutputDevice &os, const bool extended, const bool asTrip, OptionsCont &options) const
A TripItem is part of a trip, e.g., go from here to here by car.
SUMOTime getStart() const
SUMOTime getDuration() const
A walk is part of a trip, e.g., go from here to here by foot.
void saveAsXML(OutputDevice &os, const bool extended, OptionsCont &options) const
const std::string & getStopDest() const
const ConstROEdgeVector & getEdges() const
static bool myHaveWarnedPTMissing
virtual ~ROPerson()
Destructor.
bool computeIntermodal(SUMOTime time, const RORouterProvider &provider, const PersonTrip *const trip, const ROVehicle *const veh, std::vector< TripItem * > &resultItems, MsgHandler *const errorHandler)
ROPerson(const SUMOVehicleParameter &pars, const SUMOVTypeParameter *type)
Constructor.
static void addTrip(std::vector< PlanItem * > &plan, const std::string &id, const ROEdge *const from, const ROEdge *const to, const SVCPermissions modeSet, const std::string &vTypes, const double departPos, const std::string &stopOrigin, const double arrivalPos, const std::string &busStop, double walkFactor, const std::string &group)
static void addStop(std::vector< PlanItem * > &plan, const SUMOVehicleParameter::Stop &stopPar, const ROEdge *const stopEdge)
static void addRide(std::vector< PlanItem * > &plan, const ROEdge *const from, const ROEdge *const to, const std::string &lines, double arrivalPos, const std::string &destStop, const std::string &group)
void computeRoute(const RORouterProvider &provider, const bool removeLoops, MsgHandler *errorHandler)
void saveAsXML(OutputDevice &os, OutputDevice *const typeos, bool asAlternatives, OptionsCont &options, int cloneIndex=0) const
Saves the complete person description.
static void addWalk(std::vector< PlanItem * > &plan, const ConstROEdgeVector &edges, const double duration, const double speed, const double departPos, const double arrivalPos, const std::string &busStop)
std::vector< PlanItem * > myPlan
The plan of the person.
A routable thing such as a vehicle or person.
SUMOVehicleClass getVClass() const
bool isPartOfFlow() const
bool myRoutingSuccess
Whether the last routing was successful.
const SUMOVTypeParameter * getType() const
Returns the type of the routable.
const std::string & getID() const
Returns the id of the routable.
const SUMOVehicleParameter & getParameter() const
Returns the definition of the vehicle / person parameter.
double getMaxSpeed() const
Returns the vehicle's maximum speed.
Base class for a vehicle's route definition.
void addLoadedAlternative(std::shared_ptr< RORoute > alternative)
Adds a single alternative loaded from the file An alternative may also be generated during DUA.
A vehicle as used by router.
RORouteDef * getRouteDefinition() const
Returns the definition of the route the vehicle takes.
IntermodalRouter< E, L, N, V > & getIntermodalRouter() const
Structure representing possible vehicle parameter.
void write(OutputDevice &dev) const
Writes the vtype.
bool saved
Information whether this type was already saved (needed by routers)
SUMOVehicleClass vehicleClass
The vehicle's class.
Definition of vehicle stop (position and duration)
std::string lane
The lane to stop at.
std::vector< std::tuple< std::string, double, double > > accessPos
lanes and positions connected to this stop (only used by duarouter where Stop is used to store stoppi...
Structure representing possible vehicle parameter.
std::string vtypeid
The vehicle's type id.
long long int parametersSet
Information for the router which parameter were set, TraCI may modify this (when changing color)
void write(OutputDevice &dev, const OptionsCont &oc, const SumoXMLTag altTag=SUMO_TAG_VEHICLE, const std::string &typeID="") const
Writes the parameters as a beginning element.
double departPos
(optional) The position the vehicle shall depart from
std::string id
The vehicle's id.
DepartDefinition departProcedure
Information how the vehicle shall choose the depart time.
DepartPosDefinition departPosProcedure
Information how the vehicle shall choose the departure position.
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
static OutputDevice & writeParams(OutputDevice &device, const Parameterised ¶ms)
write the parameters of the given object as param tags