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>
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// ===========================================================================
45MSStageTranship::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
66}
67
68
69void
70MSStageTranship::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)->addTransportable(transportable);
80 } else {
81 myState = net->getContainerControl().getNonInteractingModel()->add(transportable, this, now);
82 (*myRouteStep)->addTransportable(transportable);
83 }
84}
85
86
87double
89 if (myArrived >= 0) {
90 const SUMOTime duration = myArrived - myDeparted;
91 return mySpeed * STEPS2TIME(duration);
92 } else {
93 return -1;
94 }
95}
96
97
98void
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
112void
113MSStageTranship::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 * STEPS2TIME(myArrived - myDeparted));
125 }
126 if (OptionsCont::getOptions().getBool("vehroute-output.exit-times")) {
129 }
130 os.closeTag(comment);
131}
132
133
134bool
135MSStageTranship::moveToNextEdge(MSTransportable* transportable, SUMOTime currentTime, int /*prevDir*/, MSEdge* /* nextInternal */) {
136 getEdge()->removeTransportable(transportable);
137 // transship does a direct move so we are already at our destination
138 if (myDestinationStop != nullptr) {
139 myDestinationStop->addTransportable(transportable); //jakob
140 }
141 if (!transportable->proceed(MSNet::getInstance(), currentTime)) {
142 if (transportable->isPerson()) {
143 MSNet::getInstance()->getPersonControl().erase(transportable);
144 } else {
145 MSNet::getInstance()->getContainerControl().erase(transportable);
146 }
147 }
148 return true;
149}
150
151
152std::string
153MSStageTranship::getStageSummary(const bool /*isPerson*/) const {
154 const std::string dest = (getDestinationStop() == nullptr ?
155 " edge '" + getDestination()->getID() + "'" :
156 " stop '" + getDestinationStop()->getID() + "'");
157 return "transhipped to " + dest;
158}
159
160
161/****************************************************************************/
long long int SUMOTime
Definition: GUI.h:36
MSStageType
Definition: MSStage.h:54
std::string time2string(SUMOTime t)
convert SUMOTime to string
Definition: SUMOTime.cpp:68
#define STEPS2TIME(x)
Definition: SUMOTime.h:54
@ 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 removeTransportable(MSTransportable *t) const
Definition: MSEdge.cpp:1094
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:183
virtual MSTransportableControl & getContainerControl()
Returns the container control.
Definition: MSNet.cpp:1105
virtual MSTransportableControl & getPersonControl()
Returns the person control.
Definition: MSNet.cpp:1096
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:61
virtual double getEdgePos(SUMOTime now) const
Definition: MSStage.cpp:79
MSStoppingPlace * myDestinationStop
the stop to reach by getting transported (if any)
Definition: MSStage.h:238
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:247
double myArrivalPos
the position at which we want to arrive
Definition: MSStage.h:241
SUMOTime myDeparted
the time at which this stage started
Definition: MSStage.h:244
MSTransportableStateAdapter * myState
state that is to be manipulated by MSPModel
std::vector< constMSEdge * >::iterator myRouteStep
current step
double mySpeed
the speed of the transportable
const MSEdge * getEdge() const
Returns the current edge.
std::vector< const MSEdge * > myRoute
The route of the container.
double myDepartPos
the depart position
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:59
Static storage of an output device and its base (abstract) implementation.
Definition: OutputDevice.h:61
OutputDevice & writeAttr(const SumoXMLAttr attr, const T &val)
writes a named attribute
Definition: OutputDevice.h:251
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.
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.