Index: /branches/thasling/DistributedGA/DistributedGA.Core/Implementation/PeerNetworkMessageHandler.cs
===================================================================
--- /branches/thasling/DistributedGA/DistributedGA.Core/Implementation/PeerNetworkMessageHandler.cs	(revision 13968)
+++ /branches/thasling/DistributedGA/DistributedGA.Core/Implementation/PeerNetworkMessageHandler.cs	(revision 13969)
@@ -28,4 +28,5 @@
     private IMessageService host = null;
 
+   public event EventHandler<Exception> ExceptionOccurend;    
 
     public void Init(string lanIpPrefix, string contactServerUrl, string problemInstance, int messageCacheCapacity, double communicationRate) {
@@ -120,4 +121,12 @@
     }
 
+    private void PropagateException(Exception ex) {
+      //if (CountdownCompleted != null)
+      //  CountdownCompleted(this, e);
+      if (ExceptionOccurend != null) {
+        ExceptionOccurend(this, ex);
+      }
+    }
+
     private string GetInternalIpAddress(string ipPrefix) {
       try {
@@ -146,4 +155,5 @@
 
     private void AddError(string source, Exception ex) {
+      PropagateException(ex);
       if (peerListManager != null) {
         try {
Index: /branches/thasling/DistributedGA/DistributedGA.Core/Interface/IMessageHandler.cs
===================================================================
--- /branches/thasling/DistributedGA/DistributedGA.Core/Interface/IMessageHandler.cs	(revision 13968)
+++ /branches/thasling/DistributedGA/DistributedGA.Core/Interface/IMessageHandler.cs	(revision 13969)
@@ -1,3 +1,4 @@
-﻿using System.Collections.Generic;
+﻿using System;
+using System.Collections.Generic;
 using DistributedGA.Core.Domain;
 
@@ -17,4 +18,6 @@
 
     void Dispose();
+
+    event EventHandler<Exception> ExceptionOccurend;
   }
 }
Index: /branches/thasling/DistributedGA/DistributedGA.Hive/P2PMigrationAnalyzer.cs
===================================================================
--- /branches/thasling/DistributedGA/DistributedGA.Hive/P2PMigrationAnalyzer.cs	(revision 13968)
+++ /branches/thasling/DistributedGA/DistributedGA.Hive/P2PMigrationAnalyzer.cs	(revision 13969)
@@ -41,7 +41,9 @@
   [Item("P2PMigrationAnalyzer", "Migrates individuals using a P2P network.")]
   [StorableClass]
-  public class P2PMigrationAnalyzer : SingleSuccessorOperator, IAnalyzer, ISingleObjectiveOperator, IExecutable {
+  public class P2PMigrationAnalyzer : SingleSuccessorOperator, IAnalyzer, ISingleObjectiveOperator {
     // state: messagehandler
     private IMessageHandler h;
+
+    public bool EnabledByDefault { get { return false; } }
 
     public ILookupParameter<BoolValue> MaximizationParameter {
@@ -134,4 +136,8 @@
       base.InitializeState();
       // init P2P
+      Init();
+    }
+
+    private void Init() {
       h = new PeerNetworkMessageHandler();
       var lanIpPrefix = ((StringValue)(Parameters["LanIpPrefix"].ActualValue)).Value;
@@ -141,7 +147,11 @@
       var messageCacheCapacity = ((IntValue)Parameters["MessageCacheCapacity"].ActualValue).Value;
       h.Init(lanIpPrefix, contactServerUri, problemInstance, (int)(100 * messageCacheCapacity), (int)(100 * communicationRate));
+      h.ExceptionOccurend += ExceptionThrown;
     }
 
     public override IOperation Apply() {
+      if (h == null) {
+        Init();
+      }
       if (MigrationIterationsParameter.ActualValue == null) {
         MigrationIterationsParameter.ActualValue = new IntValue(0);
@@ -155,14 +165,49 @@
         //define how many migrants to send
         var migrationRate = ((PercentValue)Parameters["MigrationRate"].ActualValue).Value;
-
-        //TODO: SELECT MIGRATION STRATEGY
-        // TODO: select individuals based on quality
         var popQualities = QualityParameter.ActualValue;
-
         var selectedMigStrat = MigrationStrategyParameter.Value.Value;
 
-        // select best as emigrant
-        IScope emigrants = scope.SubScopes[1];
-        emigrantsList.Add(emigrants);
+        var rand = Random;
+        int replIdx = 0;
+        IScope emigrants = null;
+
+        //determine how many emigrants to send
+        int max = Convert.ToInt32(scope.SubScopes.Count * migrationRate);
+        if (max == 0 && scope.SubScopes.Count > 0) {
+          max = 0;
+        }
+
+        for (int i = 0; i < max; i++) {
+          //select emigrant depending on strategy
+          switch (selectedMigStrat) {
+            case MigrationStrategy.TakeBestReplaceBad:
+              emigrants = scope.SubScopes[i];
+              emigrantsList.Add(emigrants);
+              break;
+
+            case MigrationStrategy.TakeBestReplaceRandom:
+              emigrants = scope.SubScopes[i];
+              emigrantsList.Add(emigrants);
+              break;
+
+            case MigrationStrategy.TakeRandomReplaceBad:
+              replIdx = rand.Next(scope.SubScopes.Count);
+              emigrants = scope.SubScopes[replIdx];
+              emigrantsList.Add(emigrants);
+              break;
+
+            case MigrationStrategy.TakeRandomReplaceRandom:
+              replIdx = rand.Next(scope.SubScopes.Count);
+              emigrants = scope.SubScopes[replIdx];
+              emigrantsList.Add(emigrants);
+              break;
+
+            default:
+              break;
+          }
+        }
+        //each subscope is one emigrand
+        //IScope emigrants = scope.SubScopes[1];
+        //emigrantsList.Add(emigrants);
 
         {
@@ -172,5 +217,5 @@
             using (var stream = new MemoryStream()) {
               var emigrantScope = emigrantsList[ei];
-              emigrantScope.ClearParentScopes();
+
               var msgScope = new Scope();
               var cloner = new Cloner();
@@ -178,4 +223,5 @@
                 msgScope.Variables.Add((IVariable)variable.Clone(cloner));
               }
+              msgScope.ClearParentScopes();
               HeuristicLab.Persistence.Default.Xml.XmlGenerator.Serialize(msgScope, stream);
               message[ei] = stream.GetBuffer();
@@ -193,11 +239,32 @@
               var immigrantScope = HeuristicLab.Persistence.Default.Xml.XmlParser.Deserialize<IScope>(stream);
 
-              // replace random individual in current population
-              var rand = Random;
-              var replIdx = rand.Next(scope.SubScopes.Count);
-
-              scope.SubScopes.RemoveAt(replIdx);
+              // replace individual in current population
+              switch (selectedMigStrat) {
+                case MigrationStrategy.TakeBestReplaceBad:
+                  scope.SubScopes.RemoveAt(0);
+                  break;
+
+                case MigrationStrategy.TakeRandomReplaceBad:
+                  scope.SubScopes.RemoveAt(0);
+                  break;
+
+                case MigrationStrategy.TakeBestReplaceRandom:
+                  //replace random
+                  replIdx = rand.Next(scope.SubScopes.Count);
+                  scope.SubScopes.RemoveAt(replIdx);
+                  break;
+
+                case MigrationStrategy.TakeRandomReplaceRandom:
+                  //replace random
+                  replIdx = rand.Next(scope.SubScopes.Count);
+                  scope.SubScopes.RemoveAt(replIdx);
+                  break;
+
+                default:
+                  break;
+              }
+
+              //insert individual sortet in population
               var qualities = QualityParameter.ActualValue;
-
               var qualityTranslatedName = QualityParameter.TranslatedName;
               var qImmigrant = ((DoubleValue)immigrantScope.Variables[qualityTranslatedName].Value).Value;
@@ -227,47 +294,9 @@
     }
 
-    public bool EnabledByDefault { get { return false; } }
-
-    #region IExecutable Members
-
-    public event EventHandler<EventArgs<Exception>> ExceptionOccurred;
-
-    public ExecutionState ExecutionState {
-      get { return ExecutionState.Prepared; }
-    }
-
-    public event EventHandler ExecutionStateChanged;
-
-    public TimeSpan ExecutionTime {
-      get { return new TimeSpan(); }
-    }
-
-    public event EventHandler ExecutionTimeChanged;
-
-    public void Pause() {
-      int i = 0;
-    }
-
-    public event EventHandler Paused;
-
-    public void Prepare() {
-      int i = 0;
-    }
-
-    public event EventHandler Prepared;
-
-    public void Start() {
-      int i = 0;
-    }
-
-    public event EventHandler Started;
-
-    public void Stop() {
-      int i = 0;
-    }
-
-    public event EventHandler Stopped;
-
-    #endregion
+    private void ExceptionThrown(object sender, Exception e) {
+      var log = LogParameter.Value;
+      log.LogMessage(e.Message);
+    }
+
   }
 }
