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-2020 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>
28 #include <utils/geom/GeomHelper.h>
29 #include <microsim/MSNet.h>
30 #include <microsim/MSEdge.h>
31 #include <microsim/MSLane.h>
36 #include <microsim/MSVehicle.h>
38 #include "MSStageTranship.h"
39 
40 
41 // ===========================================================================
42 // method definitions
43 // ===========================================================================
44 MSStageTranship::MSStageTranship(const std::vector<const MSEdge*>& route,
45  MSStoppingPlace* toStop,
46  double speed,
47  double departPos, double arrivalPos) :
48  MSStageMoving(route, toStop, speed, departPos, arrivalPos, 0., MSStageType::TRANSHIP) {
50  departPos, myRoute.front()->getLength(), SUMO_ATTR_DEPARTPOS,
51  "container getting transhipped from " + myRoute.front()->getID());
53  arrivalPos, route.back()->getLength(), SUMO_ATTR_ARRIVALPOS,
54  "container getting transhipped to " + route.back()->getID());
55 }
56 
57 
59 }
60 
61 
62 MSStage*
65 }
66 
67 
68 void
69 MSStageTranship::proceed(MSNet* net, MSTransportable* transportable, SUMOTime now, MSStage* previous) {
70  myDeparted = now;
71  //MSPModel_NonInteracting moves the transportable straight from start to end in
72  //a single step and assumes that moveToNextEdge is only called once)
73  //therefore we define that the transportable is already on its destination edge
74  myRouteStep = myRoute.end() - 1;
75  myDepartPos = previous->getEdgePos(now);
76  if (transportable->isPerson()) {
77  myState = net->getPersonControl().getNonInteractingModel()->add(transportable, this, now);
78  (*myRouteStep)->addPerson(transportable);
79  } else {
80  myState = net->getContainerControl().getNonInteractingModel()->add(transportable, this, now);
81  (*myRouteStep)->addContainer(transportable);
82  }
83 }
84 
85 
86 double
88  if (myArrived >= 0) {
89  const SUMOTime duration = myArrived - myDeparted;
90  return mySpeed * STEPS2TIME(duration);
91  } else {
92  return -1;
93  }
94 }
95 
96 
97 void
99  os.openTag("tranship");
100  os.writeAttr("depart", time2string(myDeparted));
101  os.writeAttr("departPos", myDepartPos);
102  os.writeAttr("arrival", time2string(myArrived));
103  os.writeAttr("arrivalPos", myArrivalPos);
104  os.writeAttr("duration", myArrived >= 0 ? time2string(myArrived - myDeparted) : "-1");
105  os.writeAttr("routeLength", getDistance());
106  os.writeAttr("maxSpeed", mySpeed);
107  os.closeTag();
108 }
109 
110 
111 void
112 MSStageTranship::routeOutput(const bool /*isPerson*/, OutputDevice& os, const bool withRouteLength, const MSStage* const /* previous */) const {
113  os.openTag("tranship").writeAttr(SUMO_ATTR_EDGES, myRoute);
115  if (withRouteLength) {
116  os.writeAttr("routeLength", mySpeed * (myArrived - myDeparted));
117  }
118  os.closeTag();
119 }
120 
121 
122 bool
123 MSStageTranship::moveToNextEdge(MSTransportable* transportable, SUMOTime currentTime, MSEdge* /* nextInternal */) {
124  if (transportable->isPerson()) {
125  getEdge()->removePerson(transportable);
126  } else {
127  getEdge()->removeContainer(transportable);
128  }
129  // transship does a direct move so we are already at our destination
130  if (myDestinationStop != nullptr) {
131  myDestinationStop->addTransportable(transportable); //jakob
132  }
133  if (!transportable->proceed(MSNet::getInstance(), currentTime)) {
134  if (transportable->isPerson()) {
135  MSNet::getInstance()->getPersonControl().erase(transportable);
136  } else {
137  MSNet::getInstance()->getContainerControl().erase(transportable);
138  }
139  }
140  return true;
141 }
142 
143 
144 std::string
145 MSStageTranship::getStageSummary(const bool /*isPerson*/) const {
146  const std::string dest = (getDestinationStop() == nullptr ?
147  " edge '" + getDestination()->getID() + "'" :
148  " stop '" + getDestinationStop()->getID() + "'");
149  return "transhipped to " + dest;
150 }
151 
152 
153 /****************************************************************************/
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:31
@ SUMO_ATTR_SPEED
@ SUMO_ATTR_ARRIVALPOS
@ SUMO_ATTR_EDGES
the edges of a route
@ SUMO_ATTR_DEPARTPOS
A road/street connecting two junctions.
Definition: MSEdge.h:77
virtual void removeContainer(MSTransportable *container) const
Remove container from myContainers.
Definition: MSEdge.h:667
virtual void removePerson(MSTransportable *p) const
Definition: MSEdge.cpp:953
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:171
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:995
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:986
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:221
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:230
double myArrivalPos
the position at which we want to arrive
Definition: MSStage.h:224
SUMOTime myDeparted
the time at which this stage started
Definition: MSStage.h:227
MSTransportableStateAdapter * myState
state that is to be manipulated by MSPModel
Definition: MSStage.h:523
double mySpeed
the speed of the transportable
Definition: MSStage.h:535
const MSEdge * getEdge() const
Returns the current edge.
Definition: MSStage.cpp:537
std::vector< const MSEdge * > myRoute
The route of the container.
Definition: MSStage.h:526
double myDepartPos
the depart position
Definition: MSStage.h:538
std::vector< const MSEdge * >::iterator myRouteStep
current step
Definition: MSStage.h:529
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, MSEdge *nextInternal=0)
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.
bool addTransportable(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:73
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:60
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:239
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.