25 #include <boost/numeric/conversion/cast.hpp>
26 #include <boost/random/uniform_int.hpp>
34 #include "../exceptions.h"
36 #include "ageing_clustered_ba.h"
39 namespace pagmo {
namespace topology {
55 m_m0(
boost::numeric_cast<
std::size_t>(m0)),m_m(
boost::numeric_cast<
std::size_t>(m)), m_p(double(p)), m_a(int(a)),
58 if (m0 < 2 || m < 1 || m > m0) {
59 pagmo_throw(value_error,
"the value of m and m0 must be at least 1 and 2, and m must not be greater than m0");
62 pagmo_throw(value_error,
"the value a must be greater than the value of m");
65 pagmo_throw(value_error,
"the value of p must be between 0 and 1");
79 if (prev_size < m_m0) {
84 const double prob = 0.0;
86 bool connection_added =
false;
88 for (std::pair<v_iterator,v_iterator> vertices =
get_vertices(); vertices.first != vertices.second; ++vertices.first) {
90 if (*vertices.first != idx) {
91 if (m_drng() < prob) {
92 connection_added =
true;
101 if ((!connection_added) && (prev_size != 0)) {
107 rnd = uni_int(m_urng);
108 }
while (rnd == idx);
119 boost::uniform_int<edges_size_type> uni_int2(1,m_m);
121 std::size_t j = uni_int2(m_urng);
122 std::pair<v_iterator,v_iterator> vertices;
123 std::pair<a_iterator,a_iterator> adj_vertices;
127 for(; vertices.first != vertices.second; ++vertices.first) {
128 int a = *vertices.first;
137 pagmo_assert(n_edges > 0);
138 boost::uniform_int<edges_size_type> uni_int(min_n_edges,n_edges - 1 - i);
147 for (; vertices.first != vertices.second; ++vertices.first) {
149 if (*vertices.first != idx) {
151 n += boost::numeric_cast<
edges_size_type>(std::distance(adj_vertices.first,adj_vertices.second));
157 pagmo_assert(vertices.first != vertices.second);
163 for(;adj_vertices.first != adj_vertices.second; ++adj_vertices.first) {
164 if(m_drng() < m_p && *adj_vertices.first != *vertices.first && !
are_adjacent(*adj_vertices.first,*vertices.first)) {
165 add_edge(*adj_vertices.first, *vertices.first);
166 add_edge(*vertices.first, *adj_vertices.first);
187 std::ostringstream oss;
188 oss <<
"\tm0 = " << m_m0 <<
'\n';
189 oss <<
"\tm = " << m_m <<
'\n';
190 oss <<
"\tp = " << m_p <<
'\n';
191 oss <<
"\ta = " << m_a <<
'\n';
197 return "Ageing Clustered Barabasi-Albert";
Generic thread-safe generator of pseudo-random number generators.
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base topology.
This rng returns an unsigned integer in the [0,2**32-1] range.
graph_type::edges_size_type edges_size_type
Edges size type.
Clustered Barabási-Albert with Ageing vertices graph topology.
void connect(const vertices_size_type &)
Establish connections between islands during a push_back() operation.
std::string human_readable_extra() const
Topology-specific human readable info.
vertices_size_type get_number_of_vertices() const
Get number of vertices.
base_ptr clone() const
Clone method.
graph_type::vertices_size_type vertices_size_type
Vertices size type.
ageing_clustered_ba(int m0=3, int m=2, double p=0.5, int a=1000)
Constructor from kernel size, maximum number of edges, connection probability and maximum node age...
edges_size_type get_num_adjacent_vertices(const vertices_size_type &) const
Return the number of adjacent vertices.
void add_edge(const vertices_size_type &, const vertices_size_type &)
Add an edge.
edges_size_type get_number_of_edges() const
Get number of edges.
std::pair< a_iterator, a_iterator > get_adjacent_vertices(const vertices_size_type &) const
Return iterator range to adjacent vertices.
This rng returns a double in the [0,1[ range.
std::pair< v_iterator, v_iterator > get_vertices() const
Return iterator range to vertices.
std::string get_name() const
Get name of the topology.
bool are_adjacent(const vertices_size_type &, const vertices_size_type &) const
Return true if two vertices are adjacent.