4 #include <samchon/examples/interaction/base/MasterBase.hpp> 6 #include <samchon/examples/tsp/Travel.hpp> 7 #include <samchon/library/FactorialGenerator.hpp> 18 base::MasterBase *master;
20 std::shared_ptr<tsp::Travel> best_travel;
21 size_t requested_size;
22 size_t completed_count;
25 TSPRequest(base::MasterBase *master)
27 this->master = master;
29 void init(
size_t size)
31 best_travel =
nullptr;
32 this->completed_count = 0;
33 this->requested_size = size;
36 void optimize(std::shared_ptr<library::XML> xml)
38 std::shared_ptr<tsp::Travel> travel(
new tsp::Travel());
39 travel->construct(xml);
41 auto invoke = std::make_shared<protocol::Invoke>(
"optimizeTSP", travel->toXML());
42 size_t size = library::FactorialGenerator(travel->size()).size();
44 std::cout <<
"Start Packer optimization: #" << size << std::endl;
47 void replyOptimization(std::shared_ptr<library::XML> xml)
49 std::shared_ptr<tsp::Travel> travel(
new tsp::Travel());
50 travel->construct(xml);
52 std::cout <<
"A slave has finished his optimization: " << travel->calcDistance() <<
" km" << std::endl;
55 if (best_travel ==
nullptr || best_travel->calcDistance() == 0 ||
56 travel->calcDistance() < best_travel->calcDistance())
58 std::cout <<
"The slave renewed the best solution" << std::endl;
63 if (++completed_count == requested_size)
64 master->getParent()->sendData
66 std::make_shared<protocol::Invoke>(
"replyTSPOptimization", best_travel->toXML())