Samchon Framework for CPP  1.0.0
TSPSlave.hpp
1 #pragma once
2 #include <samchon/example/interaction/Slave.hpp>
3 
4 #include <samchon/example/tsp/Scheduler.hpp>
5 
6 #include <iostream>
7 
8 namespace samchon
9 {
10 namespace example
11 {
12 namespace interaction
13 {
14  using namespace std;
15 
16  using namespace library;
17  using namespace protocol;
18 
28  class TSPSlave
29  : public Slave
30  {
31  private:
32  typedef Slave super;
33 
34  public:
35  /* ---------------------------------------------------------------------------------
36  CONSTRUCTORS
37  --------------------------------------------------------------------------------- */
43  TSPSlave(const string &ip)
44  : super(ip, 37100)
45  {
46  };
47  virtual ~TSPSlave() = default;
48 
49  protected:
50  /* ---------------------------------------------------------------------------------
51  INVOKE MESSAGE CHAIN
52  --------------------------------------------------------------------------------- */
53  virtual void optimize(shared_ptr<XML> xml, size_t index, size_t size) override
54  {
55  super::optimize(xml, index, size);
56 
57  tsp::Scheduler scheduler;
58  scheduler.construct(xml);
59  scheduler.optimize();
60 
61  cout << scheduler.toString() << endl << endl;
62  sendData( make_shared<Invoke>("replyOptimization", scheduler.toXML()) );
63  };
64 
65  public:
66  /* ---------------------------------------------------------------------------------
67  MAIN
68  --------------------------------------------------------------------------------- */
72  static void main()
73  {
74  string ip;
75  int port;
76 
77  cout << "----------------------------------------------------------------------------" << endl;
78  cout << " TSP SOLVER SLAVE" << endl;
79  cout << "----------------------------------------------------------------------------" << endl;
80  cout << " ip: "; cin >> ip;
81  cout << endl;
82 
83  TSPSlave slave(ip);
84  slave.start();
85  };
86  };
87 };
88 };
89 };
TSPSlave(const string &ip)
Construct from ip address of the master.
Definition: TSPSlave.hpp:43
virtual void optimize(shared_ptr< XML > xml, size_t index, size_t size) override
Optimize something and report the result.
Definition: TSPSlave.hpp:53
A slave system solving TSP.
Definition: TSPSlave.hpp:28
A slave system for optimizing something.
Definition: Slave.hpp:43
static void main()
Main function.
Definition: TSPSlave.hpp:72