10 double fill_max,std::string strategy) {
12 throw ValueError(
"fill_min and fill_max must be non-negative");
15 throw ValueError(
"fill_min must be less than or equal to fill_max");
27 unpackaged_ =
Ptr(
new Package(unpackaged_name_));
34 if (strategy_ ==
"uniform") {
36 }
else if (strategy_ ==
"normal") {
38 (fill_min_ + fill_max_) / 2,
39 (fill_max_ - fill_min_) / 6,
46 std::vector<double> packages;
47 if ((qty - fill_min_) < -
eps_rsrc()) {
58 if (strategy_ ==
"first") {
59 fill_mass = fill_max_;
60 }
else if (strategy_ ==
"equal") {
61 int num_min_fill = std::floor(qty / fill_min_);
62 int num_max_fill = std::ceil(qty / fill_max_);
63 if (num_min_fill >= num_max_fill) {
65 fill_mass = qty / num_max_fill;
68 fill_mass = fill_max_;
72 if (strategy_ ==
"first" || strategy_ ==
"equal") {
73 fill_mass = std::min(qty, fill_mass);
74 num_at_fill_mass =
static_cast<int>(std::floor(qty / fill_mass));
76 packages.assign(num_at_fill_mass, fill_mass);
78 qty -= num_at_fill_mass * fill_mass;
81 if (strategy_ ==
"uniform" || strategy_ ==
"normal") {
84 while ( qty >= std::max(
eps_rsrc(), fill_max_) ) {
85 fill_mass = dist_->sample();
86 packages.push_back(fill_mass);
91 if (qty >= std::max(
eps_rsrc(),fill_min_) ) {
93 packages.push_back(qty);
101Package::Package(std::string name,
double fill_min,
double fill_max,
102 std::string strategy) :
103 name_(name), fill_min_(fill_min), fill_max_(fill_max), strategy_(strategy) {
104 if (
name == unpackaged_name_) {
106 throw ValueError(
"can't create a new package with name 'unpackaged'");
110 throw ValueError(
"Invalid strategy for package: " + strategy_);
119 throw ValueError(
"fill_min and fill_max must be non-negative");
122 throw ValueError(
"fill_min must be less than or equal to fill_max");
132 if (!unrestricted_) {
135 return unrestricted_;
139 if (qty < fill_min_) {
144 if (strategy_ ==
"first") {
146 }
else if (strategy_ ==
"equal" || strategy_ ==
"hybrid") {
149 int num_at_min_fill = qty / fill_min_;
150 int num_at_max_fill = (qty + fill_max_ - 1) / fill_max_;
152 if (num_at_min_fill >= num_at_max_fill) {
155 double dbl_fill_mass = (double)qty / (
double)num_at_max_fill;
156 return std::floor(dbl_fill_mass);
169 if (pkgs == 0 || pkgs < fill_min_) {
172 }
else if (name_ == unrestricted_name_) {
175 }
else if (strategy_ ==
"first" || strategy_ ==
"equal") {
180 shippable = std::min(pkgs, (pkgs / TU_fill) * TU_fill);
183 }
else if (strategy_ ==
"hybrid") {
184 while ((pkgs > 0) && (pkgs >= fill_min_)) {
186 shippable += TU_fill;
194TransportUnit::TransportUnit(std::string name,
int fill_min,
int fill_max, std::string strategy) :
195 name_(name), fill_min_(fill_min), fill_max_(fill_max), strategy_(strategy) {
196 if (
name == unrestricted_name_) {
198 throw ValueError(
"can't create a new transport unit with name 'unrestricted'");
202 throw ValueError(
"Invalid strategy for transport unit: " + strategy_);
boost::shared_ptr< NormalDoubleDist > Ptr
Package is a class that packages materials into discrete items in ways.
static void ExceedsSplitLimits(int pkgs, std::string ss_extra="")
static Ptr Create(std::string name, double fill_min=0, double fill_max=std::numeric_limits< double >::max(), std::string strategy="first")
static Ptr & unpackaged()
boost::shared_ptr< Package > Ptr
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...
std::string strategy() const
bool IsValidStrategy(std::string strategy)
TransportUnit is a class that can be used in conjunction with packages to restrict the amount of mate...
std::string strategy() const
int GetTransportUnitFill(int qty)
Returns number of packages for each transport unit.
boost::shared_ptr< TransportUnit > Ptr
int MaxShippablePackages(int pkgs)
Returns the max number of transport units that can be shipped from the available quantity.
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.
static Ptr & unrestricted()
For values that are too big, too small, etc.
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
double eps_rsrc()
an epsilon value to be used by resources