Eclipse SUMO - Simulation of Urban MObility
MSStageTranship.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-2022 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 /****************************************************************************/
19 // The class for modelling transportable movements without interaction
20 /****************************************************************************/
21 #include <config.h>
22 
23 #include <string>
24 #include <vector>
27 #include <utils/common/ToString.h>
29 #include <utils/geom/GeomHelper.h>
30 #include <microsim/MSNet.h>
31 #include <microsim/MSEdge.h>
32 #include <microsim/MSLane.h>
37 #include <microsim/MSVehicle.h>
39 #include "MSStageTranship.h"
40 
41 
42 // ===========================================================================
43 // method definitions
44 // ===========================================================================
45 MSStageTranship::MSStageTranship(const std::vector<const MSEdge*>& route,
46  MSStoppingPlace* toStop,
47  double speed,
48  double departPos, double arrivalPos) :
49  MSStageMoving(route, toStop, speed, departPos, arrivalPos, 0., -1, MSStageType::TRANSHIP) {
51  departPos, myRoute.front()->getLength(), SUMO_ATTR_DEPARTPOS,
52  "container getting transhipped from " + myRoute.front()->getID());
54  arrivalPos, route.back()->getLength(), SUMO_ATTR_ARRIVALPOS,
55  "container getting transhipped to " + route.back()->getID());
56 }
57 
58 
60 }
61 
62 
63 MSStage*
66 }
67 
68 
69 void
70 MSStageTranship::proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, MSStage* previous) {
71  myDeparted = now;
72  //MSPModel_NonInteracting moves the transportable straight from start to end in
73  //a single step and assumes that moveToNextEdge is only called once)
74  //therefore we define that the transportable is already on its destination edge
75  myRouteStep = myRoute.end() - 1;
76  myDepartPos = previous->getEdgePos(now);
77  if (transportable->isPerson()) {
78  myState = net->getPersonControl().getNonInteractingModel()->add(transportable, this, now);
79  (*myRouteStep)->addPerson(transportable);
80  } else {
81  myState = net->getContainerControl().getNonInteractingModel()->add(transportable, this, now);
82  (*myRouteStep)->addContainer(transportable);
83  }
84 }
85 
86 
87 double
89  if (myArrived >= 0) {
90  const SUMOTime duration = myArrived - myDeparted;
91  return mySpeed * STEPS2TIME(duration);
92  } else {
93  return -1;
94  }
95 }
96 
97 
98 void
100  os.openTag("tranship");
101  os.writeAttr("depart", time2string(myDeparted));
102  os.writeAttr("departPos", myDepartPos);
103  os.writeAttr("arrival", time2string(myArrived));
104  os.writeAttr("arrivalPos", myArrivalPos);
105  os.writeAttr("duration", myArrived >= 0 ? time2string(myArrived - myDeparted) : "-1");
106  os.writeAttr("routeLength", getDistance());
107  os.writeAttr("maxSpeed", mySpeed);
108  os.closeTag();
109 }
110 
111 
112 void
113 MSStageTranship::routeOutput(const bool /*isPerson*/, OutputDevice& os, const bool withRouteLength, const MSStage* const /* previous */) const {
114  os.openTag("tranship").writeAttr(SUMO_ATTR_EDGES, myRoute);
115  std::string comment = "";
116  if (myDestinationStop != nullptr) {
118  if (myDestinationStop->getMyName() != "") {
119  comment = " <!-- " + StringUtils::escapeXML(myDestinationStop->getMyName(), true) + " -->";
120  }
121  }
123  if (withRouteLength) {
124  os.writeAttr("routeLength", mySpeed * (myArrived - myDeparted));
125  }
126  if (OptionsCont::getOptions().getBool("vehroute-output.exit-times")) {
129  }
130  os.closeTag(comment);
131 }
132 
133 
134 bool
135 MSStageTranship::moveToNextEdge(MSTransportable* transportable, SUMOTime currentTime, int /*prevDir*/, MSEdge* /* nextInternal */) {
136  if (transportable->isPerson()) {
137  getEdge()->removePerson(transportable);
138  } else {
139  getEdge()->removeContainer(transportable);
140  }
141  // transship does a direct move so we are already at our destination
142  if (myDestinationStop != nullptr) {
143  myDestinationStop->addTransportable(transportable); //jakob
144  }
145  if (!transportable->proceed(MSNet::getInstance(), currentTime)) {
146  if (transportable->isPerson()) {
147  MSNet::getInstance()->getPersonControl().erase(transportable);
148  } else {
149  MSNet::getInstance()->getContainerControl().erase(transportable);
150  }
151  }
152  return true;
153 }
154 
155 
156 std::string
157 MSStageTranship::getStageSummary(const bool /*isPerson*/) const {
158  const std::string dest = (getDestinationStop() == nullptr ?
159  " edge '" + getDestination()->getID() + "'" :
160  " stop '" + getDestinationStop()->getID() + "'");
161  return "transhipped to " + dest;
162 }
163 
164 
165 /****************************************************************************/
MSStageType
Definition: MSStage.h:54
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define STEPS2TIME(x)
Definition: SUMOTime.h:53
long long int SUMOTime
Definition: SUMOTime.h:32
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_STARTED
@ SUMO_ATTR_ARRIVALPOS
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_DEPARTPOS
@ SUMO_ATTR_ENDED
std::string toString(const T &t, std::streamsize accuracy=gPrecision)
Definition: ToString.h:46
A road/street connecting two junctions.
Definition: MSEdge.h:77
virtual void removeContainer(MSTransportable *container) const
Remove container from myContainers.
Definition: MSEdge.h:678
virtual void removePerson(MSTransportable *p) const
Definition: MSEdge.cpp:1024
The simulated network and simulation perfomer.
Definition: MSNet.h:88
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:174
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:1068
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1059
virtual MSTransportableStateAdapter * add(MSTransportable *transportable, MSStageMoving *stage, SUMOTime now)=0
register the given person as a pedestrian
const MSEdge * getDestination() const
returns the destination edge
Definition: MSStage.cpp:70
virtual double getEdgePos(SUMOTime now) const
Definition: MSStage.cpp:88
MSStoppingPlace * myDestinationStop
the stop to reach by getting transported (if any)
Definition: MSStage.h:224
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
Definition: MSStage.h:80
SUMOTime myArrived
the time at which this stage ended
Definition: MSStage.h:233
double myArrivalPos
the position at which we want to arrive
Definition: MSStage.h:227
SUMOTime myDeparted
the time at which this stage started
Definition: MSStage.h:230
MSTransportableStateAdapter * myState
state that is to be manipulated by MSPModel
Definition: MSStage.h:545
double mySpeed
the speed of the transportable
Definition: MSStage.h:557
const MSEdge * getEdge() const
Returns the current edge.
Definition: MSStage.cpp:599
std::vector< const MSEdge * > myRoute
The route of the container.
Definition: MSStage.h:548
double myDepartPos
the depart position
Definition: MSStage.h:560
std::vector< const MSEdge * >::iterator myRouteStep
current step
Definition: MSStage.h:551
MSStage * clone() const
void routeOutput(const bool isPerson, OutputDevice &os, const bool withRouteLength, const MSStage *const previous) const
Called on writing vehroute output.
double getDistance() const
get travel distance in this stage
bool moveToNextEdge(MSTransportable *container, SUMOTime currentTime, int prevDir, MSEdge *nextInternal=0)
move forward and return whether the container arrived
MSStageTranship(const std::vector< const MSEdge * > &route, MSStoppingPlace *toStop, double speed, double departPos, double arrivalPos)
constructor
void proceed(MSNet *net, MSTransportable *transportable, SUMOTime now, MSStage *previous)
proceeds to the next step
void tripInfoOutput(OutputDevice &os, const MSTransportable *const transportable) const
Called on writing tripinfo output.
~MSStageTranship()
destructor
std::string getStageSummary(const bool isPerson) const
return string summary of the current stage
A lane area vehicles can halt at.
SumoXMLTag getElement() const
return the type of this stopping place
const std::string & getMyName() const
bool addTransportable(const MSTransportable *p)
adds a transportable to this stop
MSPModel * getNonInteractingModel()
Returns the non interacting movement model (for tranship and "beaming")
virtual void erase(MSTransportable *transportable)
removes a single transportable
virtual bool proceed(MSNet *net, SUMOTime time, const bool vehicleArrived=false)
bool isPerson() const
Whether it is a person.
const std::string & getID() const
Returns the id.
Definition: Named.h:74
static OptionsCont & getOptions()
Retrieves the options.
Definition: OptionsCont.cpp:58
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & openTag(const std::string &xmlElement)
Opens an XML tag.
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:248
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
static double interpretEdgePos(double pos, double maximumValue, SumoXMLAttr attr, const std::string &id, bool silent=false)
Interprets negative edge positions and fits them onto a given edge.
static std::string escapeXML(const std::string &orig, const bool maskDoubleHyphen=false)
Replaces the standard escapes by their XML entities.