12 throw ValueError(
"fill_min and fill_max must be non-negative");
14 throw ValueError(
"fill_min must be less than or equal to fill_max");
25 unpackaged_ =
Ptr(
new Package(unpackaged_name_));
32 if (strategy_ ==
"uniform") {
34 }
else if (strategy_ ==
"normal") {
37 (fill_max_ - fill_min_) / 6,
44 std::vector<double> packages;
45 if ((qty - fill_min_) < -
eps_rsrc()) {
56 if (strategy_ ==
"first") {
57 fill_mass = fill_max_;
58 }
else if (strategy_ ==
"equal") {
59 int num_min_fill = std::floor(qty / fill_min_);
60 int num_max_fill = std::ceil(qty / fill_max_);
61 if (num_min_fill >= num_max_fill) {
63 fill_mass = qty / num_max_fill;
67 fill_mass = fill_max_;
71 if (strategy_ ==
"first" || strategy_ ==
"equal") {
72 fill_mass = std::min(qty, fill_mass);
73 num_at_fill_mass =
static_cast<int>(std::floor(qty / fill_mass));
75 packages.assign(num_at_fill_mass, fill_mass);
77 qty -= num_at_fill_mass * fill_mass;
80 if (strategy_ ==
"uniform" || strategy_ ==
"normal") {
83 while (qty >= std::max(
eps_rsrc(), fill_max_)) {
84 fill_mass = dist_->sample();
85 packages.push_back(fill_mass);
90 if (qty >= std::max(
eps_rsrc(), fill_min_)) {
92 packages.push_back(qty);
100Package::Package(std::string name,
double fill_min,
double fill_max,
101 std::string strategy)
105 strategy_(strategy) {
106 if (
name == unpackaged_name_) {
108 throw ValueError(
"can't create a new package with name 'unpackaged'");
112 throw ValueError(
"Invalid strategy for package: " + strategy_);
122 throw ValueError(
"fill_min and fill_max must be non-negative");
124 throw ValueError(
"fill_min must be less than or equal to fill_max");
134 if (!unrestricted_) {
135 unrestricted_ =
Ptr(
new TransportUnit(unrestricted_name_));
137 return unrestricted_;
141 if (qty < fill_min_) {
146 if (strategy_ ==
"first") {
148 }
else if (strategy_ ==
"equal" || strategy_ ==
"hybrid") {
151 int num_at_min_fill = qty / fill_min_;
152 int num_at_max_fill = (qty + fill_max_ - 1) / fill_max_;
154 if (num_at_min_fill >= num_at_max_fill) {
157 double dbl_fill_mass = (double)qty / (
double)num_at_max_fill;
158 return std::floor(dbl_fill_mass);
171 if (pkgs == 0 || pkgs < fill_min_) {
174 }
else if (name_ == unrestricted_name_) {
177 }
else if (strategy_ ==
"first" || strategy_ ==
"equal") {
182 shippable = std::min(pkgs, (pkgs / TU_fill) * TU_fill);
185 }
else if (strategy_ ==
"hybrid") {
186 while ((pkgs > 0) && (pkgs >= fill_min_)) {
188 shippable += TU_fill;
196TransportUnit::TransportUnit(std::string name,
int fill_min,
int fill_max,
197 std::string strategy)
201 strategy_(strategy) {
202 if (
name == unrestricted_name_) {
205 "can't create a new transport unit with name 'unrestricted'");
209 throw ValueError(
"Invalid strategy for transport unit: " + strategy_);
boost::shared_ptr< NormalDoubleDist > Ptr
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)
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