SUMO - Simulation of Urban MObility
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
ODDistrict.cpp
Go to the documentation of this file.
1 /****************************************************************************/
9 // A district (origin/destination)
10 /****************************************************************************/
11 // SUMO, Simulation of Urban MObility; see http://sumo.dlr.de/
12 // Copyright (C) 2002-2015 DLR (http://www.dlr.de/) and contributors
13 /****************************************************************************/
14 //
15 // This file is part of SUMO.
16 // SUMO is free software: you can redistribute it and/or modify
17 // it under the terms of the GNU General Public License as published by
18 // the Free Software Foundation, either version 3 of the License, or
19 // (at your option) any later version.
20 //
21 /****************************************************************************/
22 
23 
24 // ===========================================================================
25 // included modules
26 // ===========================================================================
27 #ifdef _MSC_VER
28 #include <windows_config.h>
29 #else
30 #include <config.h>
31 #endif
32 
33 #include <vector>
34 #include <string>
35 #include <utility>
37 #include <utils/common/Named.h>
39 #include "ODDistrict.h"
40 
41 
42 #ifdef CHECK_MEMORY_LEAKS
43 #include <foreign/nvwa/debug_new.h>
44 #endif // CHECK_MEMORY_LEAKS
45 
46 
47 // ===========================================================================
48 // method definitions
49 // ===========================================================================
50 ODDistrict::ODDistrict(const std::string& id)
51  : Named(id) {}
52 
53 
55 
56 
57 void
58 ODDistrict::addSource(const std::string& id, SUMOReal weight) {
59  mySources.add(weight, id);
60 }
61 
62 
63 void
64 ODDistrict::addSink(const std::string& id, SUMOReal weight) {
65  mySinks.add(weight, id);
66 }
67 
68 
69 std::string
71  return mySources.get();
72 }
73 
74 
75 std::string
77  return mySinks.get();
78 }
79 
80 
81 unsigned int
83  return (unsigned int) mySinks.getVals().size();
84 }
85 
86 
87 unsigned int
89  return (unsigned int) mySources.getVals().size();
90 }
91 
92 
93 
94 /****************************************************************************/
95 
std::string getRandomSource() const
Returns the id of a source to use.
Definition: ODDistrict.cpp:70
bool add(SUMOReal prob, T val, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
~ODDistrict()
Destructor.
Definition: ODDistrict.cpp:54
ODDistrict(const std::string &id)
Constructor.
Definition: ODDistrict.cpp:50
void addSink(const std::string &id, SUMOReal weight)
Adds a sink connection.
Definition: ODDistrict.cpp:64
const std::vector< T > & getVals() const
Returns the members of the distribution.
unsigned int sinkNumber() const
Returns the number of sinks.
Definition: ODDistrict.cpp:82
RandomDistributor< std::string > mySinks
Container of weighted sinks.
Definition: ODDistrict.h:138
void addSource(const std::string &id, SUMOReal weight)
Adds a source connection.
Definition: ODDistrict.cpp:58
RandomDistributor< std::string > mySources
Container of weighted sources.
Definition: ODDistrict.h:135
std::string getRandomSink() const
Returns the id of a sink to use.
Definition: ODDistrict.cpp:76
T get(MTRand *which=0) const
Draw a sample of the distribution.
unsigned int sourceNumber() const
Returns the number of sources.
Definition: ODDistrict.cpp:88
Base class for objects which have an id.
Definition: Named.h:45
#define SUMOReal
Definition: config.h:218