HavoqGT
havoqgt::detail::preferential_attachment_helper< DUMMY > Class Template Reference

#include <preferential_attachment.hpp>

Public Types

typedef uint64_t vertex_descriptor
 
typedef std::pair< uint64_t, uint64_t > edge_type
 

Public Member Functions

 preferential_attachment_helper (uint64_t k, uint64_t m, double beta, uint64_t rng_seed=5489)
 
edge_type gen_edge (uint64_t _edge_index)
 
uint64_t calc_source (uint64_t i)
 
uint64_t calc_target (uint64_t i)
 
vertex_descriptor make_pointer (vertex_descriptor i)
 
bool is_pointer (vertex_descriptor i)
 
uint64_t value_of_pointer (vertex_descriptor i, uint64_t _num_partitions=1)
 

Private Attributes

boost::random::mt19937 m_rng
 
uint64_t m_k
 
uint64_t m_koffset
 
vertex_descriptor m_ptr_mask
 
uint64_t m_num_edges
 
double m_alpha
 

Detailed Description

template<typename DUMMY = uint64_t>
class havoqgt::detail::preferential_attachment_helper< DUMMY >

Definition at line 63 of file preferential_attachment.hpp.

Member Typedef Documentation

template<typename DUMMY = uint64_t>
typedef std::pair<uint64_t,uint64_t> havoqgt::detail::preferential_attachment_helper< DUMMY >::edge_type

Definition at line 66 of file preferential_attachment.hpp.

template<typename DUMMY = uint64_t>
typedef uint64_t havoqgt::detail::preferential_attachment_helper< DUMMY >::vertex_descriptor

Definition at line 65 of file preferential_attachment.hpp.

Constructor & Destructor Documentation

template<typename DUMMY = uint64_t>
havoqgt::detail::preferential_attachment_helper< DUMMY >::preferential_attachment_helper ( uint64_t  k,
uint64_t  m,
double  beta,
uint64_t  rng_seed = 5489 
)
inline

Definition at line 68 of file preferential_attachment.hpp.

69  : m_rng(rng_seed)
70  {
71  m_k = k;
72  m_num_edges = m;
73  m_koffset = m_k*(m_k+1)/2;
74  m_ptr_mask = ~(std::numeric_limits<vertex_descriptor>::max() >> 1);
75  m_alpha = (beta / double(m_k) + double(1)) / (beta / double(m_k) + 2);
76  //std::cout << "beta = " << beta << ", alpha = " << m_alpha << std::endl;
77  }

Member Function Documentation

template<typename DUMMY = uint64_t>
uint64_t havoqgt::detail::preferential_attachment_helper< DUMMY >::calc_source ( uint64_t  i)
inline

Definition at line 107 of file preferential_attachment.hpp.

107  {
108  uint64_t to_return;
109  if(i+1>m_koffset) {
110  to_return = ((i-m_koffset)/m_k)+m_k+1;
111  } else {
112  to_return = (uint64_t) floor(double(-0.5f) +
113  sqrt(double(0.25f)+double(2)*double(i))+1);
114  }
115  return to_return;
116  }

Here is the caller graph for this function:

template<typename DUMMY = uint64_t>
uint64_t havoqgt::detail::preferential_attachment_helper< DUMMY >::calc_target ( uint64_t  i)
inline

Definition at line 119 of file preferential_attachment.hpp.

119  {
120  uint64_t to_return;
121  if(i+1>m_koffset) {
122  assert(false);
123  to_return = i;
124  } else {
125  double tmp = double(-0.5f) + sqrt(double(0.25f)+double(2)*double(i))+1;
126  to_return = (uint64_t) ((tmp - floor(tmp)) * floor(tmp));
127  }
128  return to_return;
129  }

Here is the caller graph for this function:

template<typename DUMMY = uint64_t>
edge_type havoqgt::detail::preferential_attachment_helper< DUMMY >::gen_edge ( uint64_t  _edge_index)
inline

Definition at line 79 of file preferential_attachment.hpp.

79  {
80  edge_type to_return;
81  to_return.first = calc_source(_edge_index);
82  if(_edge_index >= m_koffset) {
83  //
84  // Generate random edge_list location based on beta model
85  boost::random::uniform_01<boost::random::mt19937> rand_prob(m_rng);
86  boost::random::uniform_int_distribution<uint64_t> uid(0,_edge_index-1);
87  uint64_t rand = uid(m_rng) * 2;
88  if(rand_prob() > m_alpha) {
89  ++rand;
90  }
91  if(rand % 2 == 0) { //this is a source vertex, we can calc!
92  to_return.second = calc_source(rand/2);
93  } else {
94  uint64_t edge_rand = rand/2;
95  if(edge_rand < m_koffset) { //this is an early edge we can calc!
96  to_return.second = calc_target(edge_rand);
97  } else {
98  to_return.second = make_pointer(edge_rand);
99  }
100  }
101  } else {
102  to_return.second = calc_target(_edge_index);
103  }
104  return to_return;
105  }
vertex_descriptor make_pointer(vertex_descriptor i)

Here is the call graph for this function:

template<typename DUMMY = uint64_t>
bool havoqgt::detail::preferential_attachment_helper< DUMMY >::is_pointer ( vertex_descriptor  i)
inline

Definition at line 135 of file preferential_attachment.hpp.

135  {
136  return (i & m_ptr_mask) > 0;
137  }
template<typename DUMMY = uint64_t>
vertex_descriptor havoqgt::detail::preferential_attachment_helper< DUMMY >::make_pointer ( vertex_descriptor  i)
inline

Definition at line 131 of file preferential_attachment.hpp.

131  {
132  return i | m_ptr_mask;
133  }

Here is the caller graph for this function:

template<typename DUMMY = uint64_t>
uint64_t havoqgt::detail::preferential_attachment_helper< DUMMY >::value_of_pointer ( vertex_descriptor  i,
uint64_t  _num_partitions = 1 
)
inline

Definition at line 140 of file preferential_attachment.hpp.

140  {
141  i = i & ~m_ptr_mask;
142  uint64_t my_partition = i%_num_partitions;
143  uint64_t my_partition_offset = i/_num_partitions;
144  uint64_t edges_per_partition = m_num_edges / _num_partitions;
145  return my_partition * edges_per_partition + my_partition_offset;
146  }

Member Data Documentation

template<typename DUMMY = uint64_t>
double havoqgt::detail::preferential_attachment_helper< DUMMY >::m_alpha
private

Definition at line 155 of file preferential_attachment.hpp.

template<typename DUMMY = uint64_t>
uint64_t havoqgt::detail::preferential_attachment_helper< DUMMY >::m_k
private

Definition at line 151 of file preferential_attachment.hpp.

template<typename DUMMY = uint64_t>
uint64_t havoqgt::detail::preferential_attachment_helper< DUMMY >::m_koffset
private

Definition at line 152 of file preferential_attachment.hpp.

template<typename DUMMY = uint64_t>
uint64_t havoqgt::detail::preferential_attachment_helper< DUMMY >::m_num_edges
private

Definition at line 154 of file preferential_attachment.hpp.

template<typename DUMMY = uint64_t>
vertex_descriptor havoqgt::detail::preferential_attachment_helper< DUMMY >::m_ptr_mask
private

Definition at line 153 of file preferential_attachment.hpp.

template<typename DUMMY = uint64_t>
boost::random::mt19937 havoqgt::detail::preferential_attachment_helper< DUMMY >::m_rng
private

Definition at line 150 of file preferential_attachment.hpp.


The documentation for this class was generated from the following file: