2 #include <samchon/templates/distributed/DistributedProcess.hpp> 3 #include <samchon/templates/distributed/base/DistributedSystemArrayBase.hpp> 6 #include <samchon/examples/packer/Packer.hpp> 14 class PackerProcess :
public templates::distributed::DistributedProcess
17 typedef templates::distributed::DistributedProcess super;
20 PackerProcess(templates::distributed::base::DistributedSystemArrayBase *systemArray)
23 this->
name =
"packer";
25 virtual ~PackerProcess() =
default;
31 std::shared_ptr<packer::ProductArray> productArray(
new packer::ProductArray
33 std::make_shared<packer::Product>(
"Eraser", 500, 10, 70),
34 std::make_shared<packer::Product>(
"Eraser", 500, 10, 70),
35 std::make_shared<packer::Product>(
"Pencil", 400, 30, 35),
36 std::make_shared<packer::Product>(
"Book", 8000, 150, 300),
37 std::make_shared<packer::Product>(
"Book", 8000, 150, 300),
38 std::make_shared<packer::Product>(
"Drink", 1000, 75, 250),
39 std::make_shared<packer::Product>(
"Drink", 1000, 75, 250),
40 std::make_shared<packer::Product>(
"Drink", 1000, 75, 250),
41 std::make_shared<packer::Product>(
"Umbrella", 4000, 200, 1000),
42 std::make_shared<packer::Product>(
"Notebook-PC", 800000, 150, 850),
43 std::make_shared<packer::Product>(
"Notebook-PC", 800000, 150, 850),
44 std::make_shared<packer::Product>(
"Tablet-PC", 600000, 120, 450),
45 std::make_shared<packer::Product>(
"Tablet-PC", 600000, 120, 450)
48 std::unique_ptr<packer::Packer> packer(
new packer::Packer(productArray));
50 packer->emplace_back(
new packer::Wrapper(
"Large", 100, 200, 1000));
51 packer->emplace_back(
new packer::Wrapper(
"Medium", 70, 150, 500));
52 packer->emplace_back(
new packer::Wrapper(
"Small", 50, 100, 250));
55 sendData(std::make_shared<protocol::Invoke>(
"optimizePacker", packer->toXML()));
58 virtual void replyData(std::shared_ptr<protocol::Invoke> invoke)
override 60 if (invoke->getListener() ==
"replyOptimization")
61 printSolution(invoke->front()->getValueAsXML());
65 void printSolution(std::shared_ptr<library::XML> xml)
67 std::unique_ptr<packer::Packer> packer(
new packer::Packer());
68 packer->construct(xml);
70 std::cout <<
"The best packing solution: $" << packer->calcPrice() << std::endl;