CYCLUS
Loading...
Searching...
No Matches
matl_sell_policy.h
Go to the documentation of this file.
1#ifndef CYCLUS_SRC_TOOLKIT_MATL_SELL_POLICY_H_
2#define CYCLUS_SRC_TOOLKIT_MATL_SELL_POLICY_H_
3
4#include <string>
5
6#include "composition.h"
7#include "material.h"
8#include "res_buf.h"
9#include "trader.h"
10#include "package.h"
11
12namespace cyclus {
13namespace toolkit {
14
15/// MatlSellPolicy performs semi-automatic inventory management of a material
16/// buffer by making offers and trading away materials in an attempt to empty
17/// the buffer's inventory every time step.
18///
19/// For simple behavior, policies virtually eliminate the need to write any code
20/// for resource exchange. Just assign a few policies to work with a few buffers
21/// and focus on writing the physics and other behvavior of your agent. Typical
22/// usage goes something like this:
23///
24/// @code
25/// class YourAgent : public Facility {
26/// public:
27/// ...
28///
29/// void EnterNotify() {
30/// Facility::EnterNotify(); // always do this first
31///
32/// policy_.Init(this, &outbuf_, "outbuf-label").Set(outcommod).Start();
33/// }
34/// ...
35///
36/// private:
37/// MatlSellPolicy policy_;
38/// ResBuf<Material> outbuf_;
39/// ...
40/// }
41/// @endcode
42///
43/// The policy needs to be initialized with its owning agent and the material
44/// buffer that is is managing. It also needs to be activated by calling the
45/// Start function for it to begin participation in resource exchange. And
46/// don't forget to add some commodities to offer on by calling Set. All policy
47/// configuration should usually occur in the agent's EnterNotify member
48/// function.
49///
50/// @warn When a policy's managing agent is deallocated, you MUST either
51/// call the policy's Stop function or delete the policy. Otherwise SEGFAULT.
52class MatlSellPolicy : public Trader {
53 public:
54 /// Creates an uninitialized policy. The Init function MUST be called before
55 /// anything else is done with the policy.
57
58 virtual ~MatlSellPolicy();
59
60 /// Configures the policy to keep buf empty every time step by offering away
61 /// as much material as possible. If quantize is greater than zero, the
62 /// policy will make exclusive, integral quantize kg offers. Otherwise, a
63 /// single offer will be sent each time step to empty the buffer's entire
64 /// inventory.
65 /// @param manager the agent
66 /// @param buf the resource buffer
67 /// @param name a unique name identifying this policy
68 /// @param throughput a maximum throughput per time step for material leaving
69 /// buf
70 /// @ignore_comp ignore the composition of material in buf. When making bids,
71 /// requested material compositions will be used. When making trades,
72 /// material in the buffer will have its composition transmuted to match the
73 /// requested material.
74 /// @param quantize If quantize is greater than zero, the policy will make
75 /// exclusive, integral quantize kg bids. Otherwise, single bids will
76 /// be sent matching the requested quantity.
77 /// @{
78 MatlSellPolicy& Init(Agent* manager, ResBuf<Material>* buf, std::string name);
80 double throughput);
82 bool ignore_comp);
84 double throughput, bool ignore_comp);
86 double throughput, bool ignore_comp,
87 double quantize,
88 std::string package_name = Package::unpackaged_name(),
90 /// @}
91
92 /// Instructs the policy to empty its buffer with offers on the given
93 /// commodity. This must be called at least once or the policy will do
94 /// nothing. The policy can offer on an arbitrary number of commodities by
95 /// calling Set multiple times.
96 MatlSellPolicy& Set(std::string commod);
97
98 /// Registers this policy as a trader in the current simulation. This
99 /// function must be called for the policy to begin participating in resource
100 /// exchange. Init MUST be called prior to calling this function. Start is
101 /// idempotent.
102 void Start();
103
104 /// Unregisters this policy as a trader in the current simulation. This
105 /// function need only be called if a policy is to be stopped *during* a
106 /// simulation (it is not required to be called explicitly at the end). Stop
107 /// is idempotent.
108 void Stop();
109
110 /// the current (total) limit on transactions, i.e., the quantity of resources
111 /// that can be transacted in a time step
112 double Limit() const;
113
114 /// whether trades will be denoted as exclusive or not
115 inline bool Excl() const { return quantize_ > 0; }
116
117 /// Trader Methods
118 /// @{
119 virtual std::set<BidPortfolio<Material>::Ptr> GetMatlBids(
120 CommodMap<Material>::type& commod_requests);
121 virtual void GetMatlTrades(
122 const std::vector<Trade<Material> >& trades,
123 std::vector<std::pair<Trade<Material>, Material::Ptr> >& responses);
124 /// }@
125
126 private:
127 void set_quantize(double x);
128 void set_throughput(double x);
129 void set_ignore_comp(bool x);
130 void set_package(std::string x);
131 void set_transport_unit(std::string x);
132
133 ResBuf<Material>* buf_;
134 std::set<std::string> commods_;
135 double quantize_;
136 double throughput_;
137 std::string name_;
138 bool ignore_comp_;
139 Package::Ptr package_;
140 TransportUnit::Ptr transport_unit_;
141};
142
143} // namespace toolkit
144} // namespace cyclus
145
146#endif
The abstract base class used by all types of agents that live and interact in a simulation.
Definition agent.h:49
boost::shared_ptr< Material > Ptr
Definition material.h:75
boost::shared_ptr< Package > Ptr
Definition package.h:21
static std::string unpackaged_name()
Definition package.h:68
A simple API for agents that wish to exchange resources in the simulation.
Definition trader.h:24
virtual Agent * manager()
Definition trader.h:28
static std::string unrestricted_name()
Definition package.h:166
boost::shared_ptr< TransportUnit > Ptr
Definition package.h:136
MatlSellPolicy performs semi-automatic inventory management of a material buffer by making offers and...
MatlSellPolicy()
Creates an uninitialized policy.
virtual void GetMatlTrades(const std::vector< Trade< Material > > &trades, std::vector< std::pair< Trade< Material >, Material::Ptr > > &responses)
default implementation for responding to material trades
virtual std::set< BidPortfolio< Material >::Ptr > GetMatlBids(CommodMap< Material >::type &commod_requests)
Trader Methods.
MatlSellPolicy & Init(Agent *manager, ResBuf< Material > *buf, std::string name)
Configures the policy to keep buf empty every time step by offering away as much material as possible...
void Stop()
Unregisters this policy as a trader in the current simulation.
MatlSellPolicy & Set(std::string commod)
Instructs the policy to empty its buffer with offers on the given commodity.
void Start()
Registers this policy as a trader in the current simulation.
bool Excl() const
whether trades will be denoted as exclusive or not
double Limit() const
the current (total) limit on transactions, i.e., the quantity of resources that can be transacted in ...
ResBuf is a helper class that provides semi-automated management of a collection of resources (e....
Definition res_buf.h:62
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters
std::map< std::string, std::vector< Request< T > * > > type
A Trade is a simple container that associates a request for a resource with a bid for that resource.
Definition trade.h:16