Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

typedef for distributions for easier setup by archetypes #1677

Merged
merged 3 commits into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Since last release
* build and test are now fown on githubAction in place or CircleCI (#1569)
* Have separate workflows for testing, publishing dependency images, and publishing release images (#1597, #1602, #1606, #1609, #1629, #1633, #1637, #1668, #1672)
* Add Ubuntu 20.04 to the list of supported platforms (#1605, #1608)
* Add random number generator (Mersenne Twister 19937, from boost) and the ability to set the seed in the simulation control block (#1599)
* Add random number generator (Mersenne Twister 19937, from boost) and the ability to set the seed in the simulation control block (#1599, #1677)
* Added code coverage reporting to GitHub workflows (#1616, #1679)
* Adds active and dormant buying cycles in buy policy (#1596)
* Add random number generator (Mersenne Twister 19937, from boost) and the ability to set the seed in the simulation control block (#1599, #1639)
Expand Down
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
Loading