SUMO - Simulation of Urban MObility
RONet.h
Go to the documentation of this file.
00001 /****************************************************************************/
00008 // The router's network representation
00009 /****************************************************************************/
00010 // SUMO, Simulation of Urban MObility; see http://sumo.sourceforge.net/
00011 // Copyright (C) 2001-2012 DLR (http://www.dlr.de/) and contributors
00012 /****************************************************************************/
00013 //
00014 //   This file is part of SUMO.
00015 //   SUMO is free software: you can redistribute it and/or modify
00016 //   it under the terms of the GNU General Public License as published by
00017 //   the Free Software Foundation, either version 3 of the License, or
00018 //   (at your option) any later version.
00019 //
00020 /****************************************************************************/
00021 #ifndef RONet_h
00022 #define RONet_h
00023 
00024 
00025 // ===========================================================================
00026 // included modules
00027 // ===========================================================================
00028 #ifdef _MSC_VER
00029 #include <windows_config.h>
00030 #else
00031 #include <config.h>
00032 #endif
00033 
00034 #include <string>
00035 #include <set>
00036 #include <fstream>
00037 #include <deque>
00038 #include <vector>
00039 #include "ROEdge.h"
00040 #include "RONode.h"
00041 #include "ROVehicleCont.h"
00042 #include "ROVehicle.h"
00043 #include "RORouteDef.h"
00044 #include <utils/common/SUMOVTypeParameter.h>
00045 #include <utils/common/SUMOAbstractRouter.h>
00046 
00047 
00048 // ===========================================================================
00049 // class declarations
00050 // ===========================================================================
00051 class RONode;
00052 class RORouteDef;
00053 class OptionsCont;
00054 class OutputDevice;
00055 
00056 
00057 // ===========================================================================
00058 // class definitions
00059 // ===========================================================================
00068 class RONet {
00069     friend class RouteAggregator;
00070 
00071 public:
00073     RONet() ;
00074 
00075 
00077     virtual ~RONet() ;
00078 
00079 
00081 
00082 
00083     /* @brief Adds a read edge to the network
00084      *
00085      * If the edge is already known (another one with the same id exists),
00086      *  an error is generated and given to msg-error-handler. The edge
00087      *  is deleted in this case and false is returned.
00088      *
00089      * @param[in] edge The edge to add
00090      * @return Whether the edge was added (if not, it was deleted, too)
00091      */
00092     virtual bool addEdge(ROEdge* edge) ;
00093 
00094 
00104     ROEdge* getEdge(const std::string& name) const {
00105         return myEdges.get(name);
00106     }
00107 
00108 
00109     /* @brief Adds a read node to the network
00110      *
00111      * If the node is already known (another one with the same id exists),
00112      *  an error is generated and given to msg-error-handler. The node
00113      *  is deleted in this case
00114      *
00115      * @param[in] node The node to add
00116      */
00117     void addNode(RONode* node) ;
00118 
00119 
00126     RONode* getNode(const std::string& id) const {
00127         return myNodes.get(id);
00128     }
00130 
00131 
00132 
00134 
00135 
00136     /* @brief Adds a read vehicle type definition to the network
00137      *
00138      * If the vehicle type definition is already known (another one with
00139      *  the same id exists), false is returned, and the vehicle type
00140      *  is deleted.
00141      *
00142      * @param[in] def The vehicle type to add
00143      * @return Whether the vehicle type could be added
00144      */
00145     virtual bool addVehicleType(SUMOVTypeParameter* type) ;
00146 
00147 
00160     SUMOVTypeParameter* getVehicleTypeSecure(const std::string& id) ;
00161 
00162 
00163     /* @brief Adds a route definition to the network
00164      *
00165      * If the route definition is already known (another one with
00166      *  the same id exists), false is returned, but the route definition
00167      *  is not deleted.
00168      *
00169      * @param[in] def The route definition to add
00170      * @return Whether the route definition could be added
00171      * @todo Rename myRoutes to myRouteDefinitions
00172      */
00173     bool addRouteDef(RORouteDef* def) ;
00174 
00175 
00183     RORouteDef* getRouteDef(const std::string& name) const {
00184         return myRoutes.get(name);
00185     }
00186 
00187 
00188     /* @brief Adds a vehicle to the network
00189      *
00190      * If the vehicle is already known (another one with the same id
00191      *  exists), false is returned, but the vehicle is not deleted.
00192      *
00193      * Otherwise, the number of loaded routes ("myReadRouteNo") is increased.
00194      *
00195      * @param[in] id The id of the vehicle to add
00196      * @param[in] veh The vehicle to add
00197      * @return Whether the vehicle could be added
00198      */
00199     virtual bool addVehicle(const std::string& id, ROVehicle* veh) ;
00200     // @}
00201 
00202 
00203 
00205 
00206 
00218     SUMOTime saveAndRemoveRoutesUntil(OptionsCont& options,
00219                                       SUMOAbstractRouter<ROEdge, ROVehicle> &router, SUMOTime time);
00220 
00221 
00223     virtual bool furtherStored();
00225 
00226 
00227 
00228 
00229 
00241     void openOutput(const std::string& filename, bool useAlternatives, const std::string& typefilename);
00242 
00243 
00245     void closeOutput() ;
00246 
00247 
00248 
00249 
00256     ROEdge* getRandomSource() ;
00257 
00258 
00265     const ROEdge* getRandomSource() const ;
00266 
00267 
00274     ROEdge* getRandomDestination() ;
00275 
00276 
00283     const ROEdge* getRandomDestination() const ;
00284 
00285 
00287     unsigned int getEdgeNo() const;
00288 
00289     const std::map<std::string, ROEdge*> &getEdgeMap() const;
00290 
00291     bool hasRestrictions() const;
00292 
00293     void setRestrictionFound();
00294 
00295 protected:
00296     bool computeRoute(OptionsCont& options,
00297                       SUMOAbstractRouter<ROEdge, ROVehicle> &router, const ROVehicle* const veh);
00298 
00300     void checkSourceAndDestinations() const;
00301 
00302 
00304     ROVehicleCont& getVehicles() {
00305         return myVehicles;
00306     }
00307 
00308 
00309 protected:
00311     std::set<std::string> myVehIDs;
00312 
00314     NamedObjectCont<RONode*> myNodes;
00315 
00317     NamedObjectCont<ROEdge*> myEdges;
00318 
00320     NamedObjectCont<SUMOVTypeParameter*> myVehicleTypes;
00321 
00323     bool myDefaultVTypeMayBeDeleted;
00324 
00326     NamedObjectCont<RORouteDef*> myRoutes;
00327 
00329     ROVehicleCont myVehicles;
00330 
00332     mutable std::vector<ROEdge*> mySourceEdges;
00333 
00335     mutable std::vector<ROEdge*> myDestinationEdges;
00336 
00338     OutputDevice* myRoutesOutput;
00339 
00341     OutputDevice* myRouteAlternativesOutput;
00342 
00344     OutputDevice* myTypesOutput;
00345 
00347     unsigned int myReadRouteNo;
00348 
00350     unsigned int myDiscardedRouteNo;
00351 
00353     unsigned int myWrittenRouteNo;
00354 
00356     bool myHaveRestrictions;
00357 
00358 
00359 private:
00361     RONet(const RONet& src);
00362 
00364     RONet& operator=(const RONet& src);
00365 
00366 };
00367 
00368 
00369 #endif
00370 
00371 /****************************************************************************/
00372 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines