1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2014-2019 German Aerospace Center (DLR) and others.
4 // This program and the accompanying materials
5 // are made available under the terms of the Eclipse Public License v2.0
6 // which accompanies this distribution, and is available at
7 // http://www.eclipse.org/legal/epl-v20.html
8 // SPDX-License-Identifier: EPL-2.0
9 /****************************************************************************/
10 /// @file    MSCModel_NonInteracting.h
11 /// @author  Melanie Weber
12 /// @author  Andreas Kendziorra
13 /// @date    Tue, 29 July 2014
14 /// @version $Id$
15 ///
16 // The container following model for tranship (prototype)
17 /****************************************************************************/
18 #ifndef MSCModel_NonInteracting_h
19 #define MSCModel_NonInteracting_h
20 
21 // ===========================================================================
22 // included modules
23 // ===========================================================================
24 #include <config.h>
25 
26 #include <string>
27 #include <limits>
28 #include <utils/common/SUMOTime.h>
29 #include <utils/common/Command.h>
30 #include <microsim/MSContainer.h>
31 
32 
33 // ===========================================================================
34 // class declarations
35 // ===========================================================================
36 class MSNet;
37 class MSLink;
38 class MSLane;
39 class MSJunction;
40 class CState;
41 
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
46 /**
47  * @class MSCModel_NonInteracting
48  * @brief The container following model for tranship
49  *
50  */
51 class MSCModel_NonInteracting {
52 public:
53 
54     /// @brief Constructor (it should not be necessary to construct more than one instance)
55     MSCModel_NonInteracting(MSNet* net);
56 
57     ~MSCModel_NonInteracting();
58 
59     static MSCModel_NonInteracting* getModel();
60 
61     /// @brief remove state at simulation end
62     static void cleanup();
63 
64     /// @brief register the given container as a transhiped container
65     CState* add(MSTransportable* container, MSContainer::MSContainerStage_Tranship* stage, SUMOTime now);
66 
67 private:
68     static MSCModel_NonInteracting* myModel;
69 
70 private:
71     class MoveToNextEdge : public Command {
72     public:
MoveToNextEdge(MSTransportable * container,MSContainer::MSContainerStage_Tranship & tranship)73         MoveToNextEdge(MSTransportable* container, MSContainer::MSContainerStage_Tranship& tranship) : myParent(tranship), myContainer(container) {}
~MoveToNextEdge()74         ~MoveToNextEdge() {}
75         SUMOTime execute(SUMOTime currentTime);
76 
77     private:
78         MSContainer::MSContainerStage_Tranship& myParent;
79         MSTransportable* myContainer;
80     private:
81         /// @brief Invalidated assignment operator.
82         MoveToNextEdge& operator=(const MoveToNextEdge&);
83     };
84 
85 
86 private:
87     /// @brief the net to which to issue moveToNextEdge commands
88     MSNet* myNet;
89 
90 };
91 
92 class CState {
93 public:
CState()94     CState() {};
95 
~CState()96     ~CState() {};
97 
98     // @brief walking directions
99     static const int FORWARD;
100     static const int BACKWARD;
101     static const int UNDEFINED_DIRECTION;
102 
103     /// @brief the offset for computing container positions when being transhiped
104     static const double LATERAL_OFFSET;
105 
106     /// @brief return the offset from the start of the current edge measured in its natural direction
107     double getEdgePos(const MSContainer::MSContainerStage_Tranship& stage, SUMOTime now) const;
108     /// @brief return the network coordinate of the container
109     Position getPosition(const MSContainer::MSContainerStage_Tranship& stage, SUMOTime now) const;
110     /// @brief return the direction in which the container heading to
111     double getAngle(const MSContainer::MSContainerStage_Tranship& stage, SUMOTime now) const;
112     /// @brief return the current speed of the container
113     double getSpeed(const MSContainer::MSContainerStage_Tranship& stage) const;
114     /// @brief compute tranship time on edge and update state members
115     SUMOTime computeTranshipTime(const MSEdge* prev, const MSContainer::MSContainerStage_Tranship& stage, SUMOTime currentTime);
116 
117 
118 private:
119     SUMOTime myLastEntryTime;
120     SUMOTime myCurrentDuration;
121     double myCurrentBeginPos;
122     double myCurrentEndPos;
123     Position myCurrentBeginPosition;  //the position the container is moving from during its tranship stage
124     Position myCurrentEndPosition;  //the position the container is moving to during its tranship stage
125 
126 };
127 
128 
129 #endif /* MSCModel_NonInteracting_h */
130 
131