Eclipse SUMO - Simulation of Urban MObility
Loading...
Searching...
No Matches
ODDistrict.cpp
Go to the documentation of this file.
1/****************************************************************************/
2// Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3// Copyright (C) 2002-2024 German Aerospace Center (DLR) and others.
4// This program and the accompanying materials are made available under the
5// terms of the Eclipse Public License 2.0 which is available at
6// https://www.eclipse.org/legal/epl-2.0/
7// This Source Code may also be made available under the following Secondary
8// Licenses when the conditions for such availability set forth in the Eclipse
9// Public License 2.0 are satisfied: GNU General Public License, version 2
10// or later which is available at
11// https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13/****************************************************************************/
20// A district (origin/destination)
21/****************************************************************************/
22#include <config.h>
23
24#include <vector>
25#include <string>
26#include <utility>
28#include <utils/common/Named.h>
30#include "ODDistrict.h"
31
32
33
34// ===========================================================================
35// method definitions
36// ===========================================================================
37ODDistrict::ODDistrict(const std::string& id)
38 : Named(id) {}
39
40
42
43
44void
45ODDistrict::addSource(const std::string& id, double weight) {
46 mySources.add(id, weight, false);
47}
48
49
50void
51ODDistrict::addSink(const std::string& id, double weight) {
52 mySinks.add(id, weight, false);
53}
54
55
56std::string
58 return mySources.get();
59}
60
61
62std::string
64 return mySinks.get();
65}
66
67
68int
70 return (int) mySinks.getVals().size();
71}
72
73
74int
76 return (int) mySources.getVals().size();
77}
78
79
80/****************************************************************************/
Base class for objects which have an id.
Definition Named.h:54
int sourceNumber() const
Returns the number of sources.
~ODDistrict()
Destructor.
RandomDistributor< std::string > mySources
Container of weighted sources.
Definition ODDistrict.h:125
void addSource(const std::string &id, double weight)
Adds a source connection.
RandomDistributor< std::string > mySinks
Container of weighted sinks.
Definition ODDistrict.h:128
void addSink(const std::string &id, double weight)
Adds a sink connection.
ODDistrict(const std::string &id)
Constructor.
int sinkNumber() const
Returns the number of sinks.
std::string getRandomSink() const
Returns the id of a sink to use.
std::string getRandomSource() const
Returns the id of a source to use.
T get(SumoRNG *which=nullptr) const
Draw a sample of the distribution.
bool add(T val, double prob, bool checkDuplicates=true)
Adds a value with an assigned probability to the distribution.
const std::vector< T > & getVals() const
Returns the members of the distribution.