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 size_t generation_count() const;
78  virtual Population::Configs population_configs(size_t generation_index) 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 initialize();
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) const;
132 
133  // Configurable interface
134 
135  virtual std::string class_name() const {return "PopulationConfigGenerator_ConstantSize";}
136  virtual Parameters parameters() const;
137  virtual void configure(const Parameters& parameters, const Registry& registry);
138 
139  private:
140  size_t population_size_;
141 };
142 
143 
144 //
145 // MigrationRateTrajectoryInfo
146 //
147 
148 
150 {
151  size_t population_index_from;
152  size_t population_index_to;
153  TrajectoryPtr trajectory;
154 
155  MigrationRateTrajectoryInfo() : population_index_from(0), population_index_to(0) {}
156  MigrationRateTrajectoryInfo(const std::string& configuration, const Configurable::Registry& registry);
157  std::string configuration() const;
158 };
159 
160 
161 typedef std::vector<MigrationRateTrajectoryInfo> MigrationRateTrajectoryInfos;
162 
163 
164 //
165 // PopulationConfigGenerator_IslandBase
166 //
167 // This base implmentation class provides common functionality for
168 // PCG_LinearSteppingStone and PCG_Island, including parametrization, internal
169 // data structures, and population_configs() implementation.
170 //
171 // Note that the only difference between these models is the interpretation of
172 // the migration_rate_default parameter; specialization is handled by the
173 // virtual function initialize_default_trajectories().
174 //
175 
176 class PopulationConfigGenerator_IslandBase : public PopulationConfigGenerator
177 {
178  public:
179 
180  PopulationConfigGenerator_IslandBase(const std::string& id);
181 
182  virtual Population::Configs population_configs(size_t generation_index) const;
183 
184  // Configurable interface
185 
186  virtual Parameters parameters() const;
187  virtual void configure(const Parameters& parameters, const Registry& registry);
188  virtual void write_child_configurations(std::ostream& os, std::set<std::string>& ids_written) const;
189 
190  protected:
191 
192  TrajectoryPtr population_size_trajectory_;
193  TrajectoryPtr migration_rate_trajectory_default_;
194  MigrationRateTrajectoryInfos migration_rate_trajectory_infos_;
195 
196  typedef std::vector<TrajectoryPtrs> MigrationRateTrajectories;
197  MigrationRateTrajectories migration_rate_trajectories_;
198 
199  virtual void initialize_default_trajectories() = 0;
200 
201  private:
202 
203  void initialize_trajectories();
204 };
205 
206 
207 //
208 // PopulationConfigGenerator_LinearSteppingStone
209 //
210 
239 
240 
242 {
243  public:
244 
245  PopulationConfigGenerator_LinearSteppingStone(const std::string& id);
246  virtual std::string class_name() const {return "PopulationConfigGenerator_LinearSteppingStone";}
247 
248  protected:
249 
250  virtual void initialize_default_trajectories();
251 };
252 
253 
254 //
255 // PopulationConfigGenerator_Island
256 //
257 
286 
288 {
289  public:
290 
291  PopulationConfigGenerator_Island(const std::string& id);
292  virtual std::string class_name() const {return "PopulationConfigGenerator_Island";}
293 
294  protected:
295 
296  virtual void initialize_default_trajectories();
297 };
298 
299 
300 #endif // _POPULATIONCONFIGGENERATORIMPLEMENTATION_HPP_
301