SUMO - Simulation of Urban MObility
MSCModel_NonInteracting.cpp
Go to the documentation of this file.
1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2014-2017 German Aerospace Center (DLR) and others.
4 /****************************************************************************/
5 //
6 // This program and the accompanying materials
7 // are made available under the terms of the Eclipse Public License v2.0
8 // which accompanies this distribution, and is available at
9 // http://www.eclipse.org/legal/epl-v20.html
10 //
11 /****************************************************************************/
18 // The container following model for tranship (prototype)
19 /****************************************************************************/
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #ifdef _MSC_VER
25 #include <windows_config.h>
26 #else
27 #include <config.h>
28 #endif
29 //
30 #include <cmath>
31 #include <algorithm>
33 #include <utils/geom/GeomHelper.h>
35 #include <microsim/MSNet.h>
36 #include <microsim/MSEdge.h>
37 #include <microsim/MSLane.h>
38 #include <microsim/MSJunction.h>
41 
42 // ===========================================================================
43 // static members
44 // ===========================================================================
46 
47 
48 // named constants
49 const int CState::FORWARD(1);
50 const int CState::BACKWARD(-1);
51 const int CState::UNDEFINED_DIRECTION(0);
52 const double CState::LATERAL_OFFSET(0);
53 
54 // ===========================================================================
55 // MSCModel_NonInteracting method definitions
56 // ===========================================================================
57 
59  myNet(net) {
60  assert(myNet != 0);
61 }
62 
63 
65 }
66 
69  if (myModel == 0) {
70  MSNet* net = MSNet::getInstance();
72  }
73  return myModel;
74 }
75 
76 CState*
78  CState* state = new CState();
79  const SUMOTime firstEdgeDuration = state->computeTranshipTime(0, *stage, now);
80  myNet->getBeginOfTimestepEvents()->addEvent(new MoveToNextEdge(container, *stage), now + firstEdgeDuration);
81  return state;
82 }
83 
84 
85 void
87  if (myModel != 0) {
88  delete myModel;
89  myModel = 0;
90  }
91 }
92 
93 
96  CState* state = myParent.getContainerState();
97  const MSEdge* old = myParent.getEdge();
98  const bool arrived = myParent.moveToNextEdge(myContainer, currentTime);
99  if (arrived) {
100  // tranship finished. clean up state
101  delete state;
102  return 0;
103  } else {
104  return state->computeTranshipTime(old, myParent, currentTime);
105  }
106 }
107 
108 
109 double
111  return myCurrentBeginPos + (myCurrentEndPos - myCurrentBeginPos) / myCurrentDuration * (now - myLastEntryTime);
112 }
113 
114 
115 Position
117  const double dist = myCurrentBeginPosition.distanceTo2D(myCurrentEndPosition); //distance between begin and end position of this tranship stage
118  double pos = MIN2(STEPS2TIME(now - myLastEntryTime) * stage.getMaxSpeed(), dist); //the containerd shall not go beyond its end position
119  return PositionVector::positionAtOffset2D(myCurrentBeginPosition, myCurrentEndPosition, pos, 0);
120 }
121 
122 
123 double
125  double angle = stage.getEdgeAngle(stage.getEdge(), getEdgePos(stage, now)) + (myCurrentEndPos < myCurrentBeginPos ? 1.5 * M_PI : 0.5 * M_PI);
126  if (angle > M_PI) {
127  angle -= 2 * M_PI;
128  }
129  return angle;
130 }
131 
132 
133 double
135  return stage.getMaxSpeed();
136 }
137 
138 
139 SUMOTime
141  myLastEntryTime = currentTime;
142 
143  myCurrentBeginPos = stage.getDepartPos();
144  myCurrentEndPos = stage.getArrivalPos();
145 
146  const MSLane* fromLane = stage.getFromEdge()->getLanes().front(); //the lane the container starts from during its tranship stage
147  myCurrentBeginPosition = stage.getLanePosition(fromLane, myCurrentBeginPos, LATERAL_OFFSET);
148  const MSLane* toLane = stage.getToEdge()->getLanes().front(); //the lane the container ends during its tranship stage
149  myCurrentEndPosition = stage.getLanePosition(toLane, myCurrentEndPos, LATERAL_OFFSET);
150 
151  myCurrentDuration = MAX2((SUMOTime)1, TIME2STEPS(fabs(myCurrentEndPosition.distanceTo(myCurrentBeginPosition)) / stage.getMaxSpeed()));
152  return myCurrentDuration;
153 }
154 
155 
156 
157 /****************************************************************************/
MSCModel_NonInteracting(MSNet *net)
Constructor (it should not be necessary to construct more than one instance)
static MSCModel_NonInteracting * myModel
double distanceTo2D(const Position &p2) const
returns the euclidean distance in the x-y-plane
Definition: Position.h:249
Position positionAtOffset2D(double pos, double lateralOffset=0) const
Returns the position at the given length.
const MSEdge * getToEdge() const
Returns last edge of the containers route.
const std::vector< MSLane * > & getLanes() const
Returns this edge&#39;s lanes.
Definition: MSEdge.h:167
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:167
T MAX2(T a, T b)
Definition: StdDefs.h:73
const MSEdge * getFromEdge() const
Returns first edge of the containers route.
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
Position getLanePosition(const MSLane *lane, double at, double offset) const
get position on lane at length at with orthogonal offset
The simulated network and simulation perfomer.
Definition: MSNet.h:90
CState * add(MSTransportable *container, MSContainer::MSContainerStage_Tranship *stage, SUMOTime now)
register the given container as a transhiped container
static const int FORWARD
A road/street connecting two junctions.
Definition: MSEdge.h:80
static const int BACKWARD
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:45
MSNet * myNet
the net to which to issue moveToNextEdge commands
MSEventControl * getBeginOfTimestepEvents()
Returns the event control for events executed at the begin of a time step.
Definition: MSNet.h:399
virtual void addEvent(Command *operation, SUMOTime execTimeStep=-1)
Adds an Event.
#define STEPS2TIME(x)
Definition: SUMOTime.h:64
T MIN2(T a, T b)
Definition: StdDefs.h:67
double getMaxSpeed() const
accessors to be used by MSCModel_NonInteracting
Definition: MSContainer.h:185
double getAngle(const MSContainer::MSContainerStage_Tranship &stage, SUMOTime now) const
return the direction in which the container heading to
#define M_PI
Definition: odrSpiral.cpp:40
static const double LATERAL_OFFSET
the offset for computing container positions when being transhiped
SUMOTime execute(SUMOTime currentTime)
Executes the command.
double getEdgeAngle(const MSEdge *e, double at) const
get angle of the edge at a certain position
SUMOTime computeTranshipTime(const MSEdge *prev, const MSContainer::MSContainerStage_Tranship &stage, SUMOTime currentTime)
compute tranship time on edge and update state members
long long int SUMOTime
Definition: TraCIDefs.h:51
const MSEdge * getEdge() const
Returns the current edge.
The container following model for tranship.
double getSpeed(const MSContainer::MSContainerStage_Tranship &stage) const
return the current speed of the container
Position getPosition(const MSContainer::MSContainerStage_Tranship &stage, SUMOTime now) const
return the network coordinate of the container
double getEdgePos(const MSContainer::MSContainerStage_Tranship &stage, SUMOTime now) const
return the offset from the start of the current edge measured in its natural direction ...
Representation of a lane in the micro simulation.
Definition: MSLane.h:77
static const int UNDEFINED_DIRECTION
static MSCModel_NonInteracting * getModel()
static void cleanup()
remove state at simulation end