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