EuclideanDistanceRandomConnections.cpp

Go to the documentation of this file.
00001 
00011 #include "EuclideanDistanceRandomConnections.h"
00012 #include <iostream>
00013 using std::cerr;
00014 using std::endl;
00015 
00016 #include <typeinfo>
00017 using std::type_info;
00018 
00019 EuclideanDistanceRandomConnections::EuclideanDistanceRandomConnections( const double C, const double lambda )
00020         : maxConnProb(C), lambda(lambda), unirnd(UniformDistribution(0,1)) {
00021     /* NOOP */
00022 }
00023 
00024 
00025 EuclideanDistanceRandomConnections::EuclideanDistanceRandomConnections( const double C, const double lambda, MPI::Intracomm const& mpiComm)
00026         : maxConnProb(C), lambda(lambda), unirnd(0,1) {
00027     /* NOOP */
00028 }
00029 
00030 void EuclideanDistanceRandomConnections::init(const SimObjectPopulation &srcPopulation, const SimObjectPopulation &dstPopulation) {
00031     src_popul  = dynamic_cast<const SpatialSimObjectPopulation*>( &srcPopulation  );
00032     dst_popul = dynamic_cast<const SpatialSimObjectPopulation*>( &dstPopulation );
00033     if (!src_popul || !dst_popul) {
00034         throw PCSIM::ConstructionException("EuclideanDistanceRandomConnections::initPopulations", "EuclideanDistanceRandomConnections can operate only with SpatialSimObjectPopulation populations");
00035     }
00036 }
00037 
00038 void EuclideanDistanceRandomConnections::reset(
00039     SimObject::ID::SortedVector::const_iterator src_begin_it,
00040     SimObject::ID::SortedVector::const_iterator src_end_it,
00041     SimObject::ID::SortedVector::const_iterator dst_begin_it,
00042     SimObject::ID::SortedVector::const_iterator dst_end_it) {
00043 
00044     curr_src_idx = 0;
00045     curr_dst_idx = -1;
00046 
00047     this->src_begin_it = src_begin_it;
00048     this->dst_begin_it = dst_begin_it;
00049 
00050     max_src_idx = src_end_it - src_begin_it;
00051     max_dst_idx = dst_end_it - dst_begin_it;
00052 
00053 }
00054 
00055 bool EuclideanDistanceRandomConnections::next( pair<SimObject::ID, SimObject::ID> &conn_pair )
00056 {
00057     last_conn_valid = false;
00058 
00059     int src, dst;
00060 
00061     do {
00062         if (++curr_dst_idx == max_dst_idx) {
00063             curr_dst_idx = 0;
00064             if (++curr_src_idx == max_src_idx)
00065                 return false;
00066         }
00067         src = *(src_begin_it + curr_src_idx);
00068         dst = *(dst_begin_it + curr_dst_idx);
00069 
00070     } while ( unirnd( *m_rnd_eng ) > maxConnProb *
00071               exp( - sqr_distance( src_popul->getLocation(src), dst_popul->getLocation(dst)) / (lambda*lambda) )
00072               || ((*src_popul).getID(src) == (*dst_popul).getID(dst)));
00073 
00074     conn_pair.first = (*src_popul).getID(src);
00075     conn_pair.second = (*dst_popul).getID(dst);
00076 
00077     last_conn_idx.first = src;
00078     last_conn_idx.second = dst;
00079 
00080     last_conn_valid = true;
00081 
00082     return true;
00083 }

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