SUMO - Simulation of Urban MObility
ODMatrix.h
Go to the documentation of this file.
00001 /****************************************************************************/
00008 // An O/D (origin/destination) matrix
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 ODMatrix_h
00022 #define ODMatrix_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 <iostream>
00035 #include <sstream>
00036 #include <fstream>
00037 #include <vector>
00038 #include <cstdlib>
00039 #include <ctime>
00040 #include <algorithm>
00041 #include <string>
00042 #include <utils/common/SUMOTime.h>
00043 #include "ODCell.h"
00044 #include "ODDistrictCont.h"
00045 #include <utils/distribution/Distribution_Points.h>
00046 
00047 
00048 // ===========================================================================
00049 // class declarations
00050 // ===========================================================================
00051 class OutputDevice;
00052 
00053 
00054 // ===========================================================================
00055 // class definitions
00056 // ===========================================================================
00072 class ODMatrix {
00073 public:
00078     ODMatrix(const ODDistrictCont& dc) ;
00079 
00080 
00082     ~ODMatrix() ;
00083 
00084 
00106     void add(SUMOReal vehicleNumber, SUMOTime begin,
00107              SUMOTime end, const std::string& origin, const std::string& destination,
00108              const std::string& vehicleType) ;
00109 
00110 
00135     void write(SUMOTime begin, SUMOTime end,
00136                OutputDevice& dev, bool uniform, bool noVtype,
00137                const std::string& prefix, bool stepLog) ;
00138 
00139 
00146     SUMOReal getNoLoaded() const ;
00147 
00148 
00155     SUMOReal getNoWritten() const ;
00156 
00157 
00164     SUMOReal getNoDiscarded() const ;
00165 
00166 
00170     void applyCurve(const Distribution_Points& ps) ;
00171 
00172 
00173 protected:
00178     struct ODVehicle {
00180         std::string id;
00182         SUMOTime depart;
00184         ODCell* cell;
00186         std::string from;
00188         std::string to;
00189 
00190     };
00191 
00192 
00194     typedef std::vector<ODCell*> CellVector;
00195 
00196 
00221     SUMOReal computeDeparts(ODCell* cell,
00222                             size_t& vehName, std::vector<ODVehicle> &into, bool uniform,
00223                             const std::string& prefix) ;
00224 
00225 
00241     void applyCurve(const Distribution_Points& ps, ODCell* cell,
00242                     CellVector& newCells) ;
00243 
00244 
00245 protected:
00247     CellVector myContainer;
00248 
00250     const ODDistrictCont& myDistricts;
00251 
00253     SUMOReal myNoLoaded;
00254 
00256     SUMOReal myNoWritten;
00257 
00259     SUMOReal myNoDiscarded;
00260 
00261 
00266     class cell_by_begin_sorter {
00267     public:
00269         explicit cell_by_begin_sorter() { }
00270 
00271 
00282         int operator()(ODCell* p1, ODCell* p2) const {
00283             if (p1->begin == p2->begin) {
00284                 if (p1->origin == p2->origin) {
00285                     return p1->destination < p2->destination;
00286                 }
00287                 return p1->origin < p2->origin;
00288             }
00289             return p1->begin < p2->begin;
00290         }
00291 
00292     };
00293 
00294 
00302     class descending_departure_comperator {
00303     public:
00305         descending_departure_comperator() { }
00306 
00307 
00316         bool operator()(const ODVehicle& p1, const ODVehicle& p2) const {
00317             if (p1.depart == p2.depart) {
00318                 return p1.id > p2.id;
00319             }
00320             return p1.depart > p2.depart;
00321         }
00322 
00323     };
00324 
00325 private:
00327     ODMatrix(const ODMatrix& s);
00328 
00330     ODMatrix& operator=(const ODMatrix& s);
00331 
00332 };
00333 
00334 
00335 #endif
00336 
00337 /****************************************************************************/
00338 
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Defines