1 /****************************************************************************/
2 // Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.org/sumo
3 // Copyright (C) 2001-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    NIVissimDistrictConnection.h
11 /// @author  Daniel Krajzewicz
12 /// @author  Michael Behrisch
13 /// @date    End of 2002
14 /// @version $Id$
15 ///
16 // An edge imported from Vissim together for a container for
17 /****************************************************************************/
18 #ifndef NIVissimDistrictConnection_h
19 #define NIVissimDistrictConnection_h
20 
21 
22 // ===========================================================================
23 // included modules
24 // ===========================================================================
25 #include <config.h>
26 
27 #include <map>
28 #include <string>
29 #include <utils/geom/Position.h>
30 
31 
32 class NBDistrictCont;
33 class NBEdgeCont;
34 
35 
36 // ===========================================================================
37 // class definitions
38 // ===========================================================================
39 class NIVissimDistrictConnection {
40 public:
41     /// Contructor
42     NIVissimDistrictConnection(int id, const std::string& name,
43                                const std::vector<int>& districts, const std::vector<double>& percentages,
44                                int edgeid, double position,
45                                const std::vector<std::pair<int, int> >& assignedVehicles);
46 
47     // Destructor
48     ~NIVissimDistrictConnection();
49 
50     /** @brief Returns the position
51         The position yields from the edge geometry and the place the connection is plaed at */
52     Position geomPosition() const;
53 
54     /// Returns the id of the connection
getID()55     int getID() const {
56         return myID;
57     }
58 
59     /// Returns the position of the connection at the edge
getPosition()60     double getPosition() const {
61         return myPosition;
62     }
63 
64     double getMeanSpeed() const;
65 
66 public:
67     /// Inserts the connection into the dictionary after building it
68     static bool dictionary(int id, const std::string& name,
69                            const std::vector<int>& districts, const std::vector<double>& percentages,
70                            int edgeid, double position,
71                            const std::vector<std::pair<int, int> >& assignedVehicles);
72 
73     /// Inserts the build connection to the dictionary
74     static bool dictionary(int id, NIVissimDistrictConnection* o);
75 
76     /// Returns the named dictionary
77     static NIVissimDistrictConnection* dictionary(int id);
78 
79     /// Builds the nodes that belong to a district
80     static void dict_BuildDistrictNodes(NBDistrictCont& dc,
81                                         NBNodeCont& nc);
82 
83     /// Builds the districts
84     static void dict_BuildDistricts(NBDistrictCont& dc,
85                                     NBEdgeCont& ec, NBNodeCont& nc);
86 
87     /** @brief Returns the connection to a district placed at the given node
88         Yep, there onyl should be one, there is no need to build a single edge as connection between two parking places */
89     static NIVissimDistrictConnection* dict_findForEdge(int edgeid);
90 
91     /// Clears the dictionary
92     static void clearDict();
93 
94     static void dict_BuildDistrictConnections();
95 
96     static void dict_CheckEdgeEnds();
97 
98 
99 private:
100     void checkEdgeEnd();
101     double getRealSpeed(int distNo) const;
102 
103 private:
104     /// The id of the connections
105     int myID;
106 
107     /// The name of the connections
108     std::string myName;
109 
110     /// The connected districts
111     std::vector<int> myDistricts;
112 
113     /// Definition of a map of how many vehicles should leave to a certain district
114     typedef std::map<int, double> DistrictPercentages;
115 
116     /// A map how many vehicles (key, amount) should leave to a district (key)
117     DistrictPercentages myPercentages;
118 
119     /// The id of the connected edge
120     int myEdgeID;
121 
122     /// The position on the edge
123     double myPosition;
124 
125     /// The vehicles using this connection
126     std::vector<std::pair<int, int> > myAssignedVehicles;
127 
128 private:
129     /// Definition of a dictionary of district connections
130     typedef std::map<int, NIVissimDistrictConnection*> DictType;
131 
132     /// District connection dictionary
133     static DictType myDict;
134 
135     /// Map from ditricts to connections
136     static std::map<int, std::vector<int> > myDistrictsConnections;
137 
138 };
139 
140 
141 #endif
142 
143 /****************************************************************************/
144 
145