Index: branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpOrchestratorNode2.cs
===================================================================
--- branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpOrchestratorNode2.cs	(revision 14604)
+++ branches/OptimizationNetworks/HeuristicLab.Networks.IntegratedOptimization.TravelingThief/3.3/TtpOrchestratorNode2.cs	(revision 14610)
@@ -21,7 +21,5 @@
 
 using System;
-using System.Collections.Generic;
 using System.Linq;
-using System.Threading;
 using HeuristicLab.Common;
 using HeuristicLab.Core;
@@ -29,9 +27,6 @@
 using HeuristicLab.Data;
 using HeuristicLab.Encodings.BinaryVectorEncoding;
-using HeuristicLab.Encodings.PermutationEncoding;
 using HeuristicLab.Encodings.RealVectorEncoding;
-using HeuristicLab.Operators;
 using HeuristicLab.Optimization;
-using HeuristicLab.Parameters;
 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
 using HeuristicLab.Problems.Knapsack;
@@ -41,125 +36,10 @@
   [Item("TtpOrchestratorNode2", "Orchestrator for TTP optimization network version 2.")]
   [StorableClass]
-  public sealed class TtpOrchestratorNode2 : OrchestratorNode {
-    #region Constants
-    private const string InstanceParameterName = "Instance";
-    private const string TspParameterName = "TSP";
-    private const string KspParameterName = "KSP";
-    private const string AvailabilityParameterName = "Availability";
-    private const string MinSpeedParameterName = "MinSpeed";
-    private const string MaxSpeedParameterName = "MaxSpeed";
-    private const string RentingRatioParameterName = "RentingRatio";
-    private const string MetaSolverName = "MetaSolver";
-    private const string TspSolverName = "TspSolver";
-    private const string KspSolverName = "KspSolver";
-    #endregion
-
-    private CancellationTokenSource cts;
-    private ResultCollection tspResults, kspResults;
-
-    [Storable]
-    double[,] tspCoordinates;
-    [Storable]
-    TtpUtils.DistanceType distanceType;
-    [Storable]
-    int kspCapacity;
-    [Storable]
-    int[] kspItemWeights, kspItemValues, ttpAvailability;
-    [Storable]
-    double ttpMinSpeed, ttpMaxSpeed, ttpRentingRatio;
-
-    #region Parameters
-    public IFixedValueParameter<TextFileValue> InstanceParameter {
-      get { return (IFixedValueParameter<TextFileValue>)Parameters[InstanceParameterName]; }
-    }
-
-    public IValueParameter<TravelingSalesmanProblem> TspParameter {
-      get { return (IValueParameter<TravelingSalesmanProblem>)Parameters[TspParameterName]; }
-    }
-
-    public IValueParameter<BinaryKnapsackProblem> KspParameter {
-      get { return (IValueParameter<BinaryKnapsackProblem>)Parameters[KspParameterName]; }
-    }
-
-    public IValueParameter<IntArray> AvailabilityParameter {
-      get { return (IValueParameter<IntArray>)Parameters[AvailabilityParameterName]; }
-    }
-
-    public IValueParameter<DoubleValue> MinSpeedParameter {
-      get { return (IValueParameter<DoubleValue>)Parameters[MinSpeedParameterName]; }
-    }
-
-    public IValueParameter<DoubleValue> MaxSpeedParameter {
-      get { return (IValueParameter<DoubleValue>)Parameters[MaxSpeedParameterName]; }
-    }
-
-    public IValueParameter<DoubleValue> RentingRatioParameter {
-      get { return (IValueParameter<DoubleValue>)Parameters[RentingRatioParameterName]; }
-    }
-    #endregion
-
-    #region Ports
-    public IMessagePort MetaSolverOrchestrationPort {
-      get { return (IMessagePort)Ports[MetaSolverName + OrchestrationPortNameSuffix]; }
-    }
-
-    public IMessagePort MetaSolverEvaluationPort {
-      get { return (IMessagePort)Ports[MetaSolverName + EvaluationPortNameSuffix]; }
-    }
-
-    public IMessagePort TspSolverOrchestrationPort {
-      get { return (IMessagePort)Ports[TspSolverName + OrchestrationPortNameSuffix]; }
-    }
-
-    public IMessagePort TspSolverEvaluationPort {
-      get { return (IMessagePort)Ports[TspSolverName + EvaluationPortNameSuffix]; }
-    }
-
-    public IMessagePort KspSolverOrchestrationPort {
-      get { return (IMessagePort)Ports[KspSolverName + OrchestrationPortNameSuffix]; }
-    }
-
-    public IMessagePort KspSolverEvaluationPort {
-      get { return (IMessagePort)Ports[KspSolverName + EvaluationPortNameSuffix]; }
-    }
-    #endregion
-
+  public sealed class TtpOrchestratorNode2 : TtpOrchestratorNode {
     [StorableConstructor]
     private TtpOrchestratorNode2(bool deserializing) : base(deserializing) { }
-    private TtpOrchestratorNode2(TtpOrchestratorNode2 original, Cloner cloner) : base(original, cloner) {
-      tspCoordinates = (double[,])original.tspCoordinates.Clone();
-      kspCapacity = original.kspCapacity;
-      kspItemWeights = (int[])original.kspItemWeights.Clone();
-      kspItemValues = (int[])original.kspItemValues.Clone();
-      ttpAvailability = (int[])original.ttpAvailability.Clone();
-      ttpMinSpeed = original.ttpMinSpeed;
-      ttpMaxSpeed = original.ttpMaxSpeed;
-      ttpRentingRatio = original.ttpRentingRatio;
-
-      RegisterEvents();
-    }
+    private TtpOrchestratorNode2(TtpOrchestratorNode2 original, Cloner cloner) : base(original, cloner) { }
     public TtpOrchestratorNode2() : this("TtpOrchestratorNode2") { }
-    public TtpOrchestratorNode2(string name) : base(name) {
-      #region Configure Parameters
-      Parameters.Add(new FixedValueParameter<TextFileValue>(InstanceParameterName));
-      Parameters.Add(new ValueParameter<TravelingSalesmanProblem>(TspParameterName, new TravelingSalesmanProblem()));
-      Parameters.Add(new ValueParameter<BinaryKnapsackProblem>(KspParameterName, new BinaryKnapsackProblem()));
-      Parameters.Add(new ValueParameter<IntArray>(AvailabilityParameterName));
-      Parameters.Add(new ValueParameter<DoubleValue>(MinSpeedParameterName, new DoubleValue(0.1)));
-      Parameters.Add(new ValueParameter<DoubleValue>(MaxSpeedParameterName, new DoubleValue(1.0)));
-      Parameters.Add(new ValueParameter<DoubleValue>(RentingRatioParameterName, new DoubleValue(0.5)));
-      #endregion
-
-      #region Configure Ports
-      AddOrchestrationPort<VariegationProblem>(MetaSolverName);
-      AddEvaluationPort<RealVector>(MetaSolverName, "RealVector", "Quality");
-      AddOrchestrationPort<TravelingSalesmanProblem>(TspSolverName);
-      AddEvaluationPort<Permutation>(TspSolverName, "TSPTour", "TSPTourLength");
-      AddOrchestrationPort<LootProfitProblem>(KspSolverName);
-      AddEvaluationPort<BinaryVector>(KspSolverName, "KnapsackSolution", "Quality");
-
-      RegisterEvents();
-      #endregion
-    }
+    public TtpOrchestratorNode2(string name) : base(name) { }
 
     public override IDeepCloneable Clone(Cloner cloner) {
@@ -167,109 +47,6 @@
     }
 
-    [StorableHook(HookType.AfterDeserialization)]
-    private void AfterDeserialization() {
-      RegisterEvents();
-    }
-
-    private void RegisterEvents() {
-      InstanceParameter.Value.ToStringChanged += InstanceParameter_Value_ToStringChanged;
-      MetaSolverOrchestrationPort.ConnectedPortChanged += MetaSolverOrchestrationPort_ConnectedPortChanged;
-      TspSolverOrchestrationPort.ConnectedPortChanged += TspSolverOrchestrationPort_ConnectedPortChanged;
-      KspSolverOrchestrationPort.ConnectedPortChanged += KspSolverOrchestrationPort_ConnectedPortChanged;
-    }
-
-    private void InstanceParameter_Value_ToStringChanged(object sender, EventArgs e) {
-      string filePath = InstanceParameter.Value.Value;
-      TtpUtils.Import(filePath, out tspCoordinates, out distanceType,
-                                out kspCapacity, out kspItemValues, out kspItemWeights,
-                                out ttpAvailability, out ttpMinSpeed, out ttpMaxSpeed, out ttpRentingRatio);
-
-      var tsp = TspParameter.Value;
-      tsp.Coordinates = new DoubleMatrix(tspCoordinates);
-
-      var ksp = KspParameter.Value;
-      ksp.KnapsackCapacity.Value = kspCapacity;
-      ksp.Encoding.Length = kspItemValues.Length;
-      ksp.Values = new IntArray(kspItemValues);
-      ksp.Weights = new IntArray(kspItemWeights);
-
-      AvailabilityParameter.Value = new IntArray(ttpAvailability);
-      MinSpeedParameter.Value.Value = ttpMinSpeed;
-      MaxSpeedParameter.Value.Value = ttpMaxSpeed;
-      RentingRatioParameter.Value.Value = ttpRentingRatio;
-    }
-
-    public override void Prepare() {
-      Results.Clear();
-
-      var metaMsg = MetaSolverOrchestrationPort.PrepareMessage();
-      metaMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Prepare | OrchestrationMessage.QualityAdaption);
-      var problem = new VariegationProblem();
-      problem.Encoding.Length = TspParameter.Value.Coordinates.Rows * 2;
-      problem.Encoding.Bounds = new DoubleMatrix(new[,] { { -1.0, 1.0 } });
-      metaMsg["Problem"] = problem;
-      MetaSolverOrchestrationPort.SendMessage(metaMsg);
-    }
-
-    public override void Start() {
-      cts = new CancellationTokenSource();
-
-      try {
-        var metaMsg = MetaSolverOrchestrationPort.PrepareMessage();
-        metaMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Start);
-        MetaSolverOrchestrationPort.SendMessage(metaMsg);
-      } catch (Exception e) { }
-    }
-
-    public override void Pause() {
-      cts.Cancel();
-
-      var metaMsg = MetaSolverOrchestrationPort.PrepareMessage();
-      metaMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Pause);
-      MetaSolverOrchestrationPort.SendMessage(metaMsg);
-
-      var tspMsg = TspSolverOrchestrationPort.PrepareMessage();
-      tspMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Stop);
-      TspSolverOrchestrationPort.SendMessage(tspMsg);
-
-      var kspMsg = KspSolverOrchestrationPort.PrepareMessage();
-      kspMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Stop);
-      KspSolverOrchestrationPort.SendMessage(kspMsg);
-    }
-
-    public override void Stop() {
-      cts.Cancel();
-
-      var metaMsg = MetaSolverOrchestrationPort.PrepareMessage();
-      metaMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Stop);
-      MetaSolverOrchestrationPort.SendMessage(metaMsg);
-
-      var tspMsg = TspSolverOrchestrationPort.PrepareMessage();
-      tspMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Stop);
-      TspSolverOrchestrationPort.SendMessage(tspMsg);
-
-      var kspMsg = KspSolverOrchestrationPort.PrepareMessage();
-      kspMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Stop);
-      KspSolverOrchestrationPort.SendMessage(kspMsg);
-    }
-
-    protected override void ProcessMessage(IMessage message, IMessagePort port, CancellationToken token) {
-      var messageActions = new Dictionary<IMessagePort, Action<IMessage>>();
-      messageActions.Add(MetaSolverOrchestrationPort, MetaSolverOrchestrationPortMessage);
-      messageActions.Add(MetaSolverEvaluationPort, MetaSolverEvaluationPortMessage);
-      messageActions.Add(TspSolverOrchestrationPort, TspSolverOrchestrationPortMessage);
-      messageActions.Add(TspSolverEvaluationPort, TspSolverEvaluationPortMessage);
-      messageActions.Add(KspSolverOrchestrationPort, KspSolverOrchestrationPortMessage);
-      messageActions.Add(KspSolverEvaluationPort, KspSolverEvaluationPortMessage);
-
-      messageActions[port](message);
-
-      base.ProcessMessage(message, port, token);
-    }
-
     #region MetaSolver Message Handling
-    private void MetaSolverOrchestrationPortMessage(IMessage message) { }
-
-    private void MetaSolverEvaluationPortMessage(IMessage message) {
+    protected override void MetaSolverEvaluationPortMessage(IMessage message) {
       var factors = (RealVector)message["RealVector"];
 
@@ -281,5 +58,5 @@
 
       var tspMsg = TspSolverOrchestrationPort.PrepareMessage();
-      tspMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Prepare | OrchestrationMessage.Start);
+      tspMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Prepare | OrchestrationMessage.ClearRuns | OrchestrationMessage.Start);
       tspMsg["Problem"] = tsp;
       TspSolverOrchestrationPort.SendMessage(tspMsg);
@@ -291,5 +68,5 @@
 
       var kspMsg = KspSolverOrchestrationPort.PrepareMessage();
-      kspMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Prepare | OrchestrationMessage.Start);
+      kspMsg["OrchestrationMessage"] = new EnumValue<OrchestrationMessage>(OrchestrationMessage.Prepare | OrchestrationMessage.ClearRuns | OrchestrationMessage.Start);
       var lpp = new LootProfitProblem {
         Tsp = (TravelingSalesmanProblem)TspParameter.Value.Clone(),
@@ -325,5 +102,5 @@
         Results.Add(new Result("Best Tour", tour));
         Results.Add(new Result("Best Loot", loot));
-      } else if (((DoubleValue)bestQuality.Value).Value < objectiveValue) {
+      } else if (objectiveValue > ((DoubleValue)bestQuality.Value).Value) {
         ((DoubleValue)bestQuality.Value).Value = objectiveValue;
         Results["Best Tour"].Value = tour;
@@ -333,76 +110,4 @@
     }
     #endregion
-
-    #region TspSolver Message Handling
-    private void TspSolverOrchestrationPortMessage(IMessage message) {
-      var results = (ResultCollection)message["Results"];
-      if (results.ContainsKey("Best TSP Solution")) {
-        tspResults = results;
-      }
-    }
-
-    private void TspSolverEvaluationPortMessage(IMessage message) { }
-    #endregion
-
-    #region KspSolver Message Handling
-    private void KspSolverOrchestrationPortMessage(IMessage message) {
-      var results = (ResultCollection)message["Results"];
-      if (results.ContainsKey("Best Solution")) {
-        kspResults = results;
-      }
-    }
-
-    private void KspSolverEvaluationPortMessage(IMessage message) { }
-    #endregion
-
-    #region Event Handlers
-    private void MetaSolverOrchestrationPort_ConnectedPortChanged(object sender, EventArgs e) {
-      if (MetaSolverOrchestrationPort.ConnectedPort == null) return;
-
-      var node = MetaSolverOrchestrationPort.ConnectedPort.Parent as OrchestratedAlgorithmNode;
-      if (node == null) return;
-
-      var hook = new HookOperator { Name = "Meta Eval Hook" };
-      hook.Parameters.Add(new LookupParameter<RealVector>("RealVector") { Hidden = true });
-      hook.Parameters.Add(new LookupParameter<DoubleValue>("Quality") { Hidden = true });
-      node.EvalHook = hook;
-
-      node.OrchestrationPort.CloneParametersFromPort(MetaSolverOrchestrationPort);
-      node.EvaluationPort.CloneParametersFromPort(MetaSolverEvaluationPort);
-      node.EvaluationPort.ConnectedPort = MetaSolverEvaluationPort;
-    }
-
-    private void TspSolverOrchestrationPort_ConnectedPortChanged(object sender, EventArgs e) {
-      if (TspSolverOrchestrationPort.ConnectedPort == null) return;
-
-      var node = TspSolverOrchestrationPort.ConnectedPort.Parent as OrchestratedAlgorithmNode;
-      if (node == null) return;
-
-      var hook = new HookOperator { Name = "TSP Eval Hook" };
-      hook.Parameters.Add(new LookupParameter<Permutation>("TSPTour") { Hidden = true });
-      hook.Parameters.Add(new LookupParameter<DoubleValue>("TSPTourLength") { Hidden = true });
-      node.EvalHook = hook;
-
-      node.OrchestrationPort.CloneParametersFromPort(TspSolverOrchestrationPort);
-      node.EvaluationPort.CloneParametersFromPort(TspSolverEvaluationPort);
-      node.EvaluationPort.ConnectedPort = TspSolverEvaluationPort;
-    }
-
-    private void KspSolverOrchestrationPort_ConnectedPortChanged(object sender, EventArgs e) {
-      if (KspSolverOrchestrationPort.ConnectedPort == null) return;
-
-      var node = KspSolverOrchestrationPort.ConnectedPort.Parent as OrchestratedAlgorithmNode;
-      if (node == null) return;
-
-      var hook = new HookOperator { Name = "KSP Eval Hook" };
-      hook.Parameters.Add(new LookupParameter<BinaryVector>("KnapsackSolution") { Hidden = true });
-      hook.Parameters.Add(new LookupParameter<DoubleValue>("Quality") { Hidden = true });
-      node.EvalHook = hook;
-
-      node.OrchestrationPort.CloneParametersFromPort(KspSolverOrchestrationPort);
-      node.EvaluationPort.CloneParametersFromPort(KspSolverEvaluationPort);
-      node.EvaluationPort.ConnectedPort = KspSolverEvaluationPort;
-    }
-    #endregion
   }
 }
