2 #include <samchon/templates/distributed/DistributedProcess.hpp> 3 #include <samchon/templates/distributed/base/DistributedSystemArrayBase.hpp> 6 #include <samchon/library/Math.hpp> 7 #include <samchon/examples/tsp/Travel.hpp> 15 class TSPProcess :
public templates::distributed::DistributedProcess
18 typedef templates::distributed::DistributedProcess super;
21 TSPProcess(templates::distributed::base::DistributedSystemArrayBase *systemArray)
26 virtual ~TSPProcess() =
default;
32 std::unique_ptr<tsp::Travel> travel(
new tsp::Travel());
33 for (
size_t i = 0; i < 9; i++)
34 travel->emplace_back(
new tsp::GeometryPoint(i+1, Math::random(), Math::random()));
36 sendData(std::make_shared<protocol::Invoke>(
"optimizeTSP", travel->toXML()));
39 virtual void replyData(std::shared_ptr<protocol::Invoke> invoke)
override 41 if (invoke->getListener() ==
"replyOptimization")
42 printSolution(invoke->front()->getValueAsXML());
46 void printSolution(std::shared_ptr<library::XML> xml)
48 std::unique_ptr<tsp::Travel> travel(
new tsp::Travel());
49 travel->construct(xml);
51 std::cout <<
"The best travel: " << travel->calcDistance() <<
" km" << std::endl;