2 #include <samchon/protocol/master/ParallelClientArrayMediator.hpp> 3 #include <samchon/protocol/master/ParallelSlaveClientMediator.hpp> 5 #include <samchon/example/interaction/SlaveDriver.hpp> 6 #include <samchon/example/packer/Packer.hpp> 8 #include <samchon/protocol/Invoke.hpp> 9 #include <samchon/library/CombinedPermutationGenerator.hpp> 45 :
public protocol::master::ParallelClientArrayMediator
48 typedef protocol::master::ParallelClientArrayMediator super;
54 std::shared_ptr<packer::Packer>
packer;
80 dynamic_cast<protocol::master::ParallelSlaveClientMediator*
>(slave)->setAddress(
"127.0.0.1", 37300);
82 packer = std::make_shared<packer::Packer>();
88 virtual auto createChild(std::shared_ptr<library::XML>) -> protocol::ExternalSystem*
override 93 virtual void addClient(protocol::Socket *socket)
override 95 std::cout <<
"A client has connected." << std::endl;
97 super::addClient(socket);
104 virtual void sendPieceData(std::shared_ptr<protocol::Invoke> invoke,
size_t index,
size_t size)
106 if (invoke->getListener() ==
"optimize")
108 std::cout <<
"----------------------------------------------------------------------------" << std::endl;
109 std::cout <<
" OPTIMIZE FROM " << index <<
", SIZE: " << size << std::endl;
110 std::cout <<
"----------------------------------------------------------------------------" << std::endl;
114 super::sendPieceData(invoke, index, size);
116 virtual void replyData(std::shared_ptr<protocol::Invoke> invoke)
override 118 if (invoke->getListener() ==
"replyOptimization")
134 std::unique_lock<std::mutex> uk(mtx);
136 std::shared_ptr<packer::Packer>
packer(
new packer::Packer());
137 packer->construct(xml);
139 std::cout <<
"An optimization process from a slave system has completed" << std::endl;
140 std::cout <<
"\tOrdinary minimum price: " << this->packer->calcPrice()
141 <<
", New Price from the slave: " << packer->calcPrice() << std::endl;
143 if (this->packer->calcPrice() == 0 || packer->calcPrice() < this->packer->calcPrice())
144 this->packer = packer;
146 if (++optimized < this->size())
149 std::cout <<
"Parallel optimization has completed." << std::endl;
150 std::cout << packer->toString() << std::endl << std::endl;
152 slave->sendData(std::make_shared<protocol::Invoke>(
"replyOptimization", packer->toXML()));
167 std::cout <<
"----------------------------------------------------------------------------" << std::endl;
168 std::cout <<
" PACKER MEDIATOR" << std::endl;
169 std::cout <<
"----------------------------------------------------------------------------" << std::endl;
A slave system's driver for optimization.