Free cookie consent management tool by TermsFeed Policy Generator

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

Last change on this file since 13792 was 13557, checked in by thasling, 9 years ago

Implemented P2PTask-class
Changed communication protocoll http --> net.tcp
Logger is now Parameter of P2PTask

File size: 2.3 KB
Line 
1using System;
2using System.Configuration;
3using System.Threading;
4using DistributedGA.Core.Domain;
5using DistributedGA.Core.Implementation;
6using DistributedGA.Core.Interface;
7
8namespace DistributedGA.Core.Host {
9  class Program {
10    static void Main(string[] args) {
11      try {
12        Console.WriteLine("Starting peer...");
13        string ipPrefix = ConfigurationManager.AppSettings["LanIpPrefix"];
14        string serverUrl = ConfigurationManager.AppSettings["ContactServerURL"];
15
16
17        IMessageHandler h = new PeerNetworkMessageHandler();
18        h.Init(ipPrefix, serverUrl);
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));
25        }
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...");
32          h.PublishDataToNetwork(pop1);
33          Console.WriteLine("Population published.");
34          Console.WriteLine("Recieved populations:");
35          foreach (var item in h.GetDataFromNetwork()) {
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      }
44
45    }
46
47    private static SolutionInfo[] CreatePopulation() {
48      SolutionInfo si1 = new SolutionInfo() {
49        IterationNumber = 1,
50        Quality = 3.5f,
51        Solution = new Solution() {
52        }
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 };
67    }
68  }
69}
Note: See TracBrowser for help on using the repository browser.