SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
MSCModel_NonInteracting.cpp
Go to the documentation of this file.
1 /****************************************************************************/
8 // The container following model for tranship (prototype)
9 /****************************************************************************/
10 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
11 // Copyright (C) 2014-2016 DLR (http://www.dlr.de/) and contributors
12 /****************************************************************************/
13 //
14 // This file is part of SUMO.
15 // SUMO is free software: you can redistribute it and/or modify
16 // it under the terms of the GNU General Public License as published by
17 // the Free Software Foundation, either version 3 of the License, or
18 // (at your option) any later version.
19 //
20 /****************************************************************************/
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #ifdef _MSC_VER
26 #include <windows_config.h>
27 #else
28 #include <config.h>
29 #endif
30 //
31 #include <math.h>
32 #include <algorithm>
34 #include <utils/geom/GeomHelper.h>
36 #include <microsim/MSNet.h>
37 #include <microsim/MSEdge.h>
38 #include <microsim/MSLane.h>
39 #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);
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),
81  now + firstEdgeDuration, MSEventControl::ADAPT_AFTER_EXECUTION);
82  return state;
83 }
84 
85 
86 void
88  if (myModel != 0) {
89  delete myModel;
90  myModel = 0;
91  }
92 }
93 
94 
98  const MSEdge* old = myParent.getEdge();
99  const bool arrived = myParent.moveToNextEdge(myContainer, currentTime);
100  if (arrived) {
101  // tranship finished. clean up state
102  delete state;
103  return 0;
104  } else {
105  return state->computeTranshipTime(old, myParent, currentTime);
106  }
107 }
108 
109 
110 SUMOReal
112  return myCurrentBeginPos + (myCurrentEndPos - myCurrentBeginPos) / myCurrentDuration * (now - myLastEntryTime);
113 }
114 
115 
116 Position
118  const SUMOReal dist = myCurrentBeginPosition.distanceTo2D(myCurrentEndPosition); //distance between begin and end position of this tranship stage
119  SUMOReal pos = MIN2(STEPS2TIME(now - myLastEntryTime) * stage.getMaxSpeed(), dist); //the containerd shall not go beyond its end position
120  return PositionVector::positionAtOffset2D(myCurrentBeginPosition, myCurrentEndPosition, pos, 0);
121 }
122 
123 
124 SUMOReal
126  SUMOReal angle = stage.getEdgeAngle(stage.getEdge(), getEdgePos(stage, now)) + (myCurrentEndPos < myCurrentBeginPos ? 1.5 * M_PI : 0.5 * M_PI);
127  if (angle > M_PI) {
128  angle -= 2 * M_PI;
129  }
130  return angle;
131 }
132 
133 
134 SUMOReal
136  return stage.getMaxSpeed();
137 }
138 
139 
140 SUMOTime
142  myLastEntryTime = currentTime;
143 
144  myCurrentBeginPos = stage.getDepartPos();
145  myCurrentEndPos = stage.getArrivalPos();
146 
147  const MSLane* fromLane = stage.getFromEdge()->getLanes().front(); //the lane the container starts from during its tranship stage
148  myCurrentBeginPosition = stage.getLanePosition(fromLane, myCurrentBeginPos, LATERAL_OFFSET);
149  const MSLane* toLane = stage.getToEdge()->getLanes().front(); //the lane the container ends during its tranship stage
150  myCurrentEndPosition = stage.getLanePosition(toLane, myCurrentEndPos, LATERAL_OFFSET);
151 
152  myCurrentDuration = MAX2((SUMOTime)1, TIME2STEPS(fabs(myCurrentEndPosition.distanceTo(myCurrentBeginPosition)) / stage.getMaxSpeed()));
153  return myCurrentDuration;
154 }
155 
156 
157 
158 /****************************************************************************/
long long int SUMOTime
Definition: SUMOTime.h:43
MSCModel_NonInteracting(MSNet *net)
Constructor (it should not be necessary to construct more than one instance)
static MSCModel_NonInteracting * myModel
const std::vector< MSLane * > & getLanes() const
Returns this edge's lanes.
Definition: MSEdge.h:192
SUMOReal getEdgePos(const MSContainer::MSContainerStage_Tranship &stage, SUMOTime now) const
return the offset from the start of the current edge measured in its natural direction ...
#define M_PI
Definition: angles.h:37
const MSEdge * getEdge() const
Returns the current edge.
static MSNet * getInstance()
Returns the pointer to the unique instance of MSNet (singleton).
Definition: MSNet.cpp:159
T MAX2(T a, T b)
Definition: StdDefs.h:75
SUMOReal getMaxSpeed() const
accessors to be used by MSCModel_NonInteracting
Definition: MSContainer.h:183
#define TIME2STEPS(x)
Definition: SUMOTime.h:66
Position positionAtOffset2D(SUMOReal pos, SUMOReal lateralOffset=0) const
Returns the position at the given length.
SUMOReal getEdgeAngle(const MSEdge *e, SUMOReal at) const
get angle of the edge at a certain position
The simulated network and simulation perfomer.
Definition: MSNet.h:93
SUMOReal getAngle(const MSContainer::MSContainerStage_Tranship &stage, SUMOTime now) const
return the direction in which the container heading to
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
Position getLanePosition(const MSLane *lane, SUMOReal at, SUMOReal offset) const
get position on lane at length at with orthogonal offset
static const int BACKWARD
A point in 2D or 3D with translation and scaling methods.
Definition: Position.h:46
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:400
#define STEPS2TIME(x)
Definition: SUMOTime.h:65
T MIN2(T a, T b)
Definition: StdDefs.h:69
MSContainer::MSContainerStage_Tranship & myParent
const MSEdge * getFromEdge() const
Returns first edge of the containers route.
virtual SUMOTime addEvent(Command *operation, SUMOTime execTimeStep, AdaptType type)
Adds an Event.
bool moveToNextEdge(MSTransportable *container, SUMOTime currentTime, MSEdge *nextInternal=0)
move forward and return whether the container arrived
Position getPosition(const MSContainer::MSContainerStage_Tranship &stage, SUMOTime now) const
return the network coordinate of the container
SUMOTime execute(SUMOTime currentTime)
Executes the command.
Patch the time in a way that it is at least as high as the simulation begin time. ...
SUMOTime computeTranshipTime(const MSEdge *prev, const MSContainer::MSContainerStage_Tranship &stage, SUMOTime currentTime)
compute tranship time on edge and update state members
#define SUMOReal
Definition: config.h:214
SUMOReal getSpeed(const MSContainer::MSContainerStage_Tranship &stage) const
return the current speed of the container
The container following model for tranship.
const MSEdge * getToEdge() const
Returns last edge of the containers route.
Representation of a lane in the micro simulation.
Definition: MSLane.h:79
static const int UNDEFINED_DIRECTION
static MSCModel_NonInteracting * getModel()
static void cleanup()
remove state at simulation end
static const SUMOReal LATERAL_OFFSET
the offset for computing container positions when being transhiped