1 #ifndef CYCLUS_SRC_TOOLKIT_RES_BUF_H_ 2 #define CYCLUS_SRC_TOOLKIT_RES_BUF_H_ 21 typedef std::vector<Resource::Ptr>
ResVec;
22 typedef std::vector<Material::Ptr>
MatVec;
23 typedef std::vector<Product::Ptr>
ProdVec;
64 ResBuf() : cap_(INFINITY), qty_(0) { }
71 inline double capacity()
const {
return cap_; }
81 ss << std::setprecision(17) <<
"new capacity " << cap
82 <<
" lower than existing quantity " <<
quantity();
90 inline int count()
const {
return rs_.size(); }
94 inline double quantity()
const {
return qty_; }
99 inline double space()
const {
return std::max(0.0, cap_ - qty_); }
102 inline bool empty()
const {
return rs_.empty(); }
113 typename T::Ptr
Pop(
double qty) {
115 std::stringstream ss;
116 ss << std::setprecision(17) <<
"removal quantity " << qty
117 <<
" larger than buff quantity " << this->
quantity();
121 std::vector<typename T::Ptr> rs;
126 while (left > 0 &&
count() > 0) {
129 quan = r->quantity();
132 tmp = boost::dynamic_pointer_cast<T>(r->ExtractRes(left));
136 rs_present_.erase(r);
139 qty_ -= r->quantity();
152 typename T::Ptr
Pop(
double qty,
double eps) {
154 std::stringstream ss;
155 ss << std::setprecision(17) <<
"removal quantity " << qty
156 <<
" larger than buff quantity " << this->
quantity();
172 std::vector<typename T::Ptr>
PopN(
int n) {
173 if (
count() < n || n < 0) {
174 std::stringstream ss;
175 ss <<
"remove count " << n <<
" larger than buff count " <<
count();
179 std::vector<typename T::Ptr> rs;
180 for (
int i = 0; i < n; i++) {
181 typename T::Ptr r = rs_.front();
182 qty_ -= r->quantity();
185 rs_present_.erase(r);
198 if (rs_.size() < 1) {
199 throw ValueError(
"cannot peek at resource from an empty buff");
210 if (rs_.size() < 1) {
211 throw ValueError(
"cannot pop resource from an empty buff");
214 typename T::Ptr r = rs_.front();
216 rs_present_.erase(r);
217 qty_ -= r->quantity();
224 if (rs_.size() < 1) {
225 throw ValueError(
"cannot pop resource from an empty buff");
228 typename T::Ptr r = rs_.back();
230 rs_present_.erase(r);
231 qty_ -= r->quantity();
247 typename T::Ptr m = boost::dynamic_pointer_cast<T>(r);
249 throw CastError(
"pushing wrong type of resource onto ResBuf");
251 std::stringstream ss;
252 ss <<
"resource pushing breaks capacity limit: space=" <<
space()
253 <<
", rsrc->quantity()=" << r->quantity();
255 }
else if (rs_present_.count(m) == 1) {
256 throw KeyError(
"duplicate resource push attempted");
260 rs_present_.insert(m);
261 qty_ += r->quantity();
278 std::vector<typename T::Ptr> rss;
280 for (
int i = 0; i < rs.size(); i++) {
281 r = boost::dynamic_pointer_cast<T>(rs[i]);
283 throw CastError(
"pushing wrong type of resource onto ResBuf");
289 for (
int i = 0; i < rss.size(); i++) {
290 tot_qty += rss.at(i)->quantity();
293 throw ValueError(
"Resource pushing breaks capacity limit.");
296 for (
int i = 0; i < rss.size(); i++) {
297 if (rs_present_.count(rss.at(i)) == 1) {
298 throw KeyError(
"Duplicate resource pushing attempted");
302 for (
int i = 0; i < rss.size(); i++) {
303 rs_.push_back(rss[i]);
304 rs_present_.insert(rss[i]);
315 qty_ = rs_.front()->quantity();
325 std::list<typename T::Ptr> rs_;
326 std::set<typename T::Ptr> rs_present_;
332 #endif // CYCLUS_SRC_TOOLKIT_RES_BUF_H_
For values that are too big, too small, etc.
For failed casts that shouldn't.
double eps_rsrc()
an epsilon value to be used by resources
boost::shared_ptr< Resource > Ptr
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or.org/Osi/browser/trunk.
Declares the CycArithmetic class, which holds arithmetic algorithms.
For failed retrieval/insertion of key-based data into/from data structures.
double eps()
a generic epsilon value