2 #include <samchon/protocol/SharedEntityArray.hpp> 3 #include <samchon/examples/packer/Wrapper.hpp> 5 #include <samchon/library/FactorialGenerator.hpp> 17 using namespace library;
18 using namespace protocol;
59 this->reserved = make_shared<ProductArray>();
60 this->sample = make_shared<Wrapper>();
71 WrapperArray(
const string &name,
int price,
int volume,
int weight)
74 this->reserved = make_shared<ProductArray>();
75 this->sample = make_shared<Wrapper>(name, price, volume, weight);
89 this->reserved = make_shared<ProductArray>();
90 this->sample = wrapperArray.
sample;
95 virtual void construct(shared_ptr<XML> xml)
override 97 super::construct(xml);
99 sample->construct(xml);
103 virtual auto createChild(shared_ptr<XML>) ->
Wrapper*
override 121 if (product->getVolume() > sample->getVolume() ||
122 product->getWeight() > sample->getWeight())
127 reserved->push_back(product);
151 if(reserved->empty() ==
true)
155 shared_ptr<WrapperArray> minWrapperArray =
nullptr;
157 for (
size_t i = 0; i < factorial.size(); i++)
159 shared_ptr<WrapperArray> wrapperArray(
new WrapperArray(*
this));
160 vector<size_t> &row = factorial[i];
162 for (
size_t j = 0; j < row.size(); j++)
164 shared_ptr<Product> &product = this->reserved->at(row[j]);
166 if (wrapperArray->empty() ==
true ||
167 wrapperArray->at(wrapperArray->size() - 1)->tryInsert(product) ==
false)
172 wrapperArray->emplace_back(wrapper);
177 if (minWrapperArray ==
nullptr ||
178 wrapperArray->size() < minWrapperArray->size())
180 minWrapperArray = wrapperArray;
184 assign(minWrapperArray->begin(), minWrapperArray->end());
194 return sample->getPrice() * (int)size();
200 virtual auto TAG()
const ->
string override 202 return "wrapperArray";
209 virtual auto toXML() const -> shared_ptr<
XML>
override 211 shared_ptr<XML> &xml = super::toXML();
212 xml->insertAllProperties(sample->toXML());
222 string str =
"Category - " + sample->get_name() +
"\n";
223 for (
size_t i = 0; i < size(); i++)
224 str += at(i)->toString() +
"\n";
auto tryInsert(shared_ptr< Product > product) -> bool
Try to insert a product into reserved list.
auto tryInsert(shared_ptr< Product > product) -> bool
Try to insert a product into the wrapper.
WrapperArray(const WrapperArray &wrapperArray)
Copy Constructor.
virtual auto CHILD_TAG() const -> string override
A tag name of children.
shared_ptr< ProductArray > reserved
A list for reserved Product(s).
auto toString() const -> string
Return a string represents Wrapper(s) of same type.
An Entity and a container of children Entity objects.
Factorical case generator.
auto calcPrice() const -> int
Calculate price of the Wrapper(s)
WrapperArray(const string &name, int price, int volume, int weight)
Construct from arguments of sample.
WrapperArray()
Default Constructor.
void optimize()
Optimize to retrieve the best solution.
virtual auto toXML() const -> shared_ptr< XML > override
Get an XML object represents the EntityGroup.
shared_ptr< Wrapper > sample
A sample wrapper used to copy.
A wrapper can contain products.
An array of wrapper with same category (name).