forqs module reference
Forward simulation of Recombination, Quantitative traits, and Selection
 All Classes Groups Pages
Trajectory.hpp
1 //
2 // Trajectory.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 _TRAJECTORY_HPP_
37 #define _TRAJECTORY_HPP_
38 
39 
40 #include "Configurable.hpp"
41 #include "shared_ptr.hpp"
42 
43 
50 
51 
52 //
53 // Trajectory
54 //
55 
59 
60 class Trajectory : public Configurable
61 {
62  public:
63 
64  virtual double value(size_t generation_index, size_t population_index) const = 0;
65 
66  // Configurable interface
67 
68  virtual std::string class_name() const;
69  virtual Parameters parameters() const;
70  virtual void configure(const Parameters& parameters, const Registry& registry);
71 
72  protected:
73 
74  Trajectory(const std::string& id) : Configurable(id) {}
75 };
76 
77 
78 typedef shared_ptr<Trajectory> TrajectoryPtr;
79 typedef std::vector<TrajectoryPtr> TrajectoryPtrs;
80 
81 
82 //
83 // Trajectory_PopulationComposite
84 //
85 
97 
98 
100 {
101  public:
102 
103  Trajectory_PopulationComposite(const std::string& id,
104  const TrajectoryPtrs& trajectories = TrajectoryPtrs());
105 
106  virtual double value(size_t generation_index, size_t population_index) const;
107 
108  // Configurable interface
109 
110  virtual std::string class_name() const {return "Trajectory_PopulationComposite";}
111  virtual Parameters parameters() const;
112  virtual void configure(const Parameters& parameters, const Registry& registry);
113  virtual void initialize(const SimulatorConfig& config);
114  virtual void write_child_configurations(std::ostream& os, std::set<std::string>& ids_written) const;
115 
116  private:
117 
118  TrajectoryPtrs trajectories_;
119 };
120 
121 
122 //
123 // Trajectory_GenerationComposite
124 //
125 
137 
138 
140 {
141  public:
142 
143  typedef std::map<size_t, TrajectoryPtr> GenerationTrajectoryMap;
144 
145  Trajectory_GenerationComposite(const std::string& id,
146  const GenerationTrajectoryMap& trajectories = GenerationTrajectoryMap());
147 
148  virtual double value(size_t generation_index, size_t population_index) const;
149 
150  // Configurable interface
151 
152  virtual std::string class_name() const {return "Trajectory_GenerationComposite";}
153  virtual Parameters parameters() const;
154  virtual void configure(const Parameters& parameters, const Registry& registry);
155  virtual void write_child_configurations(std::ostream& os, std::set<std::string>& ids_written) const;
156 
157  private:
158 
159  GenerationTrajectoryMap trajectories_; // generation_index -> Trajectory
160 };
161 
162 
163 //
164 // Trajectory_Constant
165 //
166 
178 
179 
181 {
182  public:
183 
184  Trajectory_Constant(const std::string& id, double value = 0.)
185  : Trajectory(id), value_(value)
186  {}
187 
188  virtual double value(size_t generation_index, size_t population_index) const {return value_;}
189 
190  // Configurable interface
191 
192  virtual std::string class_name() const {return "Trajectory_Constant";}
193  virtual Parameters parameters() const;
194  virtual void configure(const Parameters& parameters, const Registry& registry);
195 
196  private:
197  double value_;
198 };
199 
200 
201 //
202 // Trajectory_Linear
203 //
204 
226 
227 
229 {
230  public:
231 
232  Trajectory_Linear(const std::string& id, double slope = 0., double intercept = 0.)
233  : Trajectory(id), slope_(slope), intercept_(intercept),
234  generation_index_begin_(-1ul), generation_index_end_(-1ul),
235  value_begin_(0), value_end_(0)
236  {}
237 
238  virtual double value(size_t generation_index, size_t population_index) const
239  {
240  return slope_ * generation_index + intercept_;
241  }
242 
243  // Configurable interface
244 
245  virtual std::string class_name() const {return "Trajectory_Linear";}
246  virtual Parameters parameters() const;
247  virtual void configure(const Parameters& parameters, const Registry& registry);
248 
249  private:
250 
251  double slope_;
252  double intercept_;
253 
254  size_t generation_index_begin_;
255  size_t generation_index_end_;
256  double value_begin_;
257  double value_end_;
258 };
259 
260 
261 //
262 // Trajectory_Exponential
263 //
264 
280 
281 
283 {
284  public:
285 
286  Trajectory_Exponential(const std::string& id,
287  size_t generation_index_begin = 0,
288  double value_begin = 0.,
289  double rate = 0.)
290  : Trajectory(id),
291  generation_index_begin_(generation_index_begin),
292  value_begin_(value_begin),
293  rate_(rate)
294  {}
295 
296  virtual double value(size_t generation_index, size_t population_index) const;
297 
298  // Configurable interface
299 
300  virtual std::string class_name() const {return "Trajectory_Exponential";}
301  virtual Parameters parameters() const;
302  virtual void configure(const Parameters& parameters, const Registry& registry);
303 
304  private:
305 
306  size_t generation_index_begin_;
307  double value_begin_;
308  double rate_;
309 };
310 
311 
312 #endif // _TRAJECTORY_HPP_
313