forqs module reference
Forward simulation of Recombination, Quantitative traits, and Selection
 All Classes Groups Pages
PopulationConfigGenerator.hpp
1 //
2 // PopulationConfigGenerator.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 _POPULATIONCONFIGGENERATOR_HPP_
37 #define _POPULATIONCONFIGGENERATOR_HPP_
38 
39 
40 #include "Population.hpp"
41 #include "Configurable.hpp"
42 #include "Trajectory.hpp"
43 #include "shared_ptr.hpp"
44 
45 
56 
57 
58 //
59 // PopulationConfigGenerator
60 //
61 
65 
67 {
68  public:
69 
70  virtual size_t generation_count() const {return generation_count_;}
71  virtual size_t population_count() const {return population_count_;}
72  virtual unsigned int id_offset_step() const {return id_offset_step_;}
73  virtual size_t chromosome_pair_count() const {return chromosome_pair_count_;}
74  virtual const std::vector<unsigned int>& chromosome_lengths() const {return chromosome_lengths_;}
75 
76  virtual Population::Configs population_configs(size_t generation_index) const = 0;
77 
78  unsigned int min_unused_id() const;
79 
80  // Configurable interface: base implementation
81 
82  virtual std::string class_name() const;
83  virtual Parameters parameters() const;
84  virtual void configure(const Parameters& parameters, const Registry& registry);
85 
86  virtual ~PopulationConfigGenerator() {}
87 
88  protected:
89 
90  PopulationConfigGenerator(const std::string& id);
91 
92  size_t generation_count_;
93  size_t population_count_;
94  unsigned int id_offset_step_;
95  size_t chromosome_pair_count_;
96  std::vector<unsigned int> chromosome_lengths_;
97 };
98 
99 
100 typedef shared_ptr<PopulationConfigGenerator> PopulationConfigGeneratorPtr;
101 
102 
103 
104 //
105 // PopulationConfigGenerator_File
106 //
107 
119 
121 {
122  public:
123 
124  PopulationConfigGenerator_File(const std::string& id, const std::string& filename = "");
125  virtual size_t generation_count() const;
126  virtual Population::Configs population_configs(size_t generation_index) const;
127 
128  // Configurable interface
129 
130  virtual std::string class_name() const {return "PopulationConfigGenerator_File";}
131  virtual Parameters parameters() const;
132  virtual void configure(const Parameters& parameters, const Registry& registry);
133 
134  private:
135 
136  std::string filename_;
137  std::vector<Population::Configs> population_configs_;
138 
139  void initialize();
140 };
141 
142 
143 //
144 // PopulationConfigGenerator_ConstantSize
145 //
146 
170 
172 {
173  public:
174 
175  PopulationConfigGenerator_ConstantSize(const std::string& id)
177  {}
178 
179  virtual Population::Configs population_configs(size_t generation_index) const;
180 
181  // Configurable interface
182 
183  virtual std::string class_name() const {return "PopulationConfigGenerator_ConstantSize";}
184  virtual Parameters parameters() const;
185  virtual void configure(const Parameters& parameters, const Registry& registry);
186 
187  private:
188  size_t population_size_;
189 };
190 
191 
192 //
193 // MigrationRateTrajectoryInfo
194 //
195 
196 
198 {
199  size_t population_index_from;
200  size_t population_index_to;
201  TrajectoryPtr trajectory;
202 
203  MigrationRateTrajectoryInfo() : population_index_from(0), population_index_to(0) {}
204  MigrationRateTrajectoryInfo(const std::string& configuration, const Configurable::Registry& registry);
205  std::string configuration() const;
206 };
207 
208 
209 typedef std::vector<MigrationRateTrajectoryInfo> MigrationRateTrajectoryInfos;
210 
211 
212 //
213 // PopulationConfigGenerator_IslandBase
214 //
215 // This base implmentation class provides common functionality for
216 // PCG_LinearSteppingStone and PCG_Island, including parametrization, internal
217 // data structures, and population_configs() implementation.
218 //
219 // Note that the only difference between these models is the interpretation of
220 // the migration_rate_default parameter; specialization is handled by the
221 // virtual function initialize_default_trajectories().
222 //
223 
225 {
226  public:
227 
228  PopulationConfigGenerator_IslandBase(const std::string& id);
229 
230  virtual Population::Configs population_configs(size_t generation_index) const;
231 
232  // Configurable interface
233 
234  virtual Parameters parameters() const;
235  virtual void configure(const Parameters& parameters, const Registry& registry);
236  virtual void write_child_configurations(std::ostream& os, std::set<std::string>& ids_written) const;
237 
238  protected:
239 
240  TrajectoryPtr population_size_trajectory_;
241  TrajectoryPtr migration_rate_trajectory_default_;
242  MigrationRateTrajectoryInfos migration_rate_trajectory_infos_;
243 
244  typedef std::vector<TrajectoryPtrs> MigrationRateTrajectories;
245  MigrationRateTrajectories migration_rate_trajectories_;
246 
247  virtual void initialize_default_trajectories() = 0;
248 
249  private:
250 
251  void initialize_trajectories();
252 };
253 
254 
255 //
256 // PopulationConfigGenerator_LinearSteppingStone
257 //
258 
287 
288 
290 {
291  public:
292 
293  PopulationConfigGenerator_LinearSteppingStone(const std::string& id);
294  virtual std::string class_name() const {return "PopulationConfigGenerator_LinearSteppingStone";}
295 
296  protected:
297 
298  virtual void initialize_default_trajectories();
299 };
300 
301 
302 //
303 // PopulationConfigGenerator_Island
304 //
305 
334 
336 {
337  public:
338 
339  PopulationConfigGenerator_Island(const std::string& id);
340  virtual std::string class_name() const {return "PopulationConfigGenerator_Island";}
341 
342  protected:
343 
344  virtual void initialize_default_trajectories();
345 };
346 
347 
348 #endif // _POPULATIONCONFIGGENERATOR_HPP_
349