1#ifndef CYCLUS_SRC_TOOLKIT_RES_BUF_H_
2#define CYCLUS_SRC_TOOLKIT_RES_BUF_H_
21typedef std::vector<Resource::Ptr>
ResVec;
22typedef std::vector<Material::Ptr>
MatVec;
63 ResBuf(
bool is_bulk =
false,
bool keep_pkg =
false)
64 : qty_(0), is_bulk_(is_bulk) {
74 inline double capacity()
const {
return cap_; }
83 throw ValueError(
"capacity must not be negative");
88 ss << std::setprecision(17) <<
"new capacity " << cap
89 <<
" lower than existing quantity " <<
quantity();
99 "bulk storage resbufs cannot keep packaging. Only one of the two "
100 "options can be true.");
109 inline int count()
const {
return rs_.size(); }
118 inline double space()
const {
return std::max(0.0, cap_ - qty_); }
121 inline bool empty()
const {
return rs_.empty(); }
133 std::stringstream ss;
134 ss << std::setprecision(17) <<
"removal quantity " << qty
135 <<
" larger than buff quantity " << this->
quantity();
139 std::vector<typename T::Ptr> rs;
144 while (left > 0 &&
count() > 0) {
147 quan = r->quantity();
150 tmp = boost::dynamic_pointer_cast<T>(r->ExtractRes(left));
154 rs_present_.erase(r);
157 qty_ -= r->quantity();
178 typename T::Ptr
Pop(
double qty,
double eps) {
180 std::stringstream ss;
181 ss << std::setprecision(17) <<
"removal quantity " << qty
182 <<
" larger than buff quantity " << this->
quantity();
198 std::vector<typename T::Ptr>
PopN(
int n) {
199 if (
count() < n || n < 0) {
200 std::stringstream ss;
201 ss <<
"remove count " << n <<
" larger than buff count " <<
count();
205 std::vector<typename T::Ptr> rs;
206 for (
int i = 0; i < n; i++) {
207 typename T::Ptr r = rs_.front();
208 qty_ -= r->quantity();
211 rs_present_.erase(r);
224 if (rs_.size() < 1) {
225 throw ValueError(
"cannot peek at resource from an empty buff");
236 if (rs_.size() < 1) {
237 throw ValueError(
"cannot pop resource from an empty buff");
240 typename T::Ptr r = rs_.front();
242 rs_present_.erase(r);
243 qty_ -= r->quantity();
250 if (rs_.size() < 1) {
251 throw ValueError(
"cannot pop resource from an empty buff");
254 typename T::Ptr r = rs_.back();
256 rs_present_.erase(r);
257 qty_ -= r->quantity();
273 typename T::Ptr m = boost::dynamic_pointer_cast<T>(r);
275 throw CastError(
"pushing wrong type of resource onto ResBuf");
277 std::stringstream ss;
278 ss <<
"resource pushing breaks capacity limit: space=" <<
space()
279 <<
", rsrc->quantity()=" << r->quantity();
281 }
else if (rs_present_.count(m) == 1) {
282 throw KeyError(
"duplicate resource push attempted");
285 if (!is_bulk_ || rs_.size() == 0) {
287 if (!keep_packaging_) {
291 rs_present_.insert(m);
293 rs_.front()->Absorb(m);
295 qty_ += r->quantity();
311 template <
class B>
void Push(std::vector<B> rs) {
312 std::vector<typename T::Ptr> rss;
314 for (
int i = 0; i < rs.size(); i++) {
315 r = boost::dynamic_pointer_cast<T>(rs[i]);
317 throw CastError(
"pushing wrong type of resource onto ResBuf");
323 for (
int i = 0; i < rss.size(); i++) {
324 tot_qty += rss.at(i)->quantity();
327 throw ValueError(
"Resource pushing breaks capacity limit.");
330 for (
int i = 0; i < rss.size(); i++) {
331 if (rs_present_.count(rss.at(i)) == 1) {
332 throw KeyError(
"Duplicate resource pushing attempted");
336 for (
int i = 0; i < rss.size(); i++) {
337 if (!is_bulk_ || rs_.size() == 0) {
338 if (!keep_packaging_) {
339 rss[i]->ChangePackage();
341 rs_.push_back(rss[i]);
342 rs_present_.insert(rss[i]);
344 rs_.front()->Absorb(rss[i]);
354 for (
auto rs : rs_) {
355 rs->Decay(curr_time);
365 qty_ = rs_.front()->quantity();
379 bool keep_packaging_;
382 std::list<typename T::Ptr> rs_;
383 std::set<typename T::Ptr> rs_present_;
For failed casts that shouldn't.
For failed retrieval/insertion of key-based data into/from data structures.
boost::shared_ptr< Resource > Ptr
For values that are too big, too small, etc.
Declares the CycArithmetic class, which holds arithmetic algorithms.
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
double eps()
a generic epsilon value