Samchon Framework for CPP  1.0.0
PackerSlave.hpp
1 #pragma once
2 #include <samchon/example/interaction/Slave.hpp>
3 
4 #include <samchon/example/packer/Packer.hpp>
5 #include <samchon/protocol/Invoke.hpp>
6 
7 namespace samchon
8 {
9 namespace example
10 {
11 namespace interaction
12 {
13  using namespace std;
14 
15  using namespace library;
16  using namespace protocol;
17 
28  : public Slave
29  {
30  private:
31  typedef Slave super;
32 
33  public:
34  /* ---------------------------------------------------------------------------------
35  CONSTRUCTORS
36  --------------------------------------------------------------------------------- */
43  PackerSlave(const string &ip, int port)
44  : super(ip, port)
45  {
46  };
47  virtual ~PackerSlave() = default;
48 
49  protected:
50  /* ---------------------------------------------------------------------------------
51  INVOKE MESSAGE CHAIN
52  --------------------------------------------------------------------------------- */
60  virtual void optimize(shared_ptr<XML> xml, size_t index, size_t size) override
61  {
62  super::optimize(xml, index, size);
63 
64  packer::Packer packer;
65  packer.construct(xml);
66  packer.optimize(index, size);
67 
68  cout << packer.toString() << endl << endl;
69  sendOptimization(packer.toXML());
70  };
71 
72  public:
73  /* ---------------------------------------------------------------------------------
74  MAIN
75  --------------------------------------------------------------------------------- */
79  static void main()
80  {
81  string ip;
82  int port;
83 
84  cout << "----------------------------------------------------------------------------" << endl;
85  cout << " PACKER SLAVE" << endl;
86  cout << "----------------------------------------------------------------------------" << endl;
87  cout << " ip: "; cin >> ip;
88  cout << " port: "; cin >> port;
89 
90  PackerSlave slave(ip, port);
91  slave.start();
92  };
93  };
94 };
95 };
96 };
PackerSlave(const string &ip, int port)
Construct from ip and port of the master.
Definition: PackerSlave.hpp:43
A slave system for solving Packer.
Definition: PackerSlave.hpp:27
virtual void optimize(shared_ptr< XML > xml, size_t index, size_t size) override
Optimize TSP and report the result.
Definition: PackerSlave.hpp:60
static void main()
Main function.
Definition: PackerSlave.hpp:79
A slave system for optimizing something.
Definition: Slave.hpp:43