25 #include <boost/numeric/conversion/cast.hpp>
26 #include <boost/random/uniform_int.hpp>
34 #include "../exceptions.h"
36 #include "barabasi_albert.h"
39 namespace pagmo {
namespace topology {
50 m_m0(
boost::numeric_cast<
std::size_t>(m0)),m_m(
boost::numeric_cast<
std::size_t>(m)),
53 if (m0 < 2 || m < 1 || m > m0) {
54 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");
67 if (prev_size < m_m0) {
72 const double prob = 0.8;
74 bool connection_added =
false;
76 for (std::pair<v_iterator,v_iterator> vertices =
get_vertices(); vertices.first != vertices.second; ++vertices.first) {
78 if (*vertices.first != idx) {
79 if (m_drng() < prob) {
80 connection_added =
true;
89 if ((!connection_added) && (prev_size != 0)) {
95 rnd = uni_int(m_urng);
107 std::pair<v_iterator,v_iterator> vertices;
108 std::pair<a_iterator,a_iterator> adj_vertices;
112 pagmo_assert(n_edges > 0);
113 boost::uniform_int<edges_size_type> uni_int(0,n_edges - 1 - i);
122 for (; vertices.first != vertices.second; ++vertices.first) {
124 if (*vertices.first != idx) {
126 n += boost::numeric_cast<
edges_size_type>(std::distance(adj_vertices.first,adj_vertices.second));
133 pagmo_assert(vertices.first != vertices.second);
152 std::ostringstream oss;
153 oss <<
"\tm0 = " << m_m0 <<
'\n';
154 oss <<
"\tm = " << m_m <<
'\n';
160 return "Barabasi-Albert";
Generic thread-safe generator of pseudo-random number generators.
base_ptr clone() const
Clone method.
boost::shared_ptr< base > base_ptr
Alias for shared pointer to base topology.
void connect(const vertices_size_type &)
Establish connections between islands during a push_back() operation.
This rng returns an unsigned integer in the [0,2**32-1] range.
graph_type::edges_size_type edges_size_type
Edges size type.
std::string get_name() const
Get name of the topology.
std::string human_readable_extra() const
Topology-specific human readable info.
vertices_size_type get_number_of_vertices() const
Get number of vertices.
graph_type::vertices_size_type vertices_size_type
Vertices size type.
Barabási-Albert graph topology.
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.
barabasi_albert(int m0=3, int m=2)
Constructor from kernel size and number of edges.
This rng returns a double in the [0,1[ range.
std::pair< v_iterator, v_iterator > get_vertices() const
Return iterator range to vertices.
bool are_adjacent(const vertices_size_type &, const vertices_size_type &) const
Return true if two vertices are adjacent.