richelbilderbeek / pbdmms

Some models
GNU General Public License v3.0
2 stars 0 forks source link

Create a templated experiment #50

Closed richelbilderbeek closed 7 years ago

richelbilderbeek commented 7 years ago

To ensure that we all do our experiment in the same way, a template function should be written, ensuring we do things in the same way.

This must be done by the team as a whole. I suggest I write a first draft, then let the team modify.

richelbilderbeek commented 7 years ago

I'll put this in the jkr namespace.

richelbilderbeek commented 7 years ago

Plan:

richelbilderbeek commented 7 years ago

I suggest from

template <class parameters, class simulation, class results>
void do_experiment(const parameters& p)
{
  simulation s = create_simulation(p);
  run(s);
  save_ltt_plot(get_results(s), get_ltt_plot_filename(p));
}

to

template <class parameters, class simulation, class results>
void do_experiment(const parameters& p)
{
  simulation s = create_simulation(p);
  const int n_generations = get_n_generations(p);
  for (int t=0; t!=n_generations; ++t)
  {
    const auto next_population = create_next_population(s);
    set_population(s, next_population);
  }
  save_ltt_plot(get_results(s), get_ltt_plot_filename(p));
}

Sure, the get/set can be done in one line, but, thanks to auto, the rigidity of the function would not change from that.

Agree on this?

richelbilderbeek commented 7 years ago

Suggestion for next iteration:

template <class parameters, class simulation, class results>
void do_experiment(const parameters& p)
{
  simulation s = create_simulation(p);
  const int n_generations = get_n_generations(p);
  std::mt19937 rng_engine(get_rng_seed(p));
  for (int t=0; t!=n_generations; ++t)
  {
    const auto next_population
      = create_next_population(
        const_cast<const simulation&>(s), //Enforce only reading the simulation
        rng_engine
      );
    set_population(s, next_population);
  }
  save_ltt_plot(get_results(s), get_ltt_plot_filename(p));
}

Agree on this?

richelbilderbeek commented 7 years ago

This goes just fine, closing this Issue for now.