Skip to content

Commit

Permalink
typedef for distributions for easier setup by archetypes
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed Feb 28, 2024
1 parent 2141f55 commit 062c30c
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 8 deletions.
17 changes: 16 additions & 1 deletion src/random_number_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,11 @@ class RandomNumberGenerator {
int high=std::numeric_limits<int>::max());

};

class DoubleDistribution {
public:
typedef boost::shared_ptr<DoubleDistribution> Ptr;

virtual double sample() = 0;
virtual double max() = 0;
};
Expand All @@ -96,6 +98,8 @@ class FixedDoubleDist : public DoubleDistribution {
private:
double value;
public:
typedef boost::shared_ptr<FixedDoubleDist> Ptr;

FixedDoubleDist(double value_) : value(value_) {};
virtual double sample() { return value; };
virtual double max() { return value; };
Expand All @@ -105,6 +109,8 @@ class UniformDoubleDist : public DoubleDistribution {
private:
boost::random::uniform_real_distribution<> dist;
public:
typedef boost::shared_ptr<UniformDoubleDist> Ptr;

UniformDoubleDist(double min = 0, double max=1) : dist(min, max) {};
virtual double sample() { return dist(RandomNumberGenerator::gen_); }
virtual double max() { return dist.max(); }
Expand All @@ -116,6 +122,8 @@ class NormalDoubleDist : public DoubleDistribution {
double min_;
double max_;
public:
typedef boost::shared_ptr<NormalDoubleDist> 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.");
Expand All @@ -130,13 +138,16 @@ class NormalDoubleDist : public DoubleDistribution {

class IntDistribution {
public:
typedef boost::shared_ptr<IntDistribution> Ptr;
virtual int sample() = 0;
};

class FixedIntDist : public IntDistribution {
private:
int value;
public:
typedef boost::shared_ptr<FixedIntDist> Ptr;

FixedIntDist(int value_) : value(value_) {};
virtual int sample() { return value; };
};
Expand All @@ -145,6 +156,8 @@ class UniformIntDist : public IntDistribution {
private:
boost::random::uniform_int_distribution<> dist;
public:
typedef boost::shared_ptr<UniformIntDist> Ptr;

UniformIntDist(int min = 0, int max=1) : dist(min, max) {};
virtual int sample() { return dist(RandomNumberGenerator::gen_); }
virtual int max() { return dist.max(); }
Expand All @@ -156,6 +169,8 @@ class NormalIntDist : public IntDistribution {
int min_;
int max_;
public:
typedef boost::shared_ptr<NormalIntDist> 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.");
Expand Down
14 changes: 7 additions & 7 deletions src/toolkit/matl_buy_policy.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,9 +122,9 @@ class MatlBuyPolicy : public Trader {
TotalInvTracker* buf_tracker);
MatlBuyPolicy& Init(Agent* manager, ResBuf<Material>* buf, std::string name,
TotalInvTracker* buf_tracker, double throughput,
boost::shared_ptr<IntDistribution> active_dist = NULL,
boost::shared_ptr<IntDistribution> dormant_dist = NULL,
boost::shared_ptr<DoubleDistribution> size_dist = NULL);
IntDistribution::Ptr active_dist = NULL,
IntDistribution::Ptr dormant_dist = NULL,
DoubleDistribution::Ptr size_dist = NULL);
MatlBuyPolicy& Init(Agent* manager, ResBuf<Material>* buf, std::string name,
TotalInvTracker* buf_tracker, double throughput,
double quantize);
Expand All @@ -138,7 +138,7 @@ class MatlBuyPolicy : public Trader {
MatlBuyPolicy& Init(Agent* manager, ResBuf<Material>* buf, std::string name,
TotalInvTracker* buf_tracker, double throughput,
double cumulative_cap,
boost::shared_ptr<IntDistribution> dormant_dist);
IntDistribution::Ptr);
/// @}

/// Instructs the policy to fill its buffer with requests on the given
Expand Down Expand Up @@ -250,9 +250,9 @@ class MatlBuyPolicy : public Trader {
int next_active_end_= 0;
int next_dormant_end_= 0;

boost::shared_ptr<IntDistribution> active_dist_;
boost::shared_ptr<IntDistribution> dormant_dist_;
boost::shared_ptr<DoubleDistribution> size_dist_;
IntDistribution::Ptr active_dist_;
IntDistribution::Ptr dormant_dist_;
DoubleDistribution::Ptr size_dist_;

std::map<Material::Ptr, std::string> rsrc_commods_;
std::map<std::string, CommodDetail> commod_details_;
Expand Down

0 comments on commit 062c30c

Please sign in to comment.