CYCLUS
|
ResBuf is a helper class that provides semi-automated management of a collection of resources (e.g.
agent stocks and inventories). Constructed buffers have infinite capacity unless explicitly changed. Resource popping occurs in the order the resources were pushed (i.e. oldest resources are popped first), unless explicitly specified otherwise.
Typically, a ResBuf will be a member variable on an agent/archetype class. Resources can be added and retrieved from it as needed, and the buffer can be queried in various ways as done in the example below:
In this example, if there is sufficient material in inventory_, 2703 kg is removed as a single object that is then placed in another buffer (outventory_) each time step.
#include <res_buf.h>
Public Member Functions | |
double | capacity () const |
void | capacity (double cap) |
int | count () const |
void | Decay (int curr_time=-1) |
bool | empty () const |
bool | keep_packaging () const |
void | keep_packaging (bool keep_packaging) |
T::Ptr | Peek () |
T::Ptr | Pop () |
T::Ptr | Pop (double qty) |
T::Ptr | Pop (double qty, double eps) |
T::Ptr | PopBack () |
std::vector< typename T::Ptr > | PopN (int n) |
ResVec | PopNRes (int n) |
std::vector< typename T::Ptr > | PopVector (double qty) |
void | Push (Resource::Ptr r) |
template<class B > | |
void | Push (std::vector< B > rs) |
double | quantity () const |
ResBuf (bool is_bulk=false, bool keep_pkg=false) | |
double | space () const |
virtual | ~ResBuf () |
|
inline |
Sets the maximum quantity this buffer can hold (units based on constituent resource objects' units).
ValueError | the new capacity is lower (by eps_rsrc()) than the quantity of resources that exist in the buffer. |
|
inline |
|
inline |
|
inline |
|
inline |
|
inline |
Pops one resource object from the buffer.
Resources are not split and are retrieved in the order they were pushed (i.e. oldest first).
ValueError | the buffer is empty. |
|
inline |
Pops and returns the specified quantity from the buffer as a single resource object.
Resources are split if necessary in order to pop the exact quantity requested (within eps_rsrc()). Resources are retrieved in the order they were pushed (i.e. oldest first) and are squashed into a single object when returned.
Same behavior as Pop(double) except a non-zero eps may be specified.
eps is used only in cases where qty might be slightly larger than the buffer's current inventory quantity.
|
inline |
|
inline |
Pops the specified number of resource objects from the buffer.
Resources are not split and are retrieved in the order they were pushed (i.e. oldest first).
ValueError | the specified n is larger than the buffer's current resource count or the specified number is negative. |
|
inline |
Pops and returns the specified quantity from the buffer as a vector of resources.
Resources are split if necessary in order to pop the exact quantity requested (within eps_rsrc()). Resources are retrieved in the order they were pushed (i.e. oldest first).
ValueError | the specified pop quantity is larger than the buffer's current inventory. |
|
inline |
Pushes a single resource object to the buffer.
If not classified as a bulk storage buffer, resource objects are not combined in the buffer; they are stored as unique objects. The resource object is only pushed to the buffer if it does not cause the buffer to exceed its capacity.
ValueError | the pushing of the given resource object would cause the buffer to exceed its capacity. |
KeyError | the resource object to be pushed is already present in the buffer. |
|
inline |
Pushes one or more resource objects (as a std::vector) to the buffer.
If not classified as a bulk storage buffer, resource objects are not squashed in the buffer; they are stored as unique objects. The resource objects are only pushed to the buffer if they do not cause the buffer to exceed its capacity; otherwise none of the given resource objects are added to the buffer.
ValueError | adding the given resource objects would cause the buffer to exceed its capacity. |
KeyError | one or more of the resource objects to be added are already present in the buffer. |
|
inline |
|
inline |