Skip to content

Commit

Permalink
implement TotalInvTracker in MatlBuyPolicy (still needs tests probably)
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed Jan 26, 2024
1 parent 72db4e3 commit 4981ca5
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 147 deletions.
16 changes: 6 additions & 10 deletions src/toolkit/matl_buy_policy.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,11 @@ void MatlBuyPolicy::set_manager(Agent* m) {

void MatlBuyPolicy::create_buf_tracker() {
std::vector<ResBuf<Material>*> bufs = {buf_};
buf_tracker_ = new ResBufTracker();
buf_tracker_ = new TotalInvTracker();
buf_tracker_->Init(bufs, buf_->capacity());
}

void MatlBuyPolicy::set_buf_tracker(ResBufTracker* t) {
std::cerr << "set_buf_trackers" << std::endl;
void MatlBuyPolicy::set_buf_tracker(TotalInvTracker* t) {
if (t == NULL){
std::vector<ResBuf<Material>*> bufs = {buf_};
buf_tracker_->Init(bufs, buf_->capacity());
Expand Down Expand Up @@ -113,26 +112,23 @@ void MatlBuyPolicy::init_active_dormant() {
}

MatlBuyPolicy& MatlBuyPolicy::Init(Agent* manager, ResBuf<Material>* buf,
std::string name, ResBufTracker* buf_tracker) {
std::string name, TotalInvTracker* buf_tracker) {
set_manager(manager);
std::cerr << "manager is " << manager << std::endl;
buf_ = buf;
name_ = name;
std::cerr << "beginning buf_tracker_ init" << std::endl;
set_buf_tracker(buf_tracker);
init_active_dormant();
return *this;
}

MatlBuyPolicy& MatlBuyPolicy::Init(Agent* manager, ResBuf<Material>* buf,
std::string name, ResBufTracker* buf_tracker,
std::string name, TotalInvTracker* buf_tracker,
double throughput, boost::shared_ptr<IntDistribution> active_dist,
boost::shared_ptr<IntDistribution> dormant_dist,
boost::shared_ptr<DoubleDistribution> size_dist) {
set_manager(manager);
buf_ = buf;
name_ = name;
std::cerr << "beginning buf_tracker_ init" << std::endl;
set_buf_tracker(buf_tracker);
set_throughput(throughput);
active_dist_ = active_dist;
Expand All @@ -144,7 +140,7 @@ MatlBuyPolicy& MatlBuyPolicy::Init(Agent* manager, ResBuf<Material>* buf,

MatlBuyPolicy& MatlBuyPolicy::Init(Agent* manager, ResBuf<Material>* buf,
std::string name,
ResBufTracker* buf_tracker,
TotalInvTracker* buf_tracker,
double fill_to, double req_when_under) {
set_manager(manager);
buf_ = buf;
Expand All @@ -158,7 +154,7 @@ MatlBuyPolicy& MatlBuyPolicy::Init(Agent* manager, ResBuf<Material>* buf,

MatlBuyPolicy& MatlBuyPolicy::Init(Agent* manager, ResBuf<Material>* buf,
std::string name,
ResBufTracker* buf_tracker,
TotalInvTracker* buf_tracker,
double throughput,
double fill_to, double req_when_under,
double quantize) {
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 @@ -7,7 +7,7 @@
#include "composition.h"
#include "material.h"
#include "res_buf.h"
#include "res_buf_tracker.h"
#include "total_inv_tracker.h"
#include "trader.h"
#include "random_number_generator.h"

Expand Down Expand Up @@ -104,17 +104,17 @@ class MatlBuyPolicy : public Trader {
/// (s, S) inventory management
/// @{
MatlBuyPolicy& Init(Agent* manager, ResBuf<Material>* buf, std::string name,
ResBufTracker* buf_tracker);
TotalInvTracker* buf_tracker);
MatlBuyPolicy& Init(Agent* manager, ResBuf<Material>* buf, std::string name,
ResBufTracker* buf_tracker, double throughput,
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);
MatlBuyPolicy& Init(Agent* manager, ResBuf<Material>* buf, std::string name,
ResBufTracker* buf_tracker,
TotalInvTracker* buf_tracker,
double fill_to, double req_when_under);
MatlBuyPolicy& Init(Agent* manager, ResBuf<Material>* buf, std::string name,
ResBufTracker* buf_tracker,
TotalInvTracker* buf_tracker,
double throughput, double fill_to,
double req_when_under, double quantize);
/// @}
Expand Down Expand Up @@ -197,7 +197,7 @@ class MatlBuyPolicy : public Trader {

void set_manager(Agent* m);
void create_buf_tracker();
void set_buf_tracker(ResBufTracker* t);
void set_buf_tracker(TotalInvTracker* t);
/// requires buf_ already set
void set_fill_to(double x);
/// requires buf_ already set
Expand All @@ -207,7 +207,7 @@ class MatlBuyPolicy : public Trader {
void init_active_dormant();

ResBuf<Material>* buf_;
ResBufTracker* buf_tracker_;
TotalInvTracker* buf_tracker_;
std::string name_;
double fill_to_, req_when_under_, quantize_, throughput_;

Expand Down
115 changes: 0 additions & 115 deletions src/toolkit/res_buf_tracker.h

This file was deleted.

30 changes: 15 additions & 15 deletions tests/toolkit/matl_buy_policy_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ TEST_F(MatlBuyPolicyTests, Init) {
double cap = 5;
ResBuf<Material> buff;
buff.capacity(cap);
ResBufTracker buff_tracker({&buff});
TotalInvTracker buff_tracker({&buff});
std::cerr << "buf cap: " << buff.capacity() << std::endl;
MatlBuyPolicy p;
std::cerr << "policy created" << std::endl;
Expand Down Expand Up @@ -98,7 +98,7 @@ TEST_F(MatlBuyPolicyTests, StartStop) {
double cap = 5;
ResBuf<Material> buff;
buff.capacity(cap);
ResBufTracker buff_tracker({&buff});
TotalInvTracker buff_tracker({&buff});
MatlBuyPolicy p;
ASSERT_THROW(p.Init(NULL, &buff, "", &buff_tracker), ValueError);
}
Expand All @@ -108,7 +108,7 @@ TEST_F(MatlBuyPolicyTests, OneReq) {
double cap = 5;
ResBuf<Material> buff;
buff.capacity(cap);
ResBufTracker buff_tracker({&buff});
TotalInvTracker buff_tracker({&buff});
cyclus::Composition::Ptr c1 = cyclus::Composition::Ptr(new TestComp());
MatlBuyPolicy p;

Expand All @@ -126,7 +126,7 @@ TEST_F(MatlBuyPolicyTests, MultipleReqs) {
double cap = 5;
ResBuf<Material> buff;
buff.capacity(cap);
ResBufTracker buff_tracker({&buff});
TotalInvTracker buff_tracker({&buff});
std::string commod1("foo"), commod2("bar");
double p2 = 2.5;
cyclus::Composition::Ptr c1 = cyclus::Composition::Ptr(new TestComp());
Expand Down Expand Up @@ -155,7 +155,7 @@ TEST_F(MatlBuyPolicyTests, Quantize) {
double cap = 5;
ResBuf<Material> buff;
buff.capacity(cap);
ResBufTracker buff_tracker({&buff});
TotalInvTracker buff_tracker({&buff});
double p2 = 2.5;
cyclus::Composition::Ptr c1 = cyclus::Composition::Ptr(new TestComp());
MatlBuyPolicy p;
Expand All @@ -175,7 +175,7 @@ TEST_F(MatlBuyPolicyTests, MultiReqQuantize) {
double cap = 5;
ResBuf<Material> buff;
buff.capacity(cap);
ResBufTracker buff_tracker({&buff});
TotalInvTracker buff_tracker({&buff});
cyclus::Composition::Ptr c1 = cyclus::Composition::Ptr(new TestComp());
cyclus::Composition::Ptr c2 = cyclus::Composition::Ptr(new TestComp());
MatlBuyPolicy p;
Expand Down Expand Up @@ -213,7 +213,7 @@ TEST_F(MatlBuyPolicyTests, DefaultFixedActiveDormant) {
TestFacility* fac = dynamic_cast<TestFacility*>(sim.agent);

cyclus::toolkit::ResBuf<cyclus::Material> inbuf;
ResBufTracker buf_tracker({&inbuf});
TotalInvTracker buf_tracker({&inbuf});
cyclus::toolkit::MatlBuyPolicy policy;
policy.Init(fac, &inbuf, "inbuf", &buf_tracker, throughput, a_d_dist, a_d_dist, NULL)
.Set("commod1").Start();
Expand Down Expand Up @@ -250,7 +250,7 @@ TEST_F(MatlBuyPolicyTests, FixedActiveDormant) {
TestFacility* fac = dynamic_cast<TestFacility*>(sim.agent);

cyclus::toolkit::ResBuf<cyclus::Material> inbuf;
ResBufTracker buf_tracker({&inbuf});
TotalInvTracker buf_tracker({&inbuf});
cyclus::toolkit::MatlBuyPolicy policy;
policy.Init(fac, &inbuf, "inbuf", &buf_tracker, throughput, a_d_dist, a_d_dist, size_dist)
.Set("commod1").Start();
Expand Down Expand Up @@ -285,7 +285,7 @@ TEST_F(MatlBuyPolicyTests, FixedActiveDormantMultipleCycles) {
TestFacility* fac = dynamic_cast<TestFacility*>(sim.agent);

cyclus::toolkit::ResBuf<cyclus::Material> inbuf;
ResBufTracker buf_tracker({&inbuf});
TotalInvTracker buf_tracker({&inbuf});
cyclus::toolkit::MatlBuyPolicy policy;
policy.Init(fac, &inbuf, "inbuf", &buf_tracker, throughput, a_dist, d_dist, NULL)
.Set("commod1").Start();
Expand Down Expand Up @@ -326,7 +326,7 @@ TEST_F(MatlBuyPolicyTests, UniformActiveDormant) {
TestFacility* fac = dynamic_cast<TestFacility*>(sim.agent);

cyclus::toolkit::ResBuf<cyclus::Material> inbuf;
ResBufTracker buf_tracker({&inbuf});
TotalInvTracker buf_tracker({&inbuf});
cyclus::toolkit::MatlBuyPolicy policy;
policy.Init(fac, &inbuf, "inbuf", &buf_tracker, throughput, a_dist, d_dist, NULL)
.Set("commod1").Start();
Expand Down Expand Up @@ -365,7 +365,7 @@ TEST_F(MatlBuyPolicyTests, NormalActiveDormant) {
TestFacility* fac = dynamic_cast<TestFacility*>(sim.agent);

cyclus::toolkit::ResBuf<cyclus::Material> inbuf;
ResBufTracker buf_tracker({&inbuf});
TotalInvTracker buf_tracker({&inbuf});
cyclus::toolkit::MatlBuyPolicy policy;
policy.Init(fac, &inbuf, "inbuf", &buf_tracker, throughput, a_dist, d_dist, NULL)
.Set("commod1").Start();
Expand Down Expand Up @@ -404,7 +404,7 @@ TEST_F(MatlBuyPolicyTests, MixedActiveDormant) {
TestFacility* fac = dynamic_cast<TestFacility*>(sim.agent);

cyclus::toolkit::ResBuf<cyclus::Material> inbuf;
ResBufTracker buf_tracker({&inbuf});
TotalInvTracker buf_tracker({&inbuf});
cyclus::toolkit::MatlBuyPolicy policy;
policy.Init(fac, &inbuf, "inbuf", &buf_tracker, throughput, a_dist, d_dist, NULL)
.Set("commod1").Start();
Expand Down Expand Up @@ -439,7 +439,7 @@ TEST_F(MatlBuyPolicyTests, RandomSizeUniform) {
TestFacility* fac = dynamic_cast<TestFacility*>(sim.agent);

cyclus::toolkit::ResBuf<cyclus::Material> inbuf;
ResBufTracker buf_tracker({&inbuf});
TotalInvTracker buf_tracker({&inbuf});
cyclus::toolkit::MatlBuyPolicy policy;
policy.Init(fac, &inbuf, "inbuf", &buf_tracker, throughput, NULL, NULL, size_dist)
.Set("commod1").Start();
Expand Down Expand Up @@ -470,7 +470,7 @@ TEST_F(MatlBuyPolicyTests, RandomSizeNormal) {
TestFacility* fac = dynamic_cast<TestFacility*>(sim.agent);

cyclus::toolkit::ResBuf<cyclus::Material> inbuf;
ResBufTracker buf_tracker({&inbuf});
TotalInvTracker buf_tracker({&inbuf});
cyclus::toolkit::MatlBuyPolicy policy;
policy.Init(fac, &inbuf, "inbuf", &buf_tracker, throughput, NULL, NULL, size_dist)
.Set("commod1").Start();
Expand Down Expand Up @@ -503,7 +503,7 @@ TEST_F(MatlBuyPolicyTests, RandomSizeAndFrequency) {
TestFacility* fac = dynamic_cast<TestFacility*>(sim.agent);

cyclus::toolkit::ResBuf<cyclus::Material> inbuf;
ResBufTracker buf_tracker({&inbuf});
TotalInvTracker buf_tracker({&inbuf});
cyclus::toolkit::MatlBuyPolicy policy;
policy.Init(fac, &inbuf, "inbuf", &buf_tracker, throughput, a_dist, d_dist, size_dist)
.Set("commod1").Start();
Expand Down

0 comments on commit 4981ca5

Please sign in to comment.