6#include <boost/lexical_cast.hpp>
11 : cyclus::Facility(ctx),
12 throughput(std::numeric_limits<double>::max()),
13 inventory_size(std::numeric_limits<double>::max()),
16 package(cyclus::Package::unpackaged_name()),
17 transport_unit(cyclus::TransportUnit::unrestricted_name()),
22void Source::InitFrom(Source* m) {
23 #pragma cyclus impl initfromcopy cycamore::Source
24 cyclus::toolkit::CommodityProducer::Copy(m);
27void Source::InitFrom(cyclus::QueryableBackend* b) {
28 #pragma cyclus impl initfromdb cycamore::Source
29 namespace tk = cyclus::toolkit;
30 tk::CommodityProducer::Add(tk::Commodity(outcommod),
31 tk::CommodInfo(throughput, throughput));
34std::string Source::str() {
35 namespace tk = cyclus::toolkit;
38 if (cyclus::toolkit::CommodityProducer::Produces(
39 cyclus::toolkit::Commodity(outcommod))) {
44 ss << cyclus::Facility::str() <<
" supplies commodity '" << outcommod
45 <<
"' with recipe '" << outrecipe <<
"' at a throughput of "
46 << throughput <<
" kg per time step "
47 <<
" commod producer members: "
48 <<
" produces " << outcommod <<
"?: " << ans
49 <<
" throughput: " << cyclus::toolkit::CommodityProducer::Capacity(outcommod)
50 <<
" with package type: " <<
package
51 << " and transport unit type: " << transport_unit
52 << " cost: " << cyclus::toolkit::CommodityProducer::Cost(outcommod);
56void Source::EnterNotify() {
57 cyclus::Facility::EnterNotify();
61void Source::Build(cyclus::Agent* parent) {
62 Facility::Build(parent);
64 using cyclus::CompMap;
65 using cyclus::Composition;
66 using cyclus::Material;
69 cyclus::Material::Ptr all_inv;
70 Composition::Ptr blank_comp = Composition::CreateFromMass(CompMap());
71 all_inv = (outrecipe.empty() || context() == NULL) ? \
72 Material::Create(
this, inventory_size, blank_comp) : \
73 Material::Create(
this, inventory_size, context()->GetRecipe(outrecipe));
74 inventory.Push(all_inv);
78std::set<cyclus::BidPortfolio<cyclus::Material>::Ptr> Source::GetMatlBids(
79 cyclus::CommodMap<cyclus::Material>::type& commod_requests) {
80 using cyclus::BidPortfolio;
81 using cyclus::CapacityConstraint;
82 using cyclus::Material;
83 using cyclus::Package;
84 using cyclus::Request;
85 using cyclus::TransportUnit;
87 double max_qty = std::min(throughput, inventory.quantity());
88 cyclus::toolkit::RecordTimeSeries<double>(
"supply"+outcommod,
this,
90 LOG(cyclus::LEV_INFO3,
"Source") << prototype() <<
" is bidding up to "
91 << max_qty <<
" kg of " << outcommod;
92 LOG(cyclus::LEV_INFO5,
"Source") <<
"stats: " << str();
94 std::set<BidPortfolio<Material>::Ptr> ports;
95 if (max_qty < cyclus::eps()) {
97 }
else if (commod_requests.count(outcommod) == 0) {
101 BidPortfolio<Material>::Ptr port(
new BidPortfolio<Material>());
102 std::vector<Request<Material>*>& requests = commod_requests[outcommod];
103 std::vector<Request<Material>*>::iterator it;
104 for (it = requests.begin(); it != requests.end(); ++it) {
105 Request<Material>* req = *it;
106 Material::Ptr target = req->target();
107 double qty = std::min(target->quantity(), max_qty);
110 std::vector<double> bids = context()->GetPackage(package)->GetFillMass(qty);
113 int shippable_pkgs = context()->GetTransportUnit(transport_unit)
114 ->MaxShippablePackages(bids.size());
115 if (shippable_pkgs < bids.size()) {
116 bids.erase(bids.begin() + shippable_pkgs, bids.end());
119 std::vector<double>::iterator bit;
120 for (bit = bids.begin(); bit != bids.end(); ++bit) {
122 m = outrecipe.empty() ? \
123 Material::CreateUntracked(*bit, target->comp()) : \
124 Material::CreateUntracked(*bit, context()->GetRecipe(outrecipe));
125 port->AddBid(req, m,
this);
129 CapacityConstraint<Material> cc(max_qty);
130 port->AddConstraint(cc);
135void Source::GetMatlTrades(
136 const std::vector<cyclus::Trade<cyclus::Material> >& trades,
137 std::vector<std::pair<cyclus::Trade<cyclus::Material>,
138 cyclus::Material::Ptr> >& responses) {
139 using cyclus::Material;
142 int shippable_trades = context()->GetTransportUnit(transport_unit)
143 ->MaxShippablePackages(trades.size());
145 std::vector<Trade<Material> >::const_iterator it;
146 for (it = trades.begin(); it != trades.end(); ++it) {
147 if (shippable_trades > 0) {
148 double qty = it->amt;
150 Material::Ptr m = inventory.Pop(qty);
152 std::vector<Material::Ptr> m_pkgd = m->Package<Material>(context()->GetPackage(package));
154 if (m->quantity() > cyclus::eps()) {
160 Material::Ptr response;
161 if (m_pkgd.size() > 0) {
165 response = m_pkgd[0];
166 shippable_trades -= 1;
169 response = Material::CreateUntracked(0, m->comp());
172 if (outrecipe.empty() && response->comp() != it->request->target()->comp()) {
173 response->Transmute(it->request->target()->comp());
176 responses.push_back(std::make_pair(*it, response));
177 LOG(cyclus::LEV_INFO5,
"Source") << prototype() <<
" sent an order"
178 <<
" for " << response->quantity() <<
" of " << outcommod;
183void Source::RecordPosition() {
184 std::string specification = this->spec();
186 ->NewDatum(
"AgentPosition")
187 ->AddVal(
"Spec", specification)
188 ->AddVal(
"Prototype", this->prototype())
189 ->AddVal(
"AgentId",
id())
190 ->AddVal(
"Latitude", latitude)
191 ->AddVal(
"Longitude", longitude)
196 return new Source(ctx);
Source(cyclus::Context *ctx)
void RecordPosition()
Records an agent's latitude and longitude to the output db.
cyclus::Agent * ConstructSource(cyclus::Context *ctx)
cyclus::toolkit::Position coordinates