forqs module reference
Forward simulation of Recombination, Quantitative traits, and Selection
 All Classes Groups Pages
PopulationConfigGeneratorImplementation.hpp
1 //
2 // PopulationConfigGeneratorImplementation.hpp
3 //
4 // Created by Darren Kessner with John Novembre
5 //
6 // Copyright (c) 2013 Regents of the University of California
7 // All rights reserved.
8 //
9 // Redistribution and use in source and binary forms, with or without
10 // modification, are permitted provided that the following conditions are met:
11 //
12 // * Redistributions of source code must retain the above copyright notice,
13 // this list of conditions and the following disclaimer.
14 //
15 // * Redistributions in binary form must reproduce the above copyright notice,
16 // this list of conditions and the following disclaimer in the documentation
17 // and/or other materials provided with the distribution.
18 //
19 // * Neither UCLA nor the names of its contributors may be used to endorse or
20 // promote products derived from this software without specific prior
21 // written permission.
22 //
23 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
24 // ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
25 // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
26 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
27 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
29 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
30 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
31 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
32 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 //
34 
35 
36 #ifndef _POPULATIONCONFIGGENERATORIMPLEMENTATION_HPP_
37 #define _POPULATIONCONFIGGENERATORIMPLEMENTATION_HPP_
38 
39 
40 #include "PopulationConfigGenerator.hpp"
41 #include "Trajectory.hpp"
42 
43 
54 
55 
56 //
57 // PopulationConfigGenerator_File
58 //
59 
71 
72 class PopulationConfigGenerator_File : public PopulationConfigGenerator
73 {
74  public:
75 
76  PopulationConfigGenerator_File(const std::string& id, const std::string& filename = "");
77  virtual Population::Configs population_configs(size_t generation_index,
78  const PopulationDataPtrs& population_datas) const;
79 
80  // Configurable interface
81 
82  virtual std::string class_name() const {return "PopulationConfigGenerator_File";}
83  virtual Parameters parameters() const;
84  virtual void configure(const Parameters& parameters, const Registry& registry);
85 
86  private:
87 
88  std::string filename_;
89  std::vector<Population::Configs> population_configs_;
90 
91  void read_file();
92 };
93 
94 
95 //
96 // PopulationConfigGenerator_ConstantSize
97 //
98 
122 
123 class PopulationConfigGenerator_ConstantSize : public PopulationConfigGenerator
124 {
125  public:
126 
127  PopulationConfigGenerator_ConstantSize(const std::string& id)
128  : PopulationConfigGenerator(id)
129  {}
130 
131  virtual Population::Configs population_configs(size_t generation_index,
132  const PopulationDataPtrs& population_datas) const;
133 
134  // Configurable interface
135 
136  virtual std::string class_name() const {return "PopulationConfigGenerator_ConstantSize";}
137  virtual Parameters parameters() const;
138  virtual void configure(const Parameters& parameters, const Registry& registry);
139 
140  private:
141  size_t population_size_;
142 };
143 
144 
145 //
146 // MigrationRateTrajectoryInfo
147 //
148 
149 
151 {
152  size_t population_index_from;
153  size_t population_index_to;
154  TrajectoryPtr trajectory;
155 
156  MigrationRateTrajectoryInfo() : population_index_from(0), population_index_to(0) {}
157  MigrationRateTrajectoryInfo(const std::string& configuration, const Configurable::Registry& registry);
158  std::string configuration() const;
159 };
160 
161 
162 typedef std::vector<MigrationRateTrajectoryInfo> MigrationRateTrajectoryInfos;
163 
164 
165 //
166 // PopulationConfigGenerator_IslandBase
167 //
168 // This base implmentation class provides common functionality for
169 // PCG_LinearSteppingStone and PCG_Island, including parametrization, internal
170 // data structures, and population_configs() implementation.
171 //
172 // Note that the only difference between these models is the interpretation of
173 // the migration_rate_default parameter; specialization is handled by the
174 // virtual function initialize_default_trajectories().
175 //
176 
177 class PopulationConfigGenerator_IslandBase : public PopulationConfigGenerator
178 {
179  public:
180 
181  PopulationConfigGenerator_IslandBase(const std::string& id);
182 
183  virtual Population::Configs population_configs(size_t generation_index,
184  const PopulationDataPtrs& population_datas) const;
185 
186  // Configurable interface
187 
188  virtual Parameters parameters() const;
189  virtual void configure(const Parameters& parameters, const Registry& registry);
190  virtual void write_child_configurations(std::ostream& os, std::set<std::string>& ids_written) const;
191 
192  protected:
193 
194  TrajectoryPtr population_size_trajectory_;
195  TrajectoryPtr migration_rate_trajectory_default_;
196  MigrationRateTrajectoryInfos migration_rate_trajectory_infos_;
197 
198  typedef std::vector<TrajectoryPtrs> MigrationRateTrajectories;
199  MigrationRateTrajectories migration_rate_trajectories_;
200 
201  virtual void initialize_default_trajectories() = 0;
202 
203  private:
204 
205  void initialize_trajectories();
206 };
207 
208 
209 //
210 // PopulationConfigGenerator_LinearSteppingStone
211 //
212 
241 
242 
244 {
245  public:
246 
247  PopulationConfigGenerator_LinearSteppingStone(const std::string& id);
248  virtual std::string class_name() const {return "PopulationConfigGenerator_LinearSteppingStone";}
249 
250  protected:
251 
252  virtual void initialize_default_trajectories();
253 };
254 
255 
256 //
257 // PopulationConfigGenerator_Island
258 //
259 
288 
290 {
291  public:
292 
293  PopulationConfigGenerator_Island(const std::string& id);
294  virtual std::string class_name() const {return "PopulationConfigGenerator_Island";}
295 
296  protected:
297 
298  virtual void initialize_default_trajectories();
299 };
300 
301 
302 #endif // _POPULATIONCONFIGGENERATORIMPLEMENTATION_HPP_
303