Free cookie consent management tool by TermsFeed Policy Generator

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

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

Upload des Projekts letztendlich, trotz buggendes Clients...

File size: 2.8 KB
Line 
1using DistributedGA.Core.Domain;
2using DistributedGA.Core.Implementation;
3using DistributedGA.Core.Interface;
4using System;
5using System.Collections.Generic;
6using System.Linq;
7using System.Text;
8using System.Threading;
9using System.Threading.Tasks;
10
11namespace DistributedGA.Core.Host
12{
13    class Program
14    {
15        static void Main(string[] args)
16        {
17            try
18            {
19                Console.WriteLine("Starting peer...");
20                IMessageHandler h = new PeerNetworkMessageHandler();
21                h.Init();
22                PeerInfo pi = h.GetPeerInfo();
23                Console.WriteLine(string.Format("Peer is hostet at IP: {0} and port: {1}", pi.IpAddress, pi.Port));
24                Thread.Sleep(1000 * 20);
25                Console.WriteLine("Current peers within network:");
26                foreach (var item in h.GetCurrentNetwork())
27                {
28                    Console.WriteLine(string.Format("Peer at {0}:{1}",item.IpAddress, item.Port));
29                }
30                while (true)
31                {
32                    Thread.Sleep(1000 * 10);
33                    var pop1 = CreatePopulation();
34                    Console.WriteLine("Publish population into network...");
35                    h.PublishMigrationInfo(pop1);
36                    Console.WriteLine("Population published.");
37                    Console.WriteLine("Recieved populations:");
38                    foreach (var item in h.GetMigrationInfo())
39                    {
40                        Console.WriteLine(string.Format("Population with Quality: {0:2} in Iteration {1}", item.Quality, item.IterationNumber));
41                    }
42                }
43            }
44            catch (Exception ex)
45            {
46                Console.WriteLine(ex.Message);
47                Console.WriteLine("press any key to continue...");
48                Console.ReadLine();
49            }
50
51        }
52
53        private static SolutionInfo[] CreatePopulation()
54        {
55            SolutionInfo si1 = new SolutionInfo()
56            {
57                IterationNumber = 1,
58                Quality = 3.5f,
59                Solution = new Solution()
60                {
61                }
62            };
63            SolutionInfo si2 = new SolutionInfo()
64            {
65                IterationNumber = 2,
66                Quality = 3.5f,
67                Solution = new Solution()
68                {
69                }
70            };
71            SolutionInfo si3 = new SolutionInfo()
72            {
73                IterationNumber = 3,
74                Quality = 3.5f,
75                Solution = new Solution()
76                {
77                }
78            };
79            return new SolutionInfo[] { si1, si2, si3 };
80        }
81    }
82}
Note: See TracBrowser for help on using the repository browser.