Skip to content

Commit

Permalink
(s,S) inventory policy
Browse files Browse the repository at this point in the history
  • Loading branch information
nuclearkatie committed Jan 31, 2024
1 parent 89c52fa commit debf2cf
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 7 deletions.
14 changes: 9 additions & 5 deletions src/storage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,23 @@ void Storage::InitFrom(cyclus::QueryableBackend* b) {
void Storage::EnterNotify() {
cyclus::Facility::EnterNotify();
inventory_tracker.set_capacity(max_inv_size);
if ((reorder_point >= 0 && reorder_quantity > 0)) {
if (reorder_point < 0) {
buy_policy.Init(this, &inventory, std::string("inventory"),
&inventory_tracker, throughput);
}
else if (reorder_quantity > 0) {
if (reorder_point + reorder_quantity > max_inv_size) {
throw cyclus::ValueError(
"reorder_point + reorder_quantity must be less than max_inv_size");
"reorder_point + reorder_quantity must be less than or equal to max_inv_size");
}
buy_policy.Init(this, &inventory, std::string("inventory"),
&inventory_tracker, throughput, "RQ",
reorder_quantity,
reorder_point);
reorder_quantity, reorder_point);
}
else {
buy_policy.Init(this, &inventory, std::string("inventory"),
&inventory_tracker, throughput);
&inventory_tracker, throughput, "sS",
max_inv_size, reorder_point);
}

// dummy comp, use in_recipe if provided
Expand Down
7 changes: 5 additions & 2 deletions src/storage.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,12 +211,15 @@ class Storage
#pragma cyclus var {"default": -1,\
"tooltip":"Reorder point",\
"doc":"The point at which the facility will request more material. "\
"Above this point, no request will be made. Must be less than max_inv_size",\
"Above this point, no request will be made. Must be less than max_inv_size."\
"If paired with reorder_quantity, this agent will have an (R,Q) inventory policy. "\
"If reorder_point is used alone, this agent will have an (s,S) inventory policy, "\
" with S (the maximum) being set at max_inv_size.",\
"uilabel":"Reorder Point"}
double reorder_point;

#pragma cyclus var {"default": -1,\
"tooltip":"Reorder amount",\
"tooltip":"Reorder amount (R,Q inventory policy)",\
"doc":"The amount of material that will be requested when the reorder point is reached. "\
"Exclusive request, so will demand exactly reorder_quantity."\
"Reorder_point + reorder_quantity must be less than max_inv_size.",\
Expand Down
40 changes: 40 additions & 0 deletions src/storage_tests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,46 @@ TEST_F(StorageTest, RQ_Inventory) {
cyclus::QueryResult qr = sim.db().Query("Transactions", &conds);
int n_trans = qr.rows.size();
EXPECT_EQ(3, n_trans) << "expected 3 transactions, got " << n_trans;
// check that the transactions occur at the expected time (0, 2, 4)
EXPECT_EQ(0, qr.GetVal<int>("Time", 0));
EXPECT_EQ(2, qr.GetVal<int>("Time", 1));
EXPECT_EQ(4, qr.GetVal<int>("Time", 2));

// check that all transactions are of size 3
qr = sim.db().Query("Resources", NULL);
EXPECT_EQ(3, qr.GetVal<double>("Quantity", 0));
}


TEST_F(StorageTest, sS_Inventory) {
std::string config =
" <in_commods> <val>spent_fuel</val> </in_commods> "
" <out_commods> <val>dry_spent</val> </out_commods> "
" <max_inv_size>5</max_inv_size>"
" <reorder_point>2</reorder_point>";

int simdur = 5;

cyclus::MockSim sim(cyclus::AgentSpec (":cycamore:Storage"), config, simdur);

sim.AddSource("spent_fuel").capacity(5).Finalize();
sim.AddSink("dry_spent").Finalize();

int id = sim.Run();

std::vector<cyclus::Cond> conds;
conds.push_back(cyclus::Cond("Commodity", "==", std::string("spent_fuel")));
cyclus::QueryResult qr = sim.db().Query("Transactions", &conds);
int n_trans = qr.rows.size();
EXPECT_EQ(3, n_trans) << "expected 3 transactions, got " << n_trans;
// check that the transactions occur at the expected time (0, 2, 4)
EXPECT_EQ(0, qr.GetVal<int>("Time", 0));
EXPECT_EQ(2, qr.GetVal<int>("Time", 1));
EXPECT_EQ(4, qr.GetVal<int>("Time", 2));

// check that all transactions are of size 3
qr = sim.db().Query("Resources", NULL);
EXPECT_EQ(5, qr.GetVal<double>("Quantity", 0));
}

TEST_F(StorageTest, PositionInitialize){
Expand Down

0 comments on commit debf2cf

Please sign in to comment.