1 | using System;
|
---|
2 | using System.Threading;
|
---|
3 | using DistributedGA.Core.Domain;
|
---|
4 | using DistributedGA.Core.Implementation;
|
---|
5 | using DistributedGA.Core.Interface;
|
---|
6 |
|
---|
7 | namespace DistributedGA.Core.Host {
|
---|
8 | class Program {
|
---|
9 | static void Main(string[] args) {
|
---|
10 | try {
|
---|
11 | Console.WriteLine("Starting peer...");
|
---|
12 | IMessageHandler h = new PeerNetworkMessageHandler();
|
---|
13 | h.Init();
|
---|
14 | PeerInfo pi = h.GetPeerInfo();
|
---|
15 | Console.WriteLine(string.Format("Peer is hostet at IP: {0} and port: {1}", pi.IpAddress, pi.Port));
|
---|
16 | Thread.Sleep(1000 * 20);
|
---|
17 | Console.WriteLine("Current peers within network:");
|
---|
18 | foreach (var item in h.GetCurrentNetwork()) {
|
---|
19 | Console.WriteLine(string.Format("Peer at {0}:{1}", item.IpAddress, item.Port));
|
---|
20 | }
|
---|
21 | int i = 1;
|
---|
22 | while (i < 10) {
|
---|
23 | i++;
|
---|
24 | Thread.Sleep(1000 * 10);
|
---|
25 | var pop1 = CreatePopulation();
|
---|
26 | Console.WriteLine("Publish population into network...");
|
---|
27 | h.PublishMigrationInfo(pop1);
|
---|
28 | Console.WriteLine("Population published.");
|
---|
29 | Console.WriteLine("Recieved populations:");
|
---|
30 | foreach (var item in h.GetMigrationInfo()) {
|
---|
31 | Console.WriteLine(string.Format("Population with Quality: {0:2} in Iteration {1}", item.Quality, item.IterationNumber));
|
---|
32 | }
|
---|
33 | }
|
---|
34 | } catch (Exception ex) {
|
---|
35 | Console.WriteLine(ex.Message);
|
---|
36 | Console.WriteLine("press any key to continue...");
|
---|
37 | Console.ReadLine();
|
---|
38 | }
|
---|
39 |
|
---|
40 | }
|
---|
41 |
|
---|
42 | private static SolutionInfo[] CreatePopulation() {
|
---|
43 | SolutionInfo si1 = new SolutionInfo() {
|
---|
44 | IterationNumber = 1,
|
---|
45 | Quality = 3.5f,
|
---|
46 | Solution = new Solution() {
|
---|
47 | }
|
---|
48 | };
|
---|
49 | SolutionInfo si2 = new SolutionInfo() {
|
---|
50 | IterationNumber = 2,
|
---|
51 | Quality = 3.5f,
|
---|
52 | Solution = new Solution() {
|
---|
53 | }
|
---|
54 | };
|
---|
55 | SolutionInfo si3 = new SolutionInfo() {
|
---|
56 | IterationNumber = 3,
|
---|
57 | Quality = 3.5f,
|
---|
58 | Solution = new Solution() {
|
---|
59 | }
|
---|
60 | };
|
---|
61 | return new SolutionInfo[] { si1, si2, si3 };
|
---|
62 | }
|
---|
63 | }
|
---|
64 | }
|
---|