2 #ifndef __SEQUENCE_COALESCENT_BITS_COALESCE_TCC__
3 #define __SEQUENCE_COALESCENT_BITS_COALESCE_TCC__
9 template<typename uniform_generator>
10 std::pair<int,int> pick2_in_deme_details( uniform_generator & uni,
11 const std::vector<Sequence::coalsim::chromosome> & sample,
12 const int & current_nsam,
13 const int & deme_nsam,
16 assert( deme_nsam > 0 );
18 assert( deme_nsam <= current_nsam );
19 std::pair<int,int> two = pick2(uni,deme_nsam);
20 assert(two.first != two.second);
22 for(int i=0,j=0;i<current_nsam;++i)
24 if( (sample.begin()+i)->pop == deme && j == two.first )
26 else if ( (sample.begin()+i)->pop == deme && j == two.second )
28 if( (sample.begin()+i)->pop == deme ) ++j;
31 return std::make_pair(std::min(c1,c2),std::max(c1,c2));
34 template<typename uniform_generator>
35 std::pair<int,int> pick2_details(uniform_generator & uni, const int & nsam)
37 //int i = int(uni(std::cref(0),std::cref(nsam)));
38 int i = int(uni(0,std::cref(nsam)));
40 while( (j = int(uni(0,std::cref(nsam)))) == i )
43 if(i>j) std::swap(i,j);
44 return std::make_pair(i,j);
47 template<typename uniform_generator>
48 std::pair<int,int> pick2_in_deme( uniform_generator & uni,
49 const std::vector<Sequence::coalsim::chromosome> & sample,
50 const int & current_nsam,
51 const int & deme_nsam,
54 \brief Choose two random chromosomes from the same deme
55 \param uni A random number generator taking two arguments, a and b, and returning
56 a random variable distributed uniformly over [a,b)
57 \param sample The current state of the simulated sample
58 \param current_snam The total sample size being simuled (the sum of sample sizes over all demes)
59 \param deme_nsam The sample size of the deme from which you wish to sample
60 \param deme The index ( 0 <= deme < # populations ) of the deme from which you wish to sample
61 \return A pair of integers which contains the indexes of two chromosomes in @a sample
65 return pick2_in_deme_details(uni,sample,current_nsam,deme_nsam,deme);
69 template<typename uniform_generator>
70 std::pair<int,int> pick2_in_deme( const uniform_generator & uni,
71 const std::vector<Sequence::coalsim::chromosome> & sample,
72 const int & current_nsam,
73 const int & deme_nsam,
76 \brief Choose two random chromosomes from the same deme
77 \param uni A random number generator taking two arguments, a and b, and returning
78 a random variable distributed uniformly over [a,b)
79 \param sample The current state of the simulated sample
80 \param current_nsam The total sample size being simuled (the sum of sample sizes over all demes)
81 \param deme_nsam The sample size of the deme from which you wish to sample
82 \param deme The index ( 0 <= deme < # populations ) of the deme from which you wish to sample
83 \return A pair of integers which contains the indexes of two chromosomes in @a sample
87 return pick2_in_deme_details(uni,sample,current_nsam,deme_nsam,deme);
90 template<typename uniform_generator>
91 std::pair<int,int> pick2( uniform_generator & uni, const int & nsam)
93 \param uni a random number function/object capable of returning
94 a double-precision random number between 0 and \a nsam-1
95 \param nsam the current sample size in the simulation
96 \return A pair of integers which contains the indexes of two chromosomes in @a sample
100 return pick2_details(uni,nsam);
103 template<typename uniform_generator>
104 std::pair<int,int> pick2( const uniform_generator & uni, const int & nsam)
106 \param uni a random number function/object capable of returning
107 a double-precision random number between 0 and \a nsam-1
108 \param nsam the current sample size in the simulation
109 \return A pair of integers which contains the indexes of two chromosomes in @a sample
113 return pick2_details(uni,nsam);