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;
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();
98 throw ValueError(
"bulk storage resbufs cannot keep packaging. Only one of the two options can be true.");
107 inline int count()
const {
return rs_.size(); }
116 inline double space()
const {
return std::max(0.0, cap_ - qty_); }
119 inline bool empty()
const {
return rs_.empty(); }
131 std::stringstream
ss;
132 ss << std::setprecision(17) <<
"removal quantity " << qty
133 <<
" larger than buff quantity " << this->
quantity();
137 std::vector<typename T::Ptr>
rs;
145 quan =
r->quantity();
148 tmp = boost::dynamic_pointer_cast<T>(
r->ExtractRes(
left));
152 rs_present_.erase(
r);
155 qty_ -=
r->quantity();
171 typename T::Ptr
Pop(
double qty) {
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();
313 std::vector<typename T::Ptr>
rss;
315 for (
int i = 0; i <
rs.size(); i++) {
316 r = boost::dynamic_pointer_cast<T>(
rs[i]);
318 throw CastError(
"pushing wrong type of resource onto ResBuf");
324 for (
int i = 0; i <
rss.size(); i++) {
328 throw ValueError(
"Resource pushing breaks capacity limit.");
331 for (
int i = 0; i <
rss.size(); i++) {
332 if (rs_present_.count(
rss.at(i)) == 1) {
333 throw KeyError(
"Duplicate resource pushing attempted");
337 for (
int i = 0; i <
rss.size(); i++) {
338 if (!is_bulk_ || rs_.size() == 0) {
339 if (!keep_packaging_) {
340 rss[i]->ChangePackage();
342 rs_.push_back(
rss[i]);
343 rs_present_.insert(
rss[i]);
345 rs_.front()->Absorb(
rss[i]);
355 for (
int i = 0; i < rs_.size(); i++) {
366 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
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters