From 062c30cadd7be766335966252f73e9fcf7303a4d Mon Sep 17 00:00:00 2001 From: Katie Mummah Date: Wed, 28 Feb 2024 12:38:46 -0600 Subject: [PATCH] typedef for distributions for easier setup by archetypes --- src/random_number_generator.h | 17 ++++++++++++++++- src/toolkit/matl_buy_policy.h | 14 +++++++------- 2 files changed, 23 insertions(+), 8 deletions(-) diff --git a/src/random_number_generator.h b/src/random_number_generator.h index 25fbfe4f6e..3f2fc0074a 100644 --- a/src/random_number_generator.h +++ b/src/random_number_generator.h @@ -85,9 +85,11 @@ class RandomNumberGenerator { int high=std::numeric_limits::max()); }; - + class DoubleDistribution { public: + typedef boost::shared_ptr Ptr; + virtual double sample() = 0; virtual double max() = 0; }; @@ -96,6 +98,8 @@ class FixedDoubleDist : public DoubleDistribution { private: double value; public: + typedef boost::shared_ptr Ptr; + FixedDoubleDist(double value_) : value(value_) {}; virtual double sample() { return value; }; virtual double max() { return value; }; @@ -105,6 +109,8 @@ class UniformDoubleDist : public DoubleDistribution { private: boost::random::uniform_real_distribution<> dist; public: + typedef boost::shared_ptr Ptr; + UniformDoubleDist(double min = 0, double max=1) : dist(min, max) {}; virtual double sample() { return dist(RandomNumberGenerator::gen_); } virtual double max() { return dist.max(); } @@ -116,6 +122,8 @@ class NormalDoubleDist : public DoubleDistribution { double min_; double max_; public: + typedef boost::shared_ptr Ptr; + NormalDoubleDist(double mean, double std_dev, double min=0, double max=1) : dist(mean, std_dev), min_(min), max_(max) { if (min_ == max_) { throw ValueError("Min and max cannot be equal for a normal distribution. Either use FixedDoubleDist or change the min/max."); @@ -130,6 +138,7 @@ class NormalDoubleDist : public DoubleDistribution { class IntDistribution { public: + typedef boost::shared_ptr Ptr; virtual int sample() = 0; }; @@ -137,6 +146,8 @@ class FixedIntDist : public IntDistribution { private: int value; public: + typedef boost::shared_ptr Ptr; + FixedIntDist(int value_) : value(value_) {}; virtual int sample() { return value; }; }; @@ -145,6 +156,8 @@ class UniformIntDist : public IntDistribution { private: boost::random::uniform_int_distribution<> dist; public: + typedef boost::shared_ptr Ptr; + UniformIntDist(int min = 0, int max=1) : dist(min, max) {}; virtual int sample() { return dist(RandomNumberGenerator::gen_); } virtual int max() { return dist.max(); } @@ -156,6 +169,8 @@ class NormalIntDist : public IntDistribution { int min_; int max_; public: + typedef boost::shared_ptr Ptr; + NormalIntDist(double mean, double std_dev, int min=0, int max=1) : dist(mean, std_dev), min_(min), max_(max) { if (min_ == max_) { throw ValueError("Min and max cannot be equal for a normal distribution. Either use FixedIntDist or change the min/max."); diff --git a/src/toolkit/matl_buy_policy.h b/src/toolkit/matl_buy_policy.h index 79516c7a81..67ea825265 100644 --- a/src/toolkit/matl_buy_policy.h +++ b/src/toolkit/matl_buy_policy.h @@ -122,9 +122,9 @@ class MatlBuyPolicy : public Trader { TotalInvTracker* buf_tracker); MatlBuyPolicy& Init(Agent* manager, ResBuf* buf, std::string name, TotalInvTracker* buf_tracker, double throughput, - boost::shared_ptr active_dist = NULL, - boost::shared_ptr dormant_dist = NULL, - boost::shared_ptr size_dist = NULL); + IntDistribution::Ptr active_dist = NULL, + IntDistribution::Ptr dormant_dist = NULL, + DoubleDistribution::Ptr size_dist = NULL); MatlBuyPolicy& Init(Agent* manager, ResBuf* buf, std::string name, TotalInvTracker* buf_tracker, double throughput, double quantize); @@ -138,7 +138,7 @@ class MatlBuyPolicy : public Trader { MatlBuyPolicy& Init(Agent* manager, ResBuf* buf, std::string name, TotalInvTracker* buf_tracker, double throughput, double cumulative_cap, - boost::shared_ptr dormant_dist); + IntDistribution::Ptr); /// @} /// Instructs the policy to fill its buffer with requests on the given @@ -250,9 +250,9 @@ class MatlBuyPolicy : public Trader { int next_active_end_= 0; int next_dormant_end_= 0; - boost::shared_ptr active_dist_; - boost::shared_ptr dormant_dist_; - boost::shared_ptr size_dist_; + IntDistribution::Ptr active_dist_; + IntDistribution::Ptr dormant_dist_; + DoubleDistribution::Ptr size_dist_; std::map rsrc_commods_; std::map commod_details_;