DegreeDistributionConnections.cpp

Go to the documentation of this file.
00001 
00011 #include "DegreeDistributionConnections.h"
00012 
00013 DegreeDistributionConnections::DegreeDistributionConnections( RandomDistribution const& degreeDistribution, DegreeType degreeType) :
00014         dist(NULL),
00015         degree_type(degreeType)
00016 {
00017     dist = degreeDistribution.clone();
00018 }
00019 
00020 DegreeDistributionConnections::~DegreeDistributionConnections()
00021 {
00022     if( dist ) delete dist;
00023 }
00024 
00025 
00026 void DegreeDistributionConnections::init(const SimObjectPopulation &srcPopulation, const SimObjectPopulation &destPopulation)
00027 {
00028     src_popul = &srcPopulation;
00029     dest_popul = &destPopulation;
00030 }
00031 
00032 
00033 void DegreeDistributionConnections::reset(
00034     SimObject::ID::SortedVector::const_iterator src_begin_it,
00035     SimObject::ID::SortedVector::const_iterator src_end_it,
00036     SimObject::ID::SortedVector::const_iterator dest_begin_it,
00037     SimObject::ID::SortedVector::const_iterator dest_end_it)
00038 {
00039     if (degree_type == incoming) {
00040         from_begin_it = src_begin_it;
00041         from_seq_size = src_end_it - src_begin_it;
00042         curr_to_it = dest_begin_it;
00043         to_end_it = dest_end_it;
00044     } else {
00045         from_begin_it = dest_begin_it;
00046         from_seq_size = dest_end_it - dest_begin_it;
00047         curr_to_it = src_begin_it;
00048         to_end_it = src_end_it;
00049     }
00050 
00051     curr_degree = (unsigned)round((*dist)(*m_rnd_eng));
00052 
00053     curr_made_connections = 0;
00054 
00055     if (curr_degree >= from_seq_size) {
00056         throw PCSIM::ConstructionException("DegreeDistributionConnections::initGenerateConnections" , "Degree generated by distribution is larger than srcPopulation size");
00057     }
00058     nonrepeat_rng.reset(0, from_seq_size - 1, curr_degree);
00059 }
00060 
00061 bool DegreeDistributionConnections::next( pair<SimObject::ID, SimObject::ID> &conn_pair )
00062 {
00063     last_conn_valid = false;
00064 
00065     if (curr_made_connections == curr_degree) {
00066         curr_to_it ++;
00067         if (curr_to_it == to_end_it)
00068             return false;
00069 
00070         curr_degree =  (unsigned)round((*dist)(*m_rnd_eng));
00071         if (curr_degree >= from_seq_size) {
00072             throw PCSIM::ConstructionException("DegreeDistributionConnections::initGenerateConnections" , "Degree generated by distribution is larger than srcPopulation size");
00073         }
00074         nonrepeat_rng.reset(curr_degree);
00075         curr_made_connections = 0;
00076     }
00077 
00078     do {
00079         int from_idx = nonrepeat_rng(*m_rnd_eng);
00080         if (degree_type == incoming) {
00081             last_conn_idx.first = *(from_begin_it + from_idx);
00082             conn_pair.first = (*src_popul).getID(last_conn_idx.first);
00083 
00084             last_conn_idx.second = *curr_to_it;
00085             conn_pair.second = (*dest_popul).getID(last_conn_idx.second);
00086         } else {
00087             last_conn_idx.first = *curr_to_it;
00088             conn_pair.first = (*src_popul).getID(last_conn_idx.first);
00089 
00090             last_conn_idx.second = *(from_begin_it + from_idx);
00091             conn_pair.second = (*dest_popul).getID(last_conn_idx.second);
00092         }
00093     } while (conn_pair.first == conn_pair.second);
00094 
00095     curr_made_connections++;
00096 
00097     last_conn_valid = true;
00098 
00099     return true;
00100 }

Generated on Wed Jul 9 16:34:37 2008 for PCSIM by  doxygen 1.5.5