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    ROMAAssignments.h
11 /// @author  Yun-Pang Floetteroed
12 /// @author  Laura Bieker
13 /// @author  Michael Behrisch
14 /// @date    Feb 2013
15 /// @version $Id$
16 ///
17 // Assignment methods
18 /****************************************************************************/
19 #ifndef ROMAAssignments_h
20 #define ROMAAssignments_h
21 
22 
23 // ===========================================================================
24 // included modules
25 // ===========================================================================
26 #include <config.h>
27 
28 #include <utils/router/SUMOAbstractRouter.h>
29 #include <utils/common/SUMOTime.h>
30 
31 // ===========================================================================
32 // class declarations
33 // ===========================================================================
34 class RONet;
35 class ODMatrix;
36 class Distribution_Points;
37 class ROEdge;
38 class ROMAEdge;
39 class ROVehicle;
40 
41 
42 
43 // ===========================================================================
44 // class definitions
45 // ===========================================================================
46 /**
47  * @class ROMAAssignments
48  * @brief assignment methods
49  *
50  */
51 class ROMAAssignments {
52 public:
53     /// Constructor
54     ROMAAssignments(const SUMOTime begin, const SUMOTime end, const bool additiveTraffic,
55                     const double adaptionFactor, const int maxAlternatives,
56                     RONet& net, ODMatrix& matrix, SUMOAbstractRouter<ROEdge, ROVehicle>& router);
57 
58     /// Destructor
59     ~ROMAAssignments();
60 
getDefaultVehicle()61     ROVehicle* getDefaultVehicle() {
62         return myDefaultVehicle;
63     }
64 
65     // @brief calculate edge capacity for the given edge
66     static double getCapacity(const ROEdge* edge);
67 
68     // @brief calculate edge travel time for the given edge and number of vehicles per hour
69     double capacityConstraintFunction(const ROEdge* edge, const double flow) const;
70 
71     // @brief clear effort storage
72     void resetFlows();
73 
74     // @brief incremental method
75     void incremental(const int numIter, const bool verbose);
76 
77     // @brief UE method
78     void ue();
79 
80     // @brief SUE method
81     void sue(const int maxOuterIteration, const int maxInnerIteration, const int kPaths, const double penalty, const double tolerance, const std::string routeChoiceMethod);
82 
83     /** @brief Returns the effort to pass an edge including penalties
84      *
85      * This method is given to the used router in order to obtain the efforts
86      *  to pass an edge from the internal edge weights container.
87      *
88      * @param[in] e The edge for which the effort to be passed shall be returned
89      * @param[in] v The (default) vehicle that is routed
90      * @param[in] t The time for which the effort shall be returned
91      * @return The effort (time to pass in this case) for an edge
92      * @see DijkstraRouter_ByProxi
93      */
94     static double getPenalizedEffort(const ROEdge* const e, const ROVehicle* const v, double t);
95 
96     /** @brief Returns the traveltime on an edge including penalties
97      *
98      * This method is given to the used router in order to obtain the efforts
99      *  to pass an edge from the internal edge weights container.
100      *
101      * @param[in] e The edge for which the effort to be passed shall be returned
102      * @param[in] v The (default) vehicle that is routed
103      * @param[in] t The time for which the effort shall be returned
104      * @return The effort (time to pass in this case) for an edge
105      * @see DijkstraRouter_ByProxi
106      */
107     static double getPenalizedTT(const ROEdge* const e, const ROVehicle* const v, double t);
108 
109     /** @brief Returns the traveltime on an edge without penalties
110      *
111      * This method is given to the used router in order to obtain the efforts
112      *  to pass an edge from the internal edge weights container.
113      *
114      * @param[in] e The edge for which the effort to be passed shall be returned
115      * @param[in] v The (default) vehicle that is routed
116      * @param[in] t The time for which the effort shall be returned
117      * @return The effort (time to pass in this case) for an edge
118      * @see DijkstraRouter_ByProxi
119      */
120     static double getTravelTime(const ROEdge* const e, const ROVehicle* const v, double t);
121 
122 private:
123     /// @brief add a route and check for duplicates
124     bool addRoute(const ConstROEdgeVector& edges, std::vector<RORoute*>& paths, std::string routeId, double prob);
125 
126     const ConstROEdgeVector computePath(ODCell* cell, const SUMOTime time = 0, const double probability = 0., SUMOAbstractRouter<ROEdge, ROVehicle>* router = nullptr);
127 
128     /// @brief get the k shortest paths
129     void getKPaths(const int kPaths, const double penalty);
130 
131 private:
132     const SUMOTime myBegin;
133     const SUMOTime myEnd;
134     const bool myAdditiveTraffic;
135     const double myAdaptionFactor;
136     const int myMaxAlternatives;
137     RONet& myNet;
138     ODMatrix& myMatrix;
139     SUMOAbstractRouter<ROEdge, ROVehicle>& myRouter;
140     static std::map<const ROEdge* const, double> myPenalties;
141     ROVehicle* myDefaultVehicle;
142 
143 #ifdef HAVE_FOX
144 private:
145     class RoutingTask : public FXWorkerThread::Task {
146     public:
RoutingTask(ROMAAssignments & assign,ODCell * c,const SUMOTime begin,const double linkFlow)147         RoutingTask(ROMAAssignments& assign, ODCell* c, const SUMOTime begin, const double linkFlow)
148             : myAssign(assign), myCell(c), myBegin(begin), myLinkFlow(linkFlow) {}
149         void run(FXWorkerThread* context);
150     private:
151         ROMAAssignments& myAssign;
152         ODCell* const myCell;
153         const SUMOTime myBegin;
154         const double myLinkFlow;
155     private:
156         /// @brief Invalidated assignment operator.
157         RoutingTask& operator=(const RoutingTask&);
158     };
159 #endif
160 
161 
162 private:
163     /// @brief Invalidated assignment operator
164     ROMAAssignments& operator=(const ROMAAssignments& src);
165 
166 };
167 
168 #endif
169