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.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 /****************************************************************************/
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(MSStageType::TRANSHIP, route, "", toStop, speed, departPos, arrivalPos, 0., -1) {
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  clon->setParameters(*this);
67  return clon;
68 }
69 
70 
71 void
72 MSStageTranship::proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, MSStage* previous) {
73  myDeparted = now;
74  //MSPModel_NonInteracting moves the transportable straight from start to end in
75  //a single step and assumes that moveToNextEdge is only called once)
76  //therefore we define that the transportable is already on its destination edge
77  myRouteStep = myRoute.end() - 1;
78  myDepartPos = previous->getEdgePos(now);
79  if (transportable->isPerson()) {
80  myPState = net->getPersonControl().getNonInteractingModel()->add(transportable, this, now);
81  (*myRouteStep)->addTransportable(transportable);
82  } else {
83  myPState = net->getContainerControl().getNonInteractingModel()->add(transportable, this, now);
84  (*myRouteStep)->addTransportable(transportable);
85  }
86 }
87 
88 
89 double
91  if (myArrived >= 0) {
92  const SUMOTime duration = myArrived - myDeparted;
93  return mySpeed * STEPS2TIME(duration);
94  } else {
95  return -1;
96  }
97 }
98 
99 
100 void
102  os.openTag("tranship");
103  os.writeAttr("depart", time2string(myDeparted));
104  os.writeAttr("departPos", myDepartPos);
105  os.writeAttr("arrival", time2string(myArrived));
106  os.writeAttr("arrivalPos", myArrivalPos);
107  os.writeAttr("duration", myArrived >= 0 ? time2string(getDuration()) : "-1");
108  os.writeAttr("routeLength", getDistance());
109  os.writeAttr("maxSpeed", mySpeed);
110  os.closeTag();
111 }
112 
113 
114 void
115 MSStageTranship::routeOutput(const bool /*isPerson*/, OutputDevice& os, const bool withRouteLength, const MSStage* const /* previous */) const {
116  os.openTag("tranship").writeAttr(SUMO_ATTR_EDGES, myRoute);
117  std::string comment = "";
118  if (myDestinationStop != nullptr) {
120  if (myDestinationStop->getMyName() != "") {
121  comment = " <!-- " + StringUtils::escapeXML(myDestinationStop->getMyName(), true) + " -->";
122  }
123  }
125  if (withRouteLength) {
126  os.writeAttr("routeLength", mySpeed * STEPS2TIME(myArrived - myDeparted));
127  }
128  if (OptionsCont::getOptions().getBool("vehroute-output.exit-times")) {
131  }
132  if (OptionsCont::getOptions().getBool("vehroute-output.cost")) {
134  }
135  os.closeTag(comment);
136 }
137 
138 
139 bool
140 MSStageTranship::moveToNextEdge(MSTransportable* transportable, SUMOTime currentTime, int /*prevDir*/, MSEdge* /* nextInternal */, const bool /* isReplay */) {
141  getEdge()->removeTransportable(transportable);
142  // transship does a direct move so we are already at our destination
143  if (myDestinationStop != nullptr) {
144  myDestinationStop->addTransportable(transportable); //jakob
145  }
146  if (!transportable->proceed(MSNet::getInstance(), currentTime)) {
147  if (transportable->isPerson()) {
148  MSNet::getInstance()->getPersonControl().erase(transportable);
149  } else {
150  MSNet::getInstance()->getContainerControl().erase(transportable);
151  }
152  }
153  return true;
154 }
155 
156 
157 std::string
158 MSStageTranship::getStageSummary(const bool /*isPerson*/) const {
159  const std::string dest = (getDestinationStop() == nullptr ?
160  " edge '" + getDestination()->getID() + "'" :
161  " stop '" + getDestinationStop()->getID() + "'");
162  return "transhipped to " + dest;
163 }
164 
165 
166 /****************************************************************************/
long long int SUMOTime
Definition: GUI.h:35
MSStageType
Definition: MSStage.h:54
std::string time2string(SUMOTime t, bool humanReadable)
convert SUMOTime to string (independently of global format setting)
Definition: SUMOTime.cpp:69
#define STEPS2TIME(x)
Definition: SUMOTime.h:55
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_STARTED
@ SUMO_ATTR_ARRIVALPOS
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_DEPARTPOS
@ SUMO_ATTR_ENDED
@ SUMO_ATTR_COST
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 removeTransportable(MSTransportable *t) const
Definition: MSEdge.cpp:1133
The simulated network and simulation perfomer.
Definition: MSNet.h:89
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:182
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:1182
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1173
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:65
virtual double getEdgePos(SUMOTime now) const
Definition: MSStage.cpp:83
MSStoppingPlace * myDestinationStop
the stop to reach by getting transported (if any)
Definition: MSStage.h:272
MSStoppingPlace * getDestinationStop() const
returns the destination stop (if any)
Definition: MSStage.h:84
double getCosts() const
Returns the costs of the stage.
Definition: MSStage.h:255
virtual SUMOTime getDuration() const
Definition: MSStage.cpp:139
SUMOTime myArrived
the time at which this stage ended
Definition: MSStage.h:284
double myArrivalPos
the longitudinal position at which we want to arrive
Definition: MSStage.h:275
SUMOTime myDeparted
the time at which this stage started
Definition: MSStage.h:281
double mySpeed
the speed of the transportable
const MSEdge * getEdge() const
Returns the current edge.
MSTransportableStateAdapter * myPState
state that is to be manipulated by MSPModel
std::vector< const MSEdge * > myRoute
The route of the container.
double myDepartPos
the depart position
std::vector< const MSEdge * >::iterator myRouteStep
current step
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
MSStageTranship(const std::vector< const MSEdge * > &route, MSStoppingPlace *toStop, double speed, double departPos, double arrivalPos)
constructor
bool moveToNextEdge(MSTransportable *container, SUMOTime currentTime, int prevDir, MSEdge *nextInternal=nullptr, const bool isReplay=false)
move forward and return whether the container arrived
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:60
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:254
bool closeTag(const std::string &comment="")
Closes the most recently opened tag and optionally adds a comment.
void setParameters(const Parameterised &params)
set the inner key/value map in map<string, string> format
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.