Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
7270e02
first pass on reworking facility_cost.cycpp.h, still needs work.
dean-krueger Dec 10, 2025
1286a46
second pass at reformatting this for MC, fixed a few errors with wher…
dean-krueger Dec 10, 2025
a53b30a
reorganized and refined after a review. Made MC caclulation more cent…
dean-krueger Dec 15, 2025
8c0aae7
moved a few of the one-liner functions to just variables in the singl…
dean-krueger Dec 17, 2025
c4efc5f
changelog
dean-krueger Dec 17, 2025
e44e5fc
removed extra code for calculating the fixed and capital costs of pro…
dean-krueger Jan 4, 2026
0b2fee3
renamed facility_cost to marginal_cost, since that's more the directi…
dean-krueger Jan 4, 2026
f0793a2
removed institution and region cost files since they no longer do any…
dean-krueger Jan 4, 2026
32dbe02
removed region_cost.cycpp.h call from null_region, fixed an inconsist…
dean-krueger Jan 4, 2026
1b2a1e3
changes to allow discrete event timing based on dynamic timeline updates
meg-krieg Feb 16, 2026
1c23f3b
deleted print statements
meg-krieg Feb 17, 2026
a0391f7
deleted print statements
meg-krieg Feb 17, 2026
06ed963
fixing a seg fault bug
meg-krieg Feb 18, 2026
4a421b3
personal feature testings
meg-krieg Feb 23, 2026
ae2dcc7
moving decom from inst tock
meg-krieg Feb 25, 2026
6263f3f
adding decom condition to agent
meg-krieg Feb 25, 2026
463297e
changing default behavior
meg-krieg Mar 3, 2026
c23ca08
default behav
meg-krieg Mar 6, 2026
d08509a
changing event end
meg-krieg Mar 17, 2026
d2cff0f
second discrete event implementation (cyclus 1.6v default)
meg-krieg May 6, 2026
4728bfe
tweaking explanatory comments
meg-krieg May 6, 2026
aa1458a
adding functions to headers
meg-krieg May 6, 2026
b6cbaa7
stop trackingin gitignore
meg-krieg May 6, 2026
2f39d6f
restoring .gitignore
meg-krieg May 6, 2026
fc5b723
added in annotations/explanations
meg-krieg May 6, 2026
7d72b87
adding sched to toolkit, adjusting maps
meg-krieg May 14, 2026
086899c
print testing phase
meg-krieg May 22, 2026
7c802fe
deleting some debugging comments
meg-krieg May 29, 2026
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,4 @@ cyclus/cycpp.py

# Rever
rever/
.vscode
.vscode
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@ Since last release
* Allow multiple archetype blocks to facilitate includes (#1874)

**Changed:**

* Made the Unit Tests far less verbose by suppressing log output during RunSim (#1927)
* Reworked the facility/instituion/region_cost.cycpp.h files to work with MC (#1931)
* Changed Dockerfile to use boost and boost-cpp instead of libboost-devel (#1906)
* Changed TradeExecutor to use adjusted preferences from ExchangeContext (#1897)
* Ran clang-format on src directory (#1881, #1893)
Expand Down
4 changes: 1 addition & 3 deletions agents/null_region.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ NullRegion::NullRegion(cyclus::Context* ctx) : cyclus::Region(ctx) {}

NullRegion::~NullRegion() {}

void NullRegion::EnterNotify() {
InitEconParameters();
}
void NullRegion::EnterNotify() {}

extern "C" cyclus::Agent* ConstructNullRegion(cyclus::Context* ctx) {
return new NullRegion(ctx);
Expand Down
3 changes: 0 additions & 3 deletions agents/null_region.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@ class NullRegion : public cyclus::Region {
"institutions but exhibits null behavior. " \
"No parameters are given when using the " \
"null region."}

private:
#include "toolkit/region_cost.cycpp.h"
};

} // namespace cyclus
Expand Down
11 changes: 11 additions & 0 deletions src/context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,17 @@ void Context::UnregisterTimeListener(TimeListener* tl) {
ti_->UnregisterTimeListener(tl);
}

void Context::UnregisterCommodityConsumer(std::set<std::string> in_commods, Trader* e){
return;
for (std::string commod : in_commods){
commodity_consumers_.at(commod).erase(e);
}
}

void Context::RegisterCommoditiesTraded(int t, std::set<std::string> trade_commods){
commodities_traded_[t].merge(trade_commods);
}

Datum* Context::NewDatum(std::string title) {
return rec_->NewDatum(title);
}
Expand Down
40 changes: 38 additions & 2 deletions src/context.h
Original file line number Diff line number Diff line change
Expand Up @@ -183,6 +183,38 @@ class Context {
/// @return the current set of traders registered for resource exchange.
inline const std::set<Trader*>& traders() const { return traders_; }

////////////////////////////////////////////////////////// discrete cyclus functions ///////////////////

inline void RegisterCommodityConsumer(std::string in_commod, Trader* e){commodity_consumers_[in_commod].insert(e);}

void UnregisterCommodityConsumer(std::set<std::string> in_commods, Trader* e);

inline const std::map<std::string, std::set<Trader*>>& consumers() const {return commodity_consumers_;}


void RegisterCommoditiesTraded(int t, std::set<std::string> trade_commods);

inline std::set<std::string>& CommoditiesTraded(int t) {return commodities_traded_.at(t);}

inline void RegisterRequesters(int time, Trader* e) {request_queue_[time].insert(e);
} //conditions to register an event is up to archetype dev

inline void EventComplete(int t) {request_queue_.erase(t);} // fit this so it purges any 0 entries as well as the most current completed event !

inline const std::set<Trader*>& EventRequesters(int t) const {return request_queue_.at(t); }

inline const std::map<int,std::set<Trader*>>& EventTimeline() const { return request_queue_; }

//// currently unused

inline void Populate(int t) {if (pop_sched_.count(t)>0){request_queue_.at(t) = traders();};} //there are more use cases for this

inline void SchedPopulate(int next_event) {pop_sched_.insert(next_event); request_queue_[next_event];} // there are more use cases for this

inline void DeregisterRequesters(int time, Trader* e) {request_queue_.at(time).erase(e);} //conditions to deregister an event is up to archetype dev

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

/// Create a new agent by cloning the named prototype. The returned agent is
/// not initialized as a simulation participant.
///
Expand Down Expand Up @@ -364,16 +396,20 @@ class Context {
/// contains archetype specs of all agents for which version have already
/// been recorded in the db
std::set<std::string> rec_ver_;

std::map<std::string, Agent*> protos_;
std::map<std::string, Composition::Ptr> recipes_;
std::map<std::string, Package::Ptr> packages_;
std::map<std::string, TransportUnit::Ptr> transport_units_;
std::set<Agent*> agent_list_;
std::set<Trader*> traders_;

std::map<int, std::set<Trader*>> request_queue_;
std::map<std::string, std::set<Trader*>> commodity_consumers_;
std::map<int,std::set<std::string>> commodities_traded_;
std::set<int> pop_sched_;

std::map<std::string, int> n_prototypes_;
std::map<std::string, int> n_specs_;

SimInfo si_;
Timer* ti_;
ExchangeSolver* solver_;
Expand Down
1 change: 1 addition & 0 deletions src/cyclus.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ extern "C" {
#include "toolkit/symbolic_function_factories.h"
#include "toolkit/symbolic_functions.h"
#include "toolkit/timeseries.h"
#include "toolkit/scheduling_function.h"

// Undefines isnan from pyne
#ifdef isnan
Expand Down
47 changes: 43 additions & 4 deletions src/facility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,12 @@
#include "institution.h"
#include "logger.h"
#include "timer.h"
#include <boost/enable_shared_from_this.hpp>
#include <boost/shared_ptr.hpp>

namespace cyclus {

Facility::Facility(Context* ctx) : Trader(this), Agent(ctx) {
Facility::Facility(Context* ctx) : Trader(this), Agent(ctx), schedule_helper_(this) {
kind_ = std::string("Facility");
}

Expand All @@ -24,13 +26,33 @@ void Facility::InitFrom(Facility* m) {
}

void Facility::Build(Agent* parent) {
Agent::Build(parent);
Agent::Build(parent);
//for agents WITHOUT the need for a checkdecom status, they can easily schedule decom at build (only reactor/separations use this right now)
if (lifetime() >= 0 && CheckDecommissionCondition() == NULL) {
context()->SchedDecom(this, exit_time());
}
for (auto& requests: GetMatlRequests()) {
if(requests){
for(auto& request : requests->requests()) {
// //hopefully this is a dry run with no impact on DRE (ie adding porfolios)
std::string commodity = request->commodity();
context()->RegisterCommodityConsumer(commodity,this);
FillInCommods(commodity); //any repeats should be
}
}
}
std::cout<<"Agent of type" << prototype()<< " has " << GetInCommods().size()<<" in_commods_ size in Trader \n\n\n";
// FORCEFULLY SET THE COMMOD MAP (not relying on tick/tock event request)
context()-> RegisterCommoditiesTraded(context()->time(), GetInCommods());
std::cout <<"Context commodity map size called in Facility::Build is "<< (context()->CommoditiesTraded(context()->time())).size()<<" (not empty) \n\n\n\n";
}

void Facility::EnterNotify() {
Agent::EnterNotify();
context()->RegisterTrader(dynamic_cast<Trader*>(this));
context()->RegisterTimeListener(this);
schedule_helper_.InitialTrade();
//all agents who have been build should want to immediately trade
}

std::string Facility::str() {
Expand All @@ -41,17 +63,34 @@ std::string Facility::str() {
}

void Facility::Decommission() {
if (!CheckDecommissionCondition()) {
if (!CheckDecommissionCondition()) { //check what happens w NULL
throw Error("Cannot decommission " + prototype());
}

context()->UnregisterTrader(dynamic_cast<Trader*>(this));
context()->UnregisterTimeListener(this);
context()->UnregisterCommodityConsumer(GetInCommods(),this);

Agent::Decommission();
}

bool Facility::CheckDecommissionCondition() {
return true;
return NULL;
}

void Facility::Tock(){ // archetype developers need to invoke this method in tock
EventRequest();
}

void Facility::Tick(){
SetTraded(false); //archetype developers need to invoke this method in tick
}

void Facility::EventRequest(){
schedule_helper_.FixIncSchedule(); //FixIncSchedule schedules like cyclus 1.6v
for(int i: schedule_helper_.EventTime()){ //probably needed in future...
selftimes_.insert(i);
}
}

Region* Facility::GetParentRegion(int layer) {
Expand Down
27 changes: 25 additions & 2 deletions src/facility.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "agent.h"
#include "time_listener.h"
#include "trader.h"
#include "toolkit/scheduling_function.h"

namespace cyclus {

Expand Down Expand Up @@ -100,7 +101,7 @@ class Facility : public TimeListener, public Agent, public Trader {

/// facilities over write this method if a condition must be met
/// before their destructors can be called
virtual bool CheckDecommissionCondition();
virtual bool CheckDecommissionCondition();

/// every agent should be able to print a verbose description
virtual std::string str();
Expand All @@ -127,6 +128,24 @@ class Facility : public TimeListener, public Agent, public Trader {
return std::set<BidPortfolio<Product>::Ptr>();
}

virtual void EventRequest(); //maybe an archetype dev will want to replace this
// this is intended to be a default behavior should an archetype developer not invoke their own "Scheduling Function "
//within cycamore
// void EventRequest(){
//schedule_helper_.<chosen function>(args);;
// or more directly schedule_helper.schedule(time,commods)
//}

virtual void Tock();

virtual void Tick();

//return all future events scheduled for some facility (this function is useful for deregistration context()->DeregisterRequesters(--)
// purposes and for archetype developer scheduled facility behavior)
inline const std::set<int>& GetFutureEvents() const {
return selftimes_;
}

/// default implementation for material preferences.
virtual void AdjustMatlPrefs(PrefMap<Material>::type& prefs) {}

Expand All @@ -139,7 +158,6 @@ class Facility : public TimeListener, public Agent, public Trader {
virtual void GetMatlTrades(
const std::vector<Trade<Material>>& trades,
std::vector<std::pair<Trade<Material>, Material::Ptr>>& responses) {
std::cout << "in material facility getmatltrades\n";
}

/// @brief default implementation for responding to product trades
Expand Down Expand Up @@ -193,6 +211,11 @@ class Facility : public TimeListener, public Agent, public Trader {
/// @brief Returns all parent facilities by traversing up the hierarchy
/// @return Vector of all parent facilities, ordered from closest to farthest
std::vector<Facility*> GetAllParentFacilities();


private:
std::set<int> selftimes_;
toolkit::SchedulingFunctions schedule_helper_;
};

} // namespace cyclus
Expand Down
2 changes: 1 addition & 1 deletion src/institution.cc
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ void Institution::Tock() {
Agent* a = *it;
if (a->lifetime() != -1 && context()->time() >= a->exit_time()) {
Facility* fac = dynamic_cast<Facility*>(a);
if (fac == NULL || fac->CheckDecommissionCondition()) {
if (fac == NULL || fac->CheckDecommissionCondition()) { // any facility without overwritten checkdecomcondition expects a NULL, only true will pass ||
CLOG(LEV_INFO3) << a->prototype()
<< " has reached the end of its lifetime";
context()->SchedDecom(a);
Expand Down
28 changes: 23 additions & 5 deletions src/resource_exchange.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ template <class T> class ResourceExchange {
inline ExchangeContext<T>& ex_ctx() { return ex_ctx_; }

/// @brief queries traders and collects all requests for bids
void AddAllRequests() {
InitTraders();
std::for_each(traders_.begin(),
traders_.end(),
void AddAllRequests() { // I think we should add other commodity consumers of type a into the mix within InitRequesters() as well.
InitRequesters();
std::for_each(requesters_.begin(),
requesters_.end(),
std::bind(&cyclus::ResourceExchange<T>::AddRequests_,
this,
std::placeholders::_1));
Expand Down Expand Up @@ -112,6 +112,24 @@ template <class T> class ResourceExchange {
}
}

void InitRequesters() {
auto orig = InitRequestersAdjacent(); //we do not need the whole ass map tbh.
std::set<Trader*>::iterator it;
for (it = orig.begin(); it != orig.end(); ++it) {
requesters_.insert(*it);
}
}

std::set<Trader*> InitRequestersAdjacent() {
std::set<Trader*> traders;
auto commod_map = sim_ctx_->consumers();
auto map2 = sim_ctx_->CommoditiesTraded(sim_ctx_->time());
for (std::string commods : map2){
traders.merge(commod_map[commods]);
}
return traders;
}

/// @brief queries a given facility agent for
void AddRequests_(Trader* t) {
std::set<typename RequestPortfolio<T>::Ptr> rp = QueryRequests<T>(t);
Expand Down Expand Up @@ -160,7 +178,7 @@ template <class T> class ResourceExchange {
// determinism of Cyclus overall. This allows all traders' resource
// exchange functions are called in a much closer to deterministic order.
std::set<Trader*, trader_compare> traders_;

std::set<Trader*,trader_compare> requesters_;
Context* sim_ctx_;
ExchangeContext<T> ex_ctx_;
};
Expand Down
Loading