4 #include <samchon/examples/interaction/base/MasterBase.hpp>     5 #include <samchon/examples/packer/Packer.hpp>    16         base::MasterBase *master;
    18         std::shared_ptr<packer::Packer> best_packer;
    19         size_t requested_size;
    20         size_t completed_count;
    23         PackerRequest(base::MasterBase *master)
    25             this->master = master;
    27         void init(
size_t size)
    29             best_packer = 
nullptr;
    30             this->completed_count = 0;
    31             this->requested_size = size;
    34         void optimize(std::shared_ptr<library::XML> xml)
    36             std::shared_ptr<packer::Packer> packer(
new packer::Packer());
    37             packer->construct(xml);
    39             auto invoke = std::make_shared<protocol::Invoke>(
"optimizePacker", packer->toXML());
    40             size_t size = library::CombinedPermutationGenerator(packer->size(), packer->productSize()).size();
    42             std::cout << 
"Start Packer optimization: #" << size << std::endl;
    45         void replyOptimization(std::shared_ptr<library::XML> xml)
    47             std::shared_ptr<packer::Packer> packer(
new packer::Packer());
    48             packer->construct(xml);
    50             std::cout << 
"A slave has finished his optimization: $" << packer->calcPrice() << std::endl;
    53             if (best_packer == 
nullptr || best_packer->calcPrice() == 0 ||
    54                 packer->calcPrice() < best_packer->calcPrice())
    56                 std::cout << 
"The slave renewed the best solution" << std::endl;
    61             if (++completed_count == requested_size)
    62                 master->getParent()->sendData
    64                     std::make_shared<protocol::Invoke>(
"replyPackerOptimization", best_packer->toXML())