41 #ifndef NETWORKBUILDER_H_
42 #define NETWORKBUILDER_H_
45 #include "Properties.h"
46 #include "Utilities.h"
60 double lowerBound, upperBound;
63 ProbItem(
int i,
double lb,
double ub);
64 bool contains(
double val);
76 template<
typename V,
typename E,
typename Ec,
typename EcM>
80 static const std::string M;
94 template<
typename V,
typename E,
typename Ec,
typename EcM>
97 template<
typename V,
typename E,
typename Ec,
typename EcM>
106 for (
int i = 0; i < m; i++) {
107 V* source = activeNodes[i];
108 for (
int j = 0; j < m; j++) {
110 graph->
addEdge(source, (activeNodes[j]));
119 for (
int i = 0, n = activeNodes.size(); i < n; i++) {
120 V* target = activeNodes[i];
121 graph->
addEdge(source, target);
122 sum += 1.0 / graph->
inDegree(target);
125 std::vector<ProbItem> probItems;
126 double lowerBound = 0;
127 for (
int i = 0, n = activeNodes.size(); i < n; i++) {
128 V* node = activeNodes[i];
129 double upperBound = lowerBound + (1.0 / graph->
inDegree(node) / sum);
130 probItems.push_back(
ProbItem(i, lowerBound, upperBound));
131 lowerBound = upperBound;
135 for (
int i = 0, n = probItems.size(); i < n; i++) {
137 if (item.contains(p)) {
138 activeNodes.erase(activeNodes.begin() + item.index());
142 activeNodes.push_back(source);
double nextDouble()
Gets the current seed.
Definition: Random.cpp:96
vertex_iterator verticesEnd()
Gets the end of an iterator over all the vertices in this graph.
Definition: Graph.h:252
boost::transform_iterator< NodeGetter< V, E >, typename VertexMap::const_iterator > vertex_iterator
An iterator over the agents that are the vertices in this Graph.
Definition: Graph.h:100
vertex_iterator verticesBegin()
Gets the start of an iterator over all the vertices in this graph.
Definition: Graph.h:242
static Random * instance()
Gets the singleton instance of this Random.
Definition: Random.cpp:80
void build(repast::Properties &props, repast::Graph< V, E, Ec, EcM > *graph)
Builds the network.
Definition: NetworkBuilder.h:98
Helper class for calculating outcomes based on a set of probabilities that sum to 1.
Definition: NetworkBuilder.h:57
virtual boost::shared_ptr< E > addEdge(V *source, V *target)
Adds an edge between source and target to this Graph.
Definition: Graph.h:350
virtual int inDegree(V *vertex)
Gets the in-degree of the specified vertex.
Definition: Graph.h:402
std::string getProperty(const std::string &key) const
Gets the property with the specified key.
Definition: Properties.cpp:90
Map type object that contains key, value(string) properties.
Definition: Properties.h:77
Graph / Network implementation where agents are vertices in the graph.
Definition: Graph.h:72
Buils KE type networks.
Definition: NetworkBuilder.h:77