PredicateBasedConnections.cpp

Go to the documentation of this file.
00001 
00011 #include "PredicateBasedConnections.h"
00012 #include <iostream>
00013 using std::cerr;
00014 using std::endl;
00015 
00016 #include <typeinfo>
00017 using std::type_info;
00018 
00019 PredicateBasedConnections::PredicateBasedConnections( shared_ptr<ConnectionDecisionPredicate> decision )
00020         : decision(decision) {
00021     /* NOOP */
00022 }
00023 
00024 
00025 PredicateBasedConnections::PredicateBasedConnections(shared_ptr<ConnectionDecisionPredicate> decision, MPI::Intracomm const& mpiComm)
00026         : decision(decision) {
00027     /* NOOP */
00028 }
00029 
00030 void PredicateBasedConnections::init(const SimObjectPopulation &srcPopulation, const SimObjectPopulation &dstPopulation) {
00031     decision->init( srcPopulation, dstPopulation, m_rnd_eng );
00032     src_popul = &srcPopulation;
00033     dst_popul = &dstPopulation;
00034 }
00035 
00036 void PredicateBasedConnections::reset(
00037     SimObject::ID::SortedVector::const_iterator src_begin,
00038     SimObject::ID::SortedVector::const_iterator src_end,
00039     SimObject::ID::SortedVector::const_iterator dst_begin,
00040     SimObject::ID::SortedVector::const_iterator dst_end) {
00041 
00042     curr_src_idx = 0;
00043     curr_dst_idx = -1;
00044 
00045     this->src_begin_it = src_begin;
00046     this->dst_begin_it = dst_begin;
00047 
00048     max_src_idx = src_end - src_begin_it;
00049     max_dst_idx = dst_end - dst_begin_it;
00050 
00051 }
00052 
00053 bool PredicateBasedConnections::next( pair<SimObject::ID, SimObject::ID> &conn_pair )
00054 {
00055     last_conn_valid = false;
00056 
00057     size_t src, dst;
00058 
00059     do {
00060         //cerr << endl;
00061 
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         //cerr << "src=" << src << ", dst=" << dst;
00071 
00072     }  while( !decision->decide( src, dst, m_rnd_eng ) );
00073 
00074     //cerr << " : True" << endl;
00075 
00076     conn_pair.first  = src_popul->getID(src);
00077     conn_pair.second = dst_popul->getID(dst);
00078 
00079     last_conn_idx.first = src;
00080     last_conn_idx.second = dst;
00081 
00082     last_conn_valid = true;
00083 
00084     return true;
00085 }
00086 
00087 

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