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