forqs module reference
Forward simulation of Recombination, Quantitative traits, and Selection
 All Classes Groups Pages
Simulator.hpp
1 //
2 // Simulator.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 _SIMULATOR_HPP_
37 #define _SIMULATOR_HPP_
38 
39 
40 #include "PopulationConfigGenerator.hpp"
41 #include "PopulationData.hpp"
42 #include "FitnessFunction.hpp"
43 #include "MutationGenerator.hpp"
44 #include "Reporter.hpp"
45 #include "VariantIndicator.hpp"
46 #include <vector>
47 #include <string>
48 #include <iostream>
49 
50 
51 // forward declarations to make SimulatorConfig accessible to VariantIndicator and Reporter
52 class VariantIndicator;
53 typedef shared_ptr<VariantIndicator> VariantIndicatorPtr;
54 class Reporter;
55 typedef shared_ptr<Reporter> ReporterPtr;
56 typedef std::vector<ReporterPtr> ReporterPtrs;
57 
58 
64 
65 
91 
93 {
94  unsigned int seed;
95  std::string output_directory;
96  bool write_popconfig;
97  bool write_vi;
98  bool use_random_seed;
99 
100  PopulationConfigGeneratorPtr population_config_generator;
101  RecombinationPositionGeneratorPtr recombination_position_generator;
102  VariantIndicatorPtr variant_indicator;
103  QuantitativeTraitPtrs quantitative_traits;
104  FitnessFunctionPtr fitness_function;
105  MutationGeneratorPtr mutation_generator;
106  ReporterPtrs reporters;
107 
108  SimulatorConfig(const std::string& id = "dummy");
109 
110  // Configurable interface
111 
112  virtual std::string class_name() const {return "SimulatorConfig";}
113  virtual Parameters parameters() const;
114  virtual void configure(const Parameters& parameters, const Registry& registry);
115  void write_child_configurations(std::ostream& os, std::set<std::string>& ids_written) const;
116 };
117 
118 
119 typedef shared_ptr<SimulatorConfig> SimulatorConfigPtr;
120 
121 
123 {
124  public:
125 
126  Simulator(const SimulatorConfig& config);
127  void simulate_single_generation();
128  void simulate_all();
129  void update_final();
130 
131  private:
132 
133  SimulatorConfig config_;
134  Genotyper genotyper_;
135 
136  size_t current_generation_index_;
137  PopulationPtrsPtr current_populations_;
138  PopulationDatasPtr current_population_datas_;
139  size_t update_step_;
140 };
141 
142 
143 typedef shared_ptr<Simulator> SimulatorPtr;
144 
145 
146 #endif // _SIMULATOR_HPP_
147