Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/18/16 10:41:50 (8 years ago)
Author:
thasling
Message:

Stable build before changing communication protocoll to net.tcp

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/thasling/DistributedGA/DistributedGA.Core.Host/Program.cs

    r13524 r13537  
    1 using DistributedGA.Core.Domain;
     1using System;
     2using System.Threading;
     3using DistributedGA.Core.Domain;
    24using DistributedGA.Core.Implementation;
    35using DistributedGA.Core.Interface;
    4 using System;
    5 using System.Collections.Generic;
    6 using System.Linq;
    7 using System.Text;
    8 using System.Threading;
    9 using System.Threading.Tasks;
    106
    11 namespace 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             }
     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));
     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      }
    5039
     40    }
     41
     42    private static SolutionInfo[] CreatePopulation() {
     43      SolutionInfo si1 = new SolutionInfo() {
     44        IterationNumber = 1,
     45        Quality = 3.5f,
     46        Solution = new Solution() {
    5147        }
    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 };
     48      };
     49      SolutionInfo si2 = new SolutionInfo() {
     50        IterationNumber = 2,
     51        Quality = 3.5f,
     52        Solution = new Solution() {
    8053        }
     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 };
    8162    }
     63  }
    8264}
Note: See TracChangeset for help on using the changeset viewer.