Simplify the interface to random. I really have no idea why I let you set the RNG later, anyway.

This commit is contained in:
James P. Howard, II
2022-08-19 20:26:29 -04:00
parent d884e603cb
commit f18e2c99da
2 changed files with 9 additions and 5 deletions

View File

@@ -88,9 +88,9 @@ namespace kami {
* @param rng [in] A uniform random number generator of type `std::mt19937`,
* used as the source of randomness.
*
* @returns a shared pointer to this instance of `RandomScheduler`
* @returns a shared pointer to the random number generator
*/
std::shared_ptr<RandomScheduler> set_rng(std::shared_ptr<std::ranlux24> rng);
std::shared_ptr<std::ranlux24> set_rng(std::shared_ptr<std::ranlux24> rng);
/**
* @brief Get the RNG

View File

@@ -27,6 +27,7 @@
#include <memory>
#include <optional>
#include <random>
#include <utility>
#include <vector>
#include <kami/model.h>
@@ -40,13 +41,16 @@ namespace kami {
}
std::optional<std::shared_ptr<std::vector<AgentID>>> RandomScheduler::step(std::shared_ptr<Model> model, std::shared_ptr<std::vector<AgentID>> agent_list) {
shuffle(agent_list->begin(),agent_list->end(), *_rng);
if (_rng == nullptr)
return std::nullopt;
shuffle(agent_list->begin(), agent_list->end(), *_rng);
return std::move(this->SequentialScheduler::step(model, agent_list));
}
std::shared_ptr<RandomScheduler> RandomScheduler::set_rng(std::shared_ptr<std::ranlux24> rng) {
std::shared_ptr<std::ranlux24> RandomScheduler::set_rng(std::shared_ptr<std::ranlux24> rng) {
this->_rng = std::move(rng);
return shared_from_this();
return _rng;
}
std::shared_ptr<std::ranlux24> RandomScheduler::get_rng() { return (this->_rng); }