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 "MutationGenerator.hpp"
43 #include "QuantitativeTrait.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 
90 
92 {
93  unsigned int seed;
94  std::string output_directory;
95  bool write_popconfig;
96  bool write_vi;
97  bool use_random_seed;
98 
99  PopulationConfigGeneratorPtr population_config_generator;
100  RecombinationPositionGeneratorPtrs recombination_position_generators;
101  VariantIndicatorPtr variant_indicator;
102  QuantitativeTraitPtrs quantitative_traits;
103  MutationGeneratorPtr mutation_generator;
104  ReporterPtrs reporters;
105 
106  SimulatorConfig(const std::string& id = "dummy");
107 
108  // Configurable interface
109 
110  virtual std::string class_name() const {return "SimulatorConfig";}
111  virtual Parameters parameters() const;
112  virtual void configure(const Parameters& parameters, const Registry& registry);
113  void write_child_configurations(std::ostream& os, std::set<std::string>& ids_written) const;
114 };
115 
116 
117 typedef shared_ptr<SimulatorConfig> SimulatorConfigPtr;
118 
119 
121 {
122  public:
123 
124  Simulator(const SimulatorConfig& config);
125  void simulate_single_generation();
126  void simulate_all();
127  void update_final();
128 
129  private:
130 
131  SimulatorConfig config_;
132  Genotyper genotyper_;
133 
134  size_t current_generation_index_;
135  PopulationPtrsPtr current_populations_;
136  PopulationDataPtrsPtr current_population_datas_;
137  size_t update_step_;
138 };
139 
140 
141 typedef shared_ptr<Simulator> SimulatorPtr;
142 
143 
144 #endif // _SIMULATOR_HPP_
145