1#ifndef CYCLUS_SRC_TOOLKIT_TOTAL_INV_TRACKER_H_
2#define CYCLUS_SRC_TOOLKIT_TOTAL_INV_TRACKER_H_
39class TotalInvTracker {
44 : max_inv_size_(std::numeric_limits<double>::max()), qty_(0){};
46 TotalInvTracker(std::vector<ResBuf<Material>*> bufs,
47 double max_inv_size = std::numeric_limits<double>::max()) {
48 Init(bufs, max_inv_size);
55 void Init(std::vector<ResBuf<Material>*> bufs,
56 double max_inv_size = std::numeric_limits<double>::max()) {
57 if (bufs.size() == 0) {
59 "TotalInvTracker must be initialized with at least one ResBuf");
62 if (max_inv_size <= 0) {
64 "TotalInvTracker must be initialized with a positive capacity");
66 max_inv_size_ = max_inv_size;
71 inline double quantity() {
74 for (
int i = 0; i < num; i++) {
75 qty_ += bufs_[i]->quantity();
83 inline double capacity() {
84 return std::min(total_capacity_bufs(), max_inv_size_);
89 inline double total_capacity_bufs() {
92 for (
int i = 0; i < num; i++) {
93 cap += bufs_[i]->capacity();
99 inline double tracker_capacity() {
return max_inv_size_; }
102 inline double space() {
return std::max(0.0, capacity() - quantity()); }
106 inline double constrained_buf_space(ResBuf<Material>* buf) {
107 return std::min(buf->space(), space());
111 inline bool empty() {
return quantity() == 0; }
115 inline int num_bufs() {
116 int num = bufs_.size();
119 "TotalInvTracker has not been initialized, no buffers to track");
127 void set_capacity(
double cap) {
128 if (quantity() - cap >
eps_rsrc()) {
129 std::stringstream ss;
130 ss << std::setprecision(17) <<
"new capacity " << cap
131 <<
" lower than existing quantity " << quantity();
132 throw ValueError(ss.str());
137 bool buf_in_tracker(ResBuf<Material>* buf) {
138 for (
int i = 0; i < num_bufs(); i++) {
139 if (bufs_[i] == buf) {
147 double max_inv_size_;
149 std::vector<ResBuf<Material>*> bufs_;
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
double eps_rsrc()
an epsilon value to be used by resources