Free cookie consent management tool by TermsFeed Policy Generator

source: branches/thasling/DistributedGA/DistributedGA.Core.Host/Program.cs @ 13537

Last change on this file since 13537 was 13537, checked in by thasling, 8 years ago

Stable build before changing communication protocoll to net.tcp

File size: 2.1 KB
RevLine 
[13537]1using System;
2using System.Threading;
3using DistributedGA.Core.Domain;
[13524]4using DistributedGA.Core.Implementation;
5using DistributedGA.Core.Interface;
6
[13537]7namespace 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));
[13524]20        }
[13537]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      }
[13524]39
[13537]40    }
41
42    private static SolutionInfo[] CreatePopulation() {
43      SolutionInfo si1 = new SolutionInfo() {
44        IterationNumber = 1,
45        Quality = 3.5f,
46        Solution = new Solution() {
[13524]47        }
[13537]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 };
[13524]62    }
[13537]63  }
[13524]64}
Note: See TracBrowser for help on using the repository browser.