CYCLUS
Loading...
Searching...
No Matches
package.h
Go to the documentation of this file.
1#ifndef CYCLUS_SRC_PACKAGE_H_
2#define CYCLUS_SRC_PACKAGE_H_
3
4#include <limits>
5#include <string>
6#include <vector>
7#include <cmath>
8#include <boost/shared_ptr.hpp>
9
10#include "error.h"
11#include "logger.h"
13
14namespace cyclus {
15
16/// Package is a class that packages materials into discrete items in ways
17// that mimic realistic nuclear material handling. Package is a parameter
18// of materials and products, with default unpackaged
19class Package {
20 public:
21 typedef boost::shared_ptr<Package> Ptr;
22
23 // create a new package type. Should be called by the context only
24 // (see Context::AddPackage), unless you want an untracked package
25 // type (which you probably don't)
26 static Ptr Create(std::string name, double fill_min = 0,
27 double fill_max = std::numeric_limits<double>::max(),
28 std::string strategy = "first");
29
30 /// Returns optimal fill mass for a resource to be packaged, and number of
31 /// packages that can be crated at that fill mass (note that up to one
32 /// additional package may be possible to create with a lower fill mass,
33 /// which much be checked separately).
34 /// Can be used to determine how to respond to requests for material, and
35 /// to actually package and send off trades.
36 /// Packaging strategy "first" simply fills the packages one by one to the
37 /// maximum fill. Therefore, it should always try to max fill.
38 /// Packaging strategy "equal" tries to fill all packages to the same mass.
39 /// This tries to find the optimal number and fill mass of packages given
40 /// the packaging limitations. It does this by calculating bounding fills,
41 /// floor(quantity/fill_min) and ceiling(quantity/fill_max).
42 /// Packaging strategy "uniform" fills packages with a random mass between
43 /// fill_min and fill_max, if at least fill_max is available. If less than
44 /// fill_max is available, a partial package is filled with the total mass.
45 /// Packaging strategy "normal" fills packages with a random mass between
46 /// fill_min and fill_max, with a normal distribution. Mean is the middle
47 /// of fill_min and fill_max, standard deviation is 1/6 of the range such
48 /// that 3 sigma is the range. If less than fill_max is available, a
49 /// partial package is filled with the total mass (no dist sampling).
50 /// There might be a scenario where there is no solution, i.e. an integer
51 /// number of packages cannot be filled with no remainder. In this case,
52 /// the most effective fill strategy is to fill to the max. Numeric example:
53 /// quantity = 5, fill_min = 3, fill_max = 4. num_min_fill = floor(5/3) = 1,
54 /// num_max_fill = ceil(5/4) = 2. num_min_fill < num_max_fill, so fill to
55 /// the max.
56 std::vector<double> GetFillMass(double qty);
57
58 // returns package name
59 std::string name() const { return name_; }
60 // returns package fill min
61 double fill_min() const { return fill_min_; }
62 // returns package fill max
63 double fill_max() const { return fill_max_; }
64 // returns package strategy
65 std::string strategy() const { return strategy_; }
66
67 // returns the unpackaged package name
68 static std::string unpackaged_name() { return unpackaged_name_; }
69
70 // returns the unpackaged singleton object
71 static Ptr& unpackaged();
72
73 static void ExceedsSplitLimits(int pkgs, std::string ss_extra = "") {
74 if (pkgs > SplitLimit() || pkgs < (0.9*std::numeric_limits<int>::min())) {
75 throw ValueError("Resource::Package() cannot package into more than " +
76 std::to_string(SplitLimit()) +
77 " items at once." + ss_extra);
78 } else if (pkgs > SplitWarn()) {
79 // if pkgs is int min, overflow has occurred
80 CLOG(cyclus::LEV_INFO1) << "Resource::Package() is attempting to "
81 << "package into " << pkgs
82 << " items at once, is this intended? "
83 << ss_extra;
84 }
85 return;
86 }
87
88 // When a resource is split into individual items, warn when more than
89 // one million items are trying to be created at once
90 static int SplitWarn() { return 100000; }
91
92 // Numeric limits for splitting resources is based on vector limits and
93 // memory constraints. Use unsigned int max / 100 to be safe
94 static int SplitLimit() {
95 return (std::numeric_limits<int>::max() / 10);
96 }
97
98 bool IsValidStrategy(std::string strategy) {
99 return strategy == "first"
100 || strategy == "equal"
101 || strategy == "uniform"
102 || strategy == "normal";
103 }
104
105 void SetDistribution();
106
107 private:
108 Package(std::string name,
109 double fill_min = 0,
110 double fill_max = std::numeric_limits<double>::max(),
111 std::string strategy = "first");
112
113 static constexpr char unpackaged_name_[11] = "unpackaged";
114 static Ptr unpackaged_;
115
116 std::string name_;
117 double fill_min_;
118 double fill_max_;
119 std::string strategy_;
121};
122
123/// TransportUnit is a class that can be used in conjunction with packages to
124/// restrict the amount of material that can be traded between facilities.
125/// Unlike Packages, TransportUnits are not a property of resources. They are
126/// simply applied at the response to request for bids phase and then the trade
127/// execution to determine whether the available number of packages is
128/// allowable given the TransportUnit parameters. Default is unrestricted
129/// Strategy "first" simply fill transport units one by one to max fill
130/// Strategy "equal" tries to fill all transport units with the
131/// Strategy "hybrid" is iterative, recursively filling transport units
132/// with the max fill until the remaining quantity can be filled with the
133/// at least the min fill. This is the most efficient strategy
135 public:
136 typedef boost::shared_ptr<TransportUnit> Ptr;
137
138 /// create a new transport unit type. Should be called by the context only
139 /// (see Context::AddTransportUnit), unless you want an untracked transport
140 /// unit type (which you probably don't)
141 static Ptr Create(std::string name, int fill_min = 0,
142 int fill_max = std::numeric_limits<int>::max(),
143 std::string strategy = "first");
144
145 /// Returns number of packages for each transport unit.
146 /// same number of packages
147 int GetTransportUnitFill(int qty);
148
149 /// Returns the max number of transport units that can be shipped from the
150 /// available quantity
151 int MaxShippablePackages(int pkgs);
152
153 // returns transport unit name
154 std::string name() const { return name_; }
155 // returns transport unit fill min
156 int fill_min() const { return fill_min_; }
157 // returns transport unit fill max
158 int fill_max() const { return fill_max_; }
159 // returns transport unit strategy
160 std::string strategy() const { return strategy_; }
161
162 // returns the unrestricted id (1)
163 static int unrestricted_id() { return unrestricted_id_; }
164
165 // returns the unrestricted transport unit name
166 static std::string unrestricted_name() { return unrestricted_name_; }
167
168 // returns the unrestricted singleton object
169 static Ptr& unrestricted();
170
171 private:
172 TransportUnit(std::string name,
173 int fill_min = 0,
174 int fill_max = std::numeric_limits<int>::max(),
175 std::string strategy = "hybrid");
176
177 static const int unrestricted_id_ = 1;
178 static constexpr char unrestricted_name_[13] = "unrestricted";
179 static Ptr unrestricted_;
180 static int next_tranport_unit_id_;
181
182 std::string name_;
183 int id_;
184 int fill_min_;
185 int fill_max_;
186 std::string strategy_;
187};
188
189} // namespace cyclus
190
191#endif // CYCLUS_SRC_PACKAGE_H_
boost::shared_ptr< DoubleDistribution > Ptr
Package is a class that packages materials into discrete items in ways.
Definition package.h:19
static void ExceedsSplitLimits(int pkgs, std::string ss_extra="")
Definition package.h:73
static Ptr Create(std::string name, double fill_min=0, double fill_max=std::numeric_limits< double >::max(), std::string strategy="first")
Definition package.cc:9
static Ptr & unpackaged()
Definition package.cc:24
static int SplitLimit()
Definition package.h:94
boost::shared_ptr< Package > Ptr
Definition package.h:21
static std::string unpackaged_name()
Definition package.h:68
std::string name() const
Definition package.h:59
std::vector< double > GetFillMass(double qty)
Returns optimal fill mass for a resource to be packaged, and number of packages that can be crated at...
Definition package.cc:45
void SetDistribution()
Definition package.cc:33
double fill_min() const
Definition package.h:61
double fill_max() const
Definition package.h:63
std::string strategy() const
Definition package.h:65
bool IsValidStrategy(std::string strategy)
Definition package.h:98
static int SplitWarn()
Definition package.h:90
TransportUnit is a class that can be used in conjunction with packages to restrict the amount of mate...
Definition package.h:134
std::string strategy() const
Definition package.h:160
int fill_max() const
Definition package.h:158
static std::string unrestricted_name()
Definition package.h:166
int fill_min() const
Definition package.h:156
int GetTransportUnitFill(int qty)
Returns number of packages for each transport unit.
Definition package.cc:138
static int unrestricted_id()
Definition package.h:163
boost::shared_ptr< TransportUnit > Ptr
Definition package.h:136
int MaxShippablePackages(int pkgs)
Returns the max number of transport units that can be shipped from the available quantity.
Definition package.cc:165
static Ptr Create(std::string name, int fill_min=0, int fill_max=std::numeric_limits< int >::max(), std::string strategy="first")
create a new transport unit type.
Definition package.cc:117
static Ptr & unrestricted()
Definition package.cc:131
std::string name() const
Definition package.h:154
For values that are too big, too small, etc.
Definition error.h:41
Code providing rudimentary logging capability for the Cyclus core.
#define CLOG(level)
Definition logger.h:39
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
Definition agent.cc:14
@ LEV_INFO1
Information helpful for simulation users and developers alike - least verbose.
Definition logger.h:53
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters