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,
47 if ((qty - fill_min_) < -
eps_rsrc()) {
58 if (strategy_ ==
"first") {
60 }
else if (strategy_ ==
"equal") {
72 if (strategy_ ==
"first" || strategy_ ==
"equal") {
81 if (strategy_ ==
"uniform" || strategy_ ==
"normal") {
84 while ( qty >= std::max(
eps_rsrc(), fill_max_) ) {
91 if (qty >= std::max(
eps_rsrc(),fill_min_) ) {
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") {
169 if (
pkgs == 0 ||
pkgs < fill_min_) {
172 }
else if (name_ == unrestricted_name_) {
175 }
else if (strategy_ ==
"first" || strategy_ ==
"equal") {
183 }
else if (strategy_ ==
"hybrid") {
184 while ((
pkgs > 0) && (
pkgs >= fill_min_)) {
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
T OptionalQuery(InfileTree *tree, std::string query, T default_val)
a query method for optional parameters