Index: /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/AlgorithmNode.cs
===================================================================
--- /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/AlgorithmNode.cs	(revision 11406)
+++ /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/AlgorithmNode.cs	(revision 11406)
@@ -0,0 +1,204 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+using System.Collections.Generic;
+using System.Drawing;
+using HeuristicLab.Common;
+using HeuristicLab.Core;
+using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
+
+namespace HeuristicLab.Optimization.Networks {
+  [Item("AlgorithmNode", "A node of an optimization network which contains a HeuristicLab algorithm.")]
+  [StorableClass]
+  public class AlgorithmNode : Node {
+    [Storable]
+    private IAlgorithm algorithm;
+    public IAlgorithm Algorithm {
+      get { return algorithm; }
+      set {
+        if (value != algorithm) {
+          DeregisterAlgorithmEvents();
+          algorithm = value;
+          RegisterAlgorithmEvents();
+          OnAlgorithmChanged();
+        }
+      }
+    }
+
+    [StorableConstructor]
+    protected AlgorithmNode(bool deserializing) : base(deserializing) { }
+    protected AlgorithmNode(AlgorithmNode original, Cloner cloner)
+      : base(original, cloner) {
+      algorithm = cloner.Clone(original.algorithm);
+      RegisterPortsEvents();
+      RegisterAlgorithmEvents();
+    }
+    public AlgorithmNode()
+      : base("Node") {
+      RegisterPortsEvents();
+    }
+    public AlgorithmNode(string name)
+      : base(name) {
+      RegisterPortsEvents();
+    }
+    public AlgorithmNode(string name, string description)
+      : base(name, description) {
+      RegisterPortsEvents();
+    }
+
+    [StorableHook(HookType.AfterDeserialization)]
+    private void AfterDeserialization() {
+      RegisterPortsEvents();
+    }
+
+    public override IDeepCloneable Clone(Cloner cloner) {
+      return new AlgorithmNode(this, cloner);
+    }
+
+    private void UpdateParameter(IInputPort port) {
+      if (algorithm != null) {
+        foreach (var param in algorithm.Parameters) {
+          IValueParameter p = param as IValueParameter;
+          if ((p != null) && (p.Name == port.Name)) {
+            p.Value = (IItem)port.Value;
+          }
+        }
+      }
+    }
+    private void UpdateOutputPort(IResult result) {
+      foreach (var port in Ports) {
+        IOutputPort p = port as IOutputPort;
+        if ((p != null) && (p.Name == result.Name)) {
+          p.Value = result.Value;
+        }
+      }
+    }
+
+    public event EventHandler AlgorithmChanged;
+    protected virtual void OnAlgorithmChanged() {
+      var handler = AlgorithmChanged;
+      if (handler != null) handler(this, EventArgs.Empty);
+    }
+
+    #region Ports Events
+    private void RegisterPortsEvents() {
+      Ports.ItemsAdded += Ports_ItemsAdded;
+      Ports.ItemsRemoved += Ports_ItemsRemoved;
+      Ports.ItemsReplaced += Ports_ItemsReplaced;
+      Ports.CollectionReset += Ports_CollectionReset;
+    }
+    void Ports_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) {
+      foreach (var p in e.Items)
+        RegisterPortEvents(p);
+    }
+    void Ports_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) {
+      foreach (var p in e.Items)
+        DeregisterPortEvents(p);
+    }
+    void Ports_ItemsReplaced(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) {
+      foreach (var p in e.OldItems)
+        DeregisterPortEvents(p);
+      foreach (var p in e.Items)
+        RegisterPortEvents(p);
+    }
+    void Ports_CollectionReset(object sender, Collections.CollectionItemsChangedEventArgs<IPort> e) {
+      foreach (var p in e.OldItems)
+        DeregisterPortEvents(p);
+      foreach (var p in e.Items)
+        RegisterPortEvents(p);
+    }
+    #endregion
+
+    #region Port Events
+    private void RegisterPortEvents(IPort port) {
+      IInputPort p = port as IInputPort;
+      if (p != null) {
+        p.ValueChanged += InputPort_ValueChanged;
+      }
+    }
+    private void DeregisterPortEvents(IPort port) {
+      IInputPort p = port as IInputPort;
+      if (p != null) {
+        p.ValueChanged -= InputPort_ValueChanged;
+      }
+    }
+    private void InputPort_ValueChanged(object sender, EventArgs e) {
+      UpdateParameter((IInputPort)sender);
+    }
+    #endregion
+
+    #region Algorithm Events
+    private void RegisterAlgorithmEvents() {
+      if (algorithm != null) {
+        algorithm.Results.ItemsAdded += Results_ItemsAdded;
+        algorithm.Results.ItemsRemoved += Results_ItemsRemoved;
+        algorithm.Results.ItemsReplaced += Results_ItemsReplaced;
+        algorithm.Results.CollectionReset += Results_CollectionReset;
+      }
+    }
+    private void DeregisterAlgorithmEvents() {
+      if (algorithm != null) {
+        algorithm.Results.ItemsAdded -= Results_ItemsAdded;
+        algorithm.Results.ItemsRemoved -= Results_ItemsRemoved;
+        algorithm.Results.ItemsReplaced -= Results_ItemsReplaced;
+        algorithm.Results.CollectionReset -= Results_CollectionReset;
+      }
+    }
+    private void Results_ItemsAdded(object sender, Collections.CollectionItemsChangedEventArgs<IResult> e) {
+      foreach (var r in e.Items)
+        RegisterResultEvents(r);
+    }
+    private void Results_ItemsRemoved(object sender, Collections.CollectionItemsChangedEventArgs<IResult> e) {
+      foreach (var r in e.Items)
+        DeregisterResultEvents(r);
+    }
+    private void Results_ItemsReplaced(object sender, Collections.CollectionItemsChangedEventArgs<IResult> e) {
+      foreach (var r in e.OldItems)
+        DeregisterResultEvents(r);
+      foreach (var r in e.Items)
+        RegisterResultEvents(r);
+    }
+    private void Results_CollectionReset(object sender, Collections.CollectionItemsChangedEventArgs<IResult> e) {
+      foreach (var r in e.OldItems)
+        DeregisterResultEvents(r);
+      foreach (var r in e.Items)
+        RegisterResultEvents(r);
+    }
+    #endregion
+
+    #region Result Events
+    private void RegisterResultEvents(IResult result) {
+      if (result != null) {
+        result.ValueChanged += Result_ValueChanged;
+      }
+    }
+    private void DeregisterResultEvents(IResult result) {
+      if (result != null) {
+        result.ValueChanged -= Result_ValueChanged;
+      }
+    }
+    private void Result_ValueChanged(object sender, EventArgs e) {
+      UpdateOutputPort((IResult)sender);
+    }
+    #endregion
+  }
+}
Index: /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/EventArgs.cs
===================================================================
--- /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/EventArgs.cs	(revision 11405)
+++ /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/EventArgs.cs	(revision 11406)
@@ -24,8 +24,13 @@
 
 namespace HeuristicLab.Optimization.Networks {
-  public class OutputInputPortEventArgs<T> : EventArgs where T : class, IItem {
-    public T Result { get; set; }
+  public class OutputInputPortEventArgs<TOut, TIn> : EventArgs
+    where TOut : class, IItem
+    where TIn : class, IItem {
+    public TOut Value { get; private set; }
+    public TIn Result { get; set; }
 
-    public OutputInputPortEventArgs() { }
+    public OutputInputPortEventArgs(TOut value) {
+      Value = value;
+    }
   }
 }
Index: /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/HeuristicLab.Optimization.Networks-3.3.csproj
===================================================================
--- /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/HeuristicLab.Optimization.Networks-3.3.csproj	(revision 11405)
+++ /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/HeuristicLab.Optimization.Networks-3.3.csproj	(revision 11406)
@@ -50,6 +50,8 @@
     <Compile Include="EventArgs.cs" />
     <Compile Include="IInputOutputPort.cs" />
+    <Compile Include="IAlgorithmNode.cs" />
     <Compile Include="InputOutputPort.cs" />
     <Compile Include="IOutputInputPort.cs" />
+    <Compile Include="AlgorithmNode.cs" />
     <Compile Include="OutputInputPort.cs" />
     <Compile Include="OutputPort.cs" />
@@ -90,4 +92,8 @@
       <Name>HeuristicLab.Core-3.3</Name>
     </ProjectReference>
+    <ProjectReference Include="..\..\HeuristicLab.Optimization\3.3\HeuristicLab.Optimization-3.3.csproj">
+      <Project>{14ab8d24-25bc-400c-a846-4627aa945192}</Project>
+      <Name>HeuristicLab.Optimization-3.3</Name>
+    </ProjectReference>
     <ProjectReference Include="..\..\HeuristicLab.Persistence\3.3\HeuristicLab.Persistence-3.3.csproj">
       <Project>{102bc7d3-0ef9-439c-8f6d-96ff0fdb8e1b}</Project>
Index: /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IAlgorithmNode.cs
===================================================================
--- /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IAlgorithmNode.cs	(revision 11406)
+++ /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IAlgorithmNode.cs	(revision 11406)
@@ -0,0 +1,29 @@
+#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
+ *
+ * This file is part of HeuristicLab.
+ *
+ * HeuristicLab is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * HeuristicLab is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
+ */
+#endregion
+
+using System;
+
+namespace HeuristicLab.Optimization.Networks {
+  public interface IAlgorithmNode : INode {
+    IAlgorithm Algorithm { get; set; }
+    event EventHandler AlgorithmChanged;
+  }
+}
Index: /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IInputOutputPort.cs
===================================================================
--- /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IInputOutputPort.cs	(revision 11405)
+++ /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IInputOutputPort.cs	(revision 11406)
@@ -21,4 +21,5 @@
 
 using HeuristicLab.Core;
+using System;
 
 namespace HeuristicLab.Optimization.Networks {
@@ -31,4 +32,6 @@
     where TOut : class, IItem {
     new IOutputInputPort<TIn, TOut> OutputInputPort { get; set; }
+
+    event EventHandler<OutputInputPortEventArgs<TIn, TOut>> ValueReceived;
   }
 }
Index: /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IOutputInputPort.cs
===================================================================
--- /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IOutputInputPort.cs	(revision 11405)
+++ /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/IOutputInputPort.cs	(revision 11406)
@@ -33,5 +33,5 @@
     TIn SendValue(TOut value);
 
-    event EventHandler<OutputInputPortEventArgs<TIn>> ValueSent;
+    event EventHandler<OutputInputPortEventArgs<TOut, TIn>> ValueSent;
   }
 }
Index: /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/InputOutputPort.cs
===================================================================
--- /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/InputOutputPort.cs	(revision 11405)
+++ /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/InputOutputPort.cs	(revision 11406)
@@ -73,4 +73,12 @@
     }
 
+    public event EventHandler<OutputInputPortEventArgs<TIn, TOut>> ValueReceived;
+    protected TOut OnValueReceived(TIn value) {
+      var args = new OutputInputPortEventArgs<TIn, TOut>(value);
+      var handler = ValueReceived;
+      if (handler != null) handler(this, args);
+      return args.Result;
+    }
+
     protected void RegisterOutputInputPortEvents() {
       outputInputPort.ValueSent += OutputInputPort_ValueSent;
@@ -79,9 +87,10 @@
       outputInputPort.ValueSent -= OutputInputPort_ValueSent;
     }
-    protected void OutputInputPort_ValueSent(object sender, OutputInputPortEventArgs<TOut> e) {
-      Value = OutputInputPort.Value;
-      //TODO: switch threads to decouple value propagation and resulting action
-      //TODO: clone value?
-      //TODO: add computed result to event args
+    protected void OutputInputPort_ValueSent(object sender, OutputInputPortEventArgs<TIn, TOut> e) {
+      var value = (TIn)e.Value.Clone();
+      Value = value;
+      e.Result = OnValueReceived(value);
+      //DISCUSS: clone value?
+      //DISCUSS: switch threads to decouple value propagation and resulting action -> should be done in Node?
     }
   }
Index: /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/InputPort.cs
===================================================================
--- /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/InputPort.cs	(revision 11405)
+++ /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/InputPort.cs	(revision 11406)
@@ -79,8 +79,7 @@
     }
     protected void OutputPort_ValueChanged(object sender, EventArgs e) {
-      Value = OutputPort.Value;
-      //TODO: switch threads to decouple value propagation and to make communication asynchronous
-      //TODO: clone value?
-      //TODO: clone value?
+      Value = (T)OutputPort.Value.Clone();
+      //DISCUSS: clone value?
+      //DISCUSS: switch threads to decouple value propagation and to make communication asynchronous -> should be done in Node?
     }
   }
Index: /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/OutputInputPort.cs
===================================================================
--- /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/OutputInputPort.cs	(revision 11405)
+++ /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/OutputInputPort.cs	(revision 11406)
@@ -45,5 +45,5 @@
     public TIn SendValue(TOut value) {
       Value = value;
-      return OnValueSent();
+      return OnValueSent(value);
     }
     public object SendValue(object value) {
@@ -57,7 +57,7 @@
     }
 
-    public event EventHandler<OutputInputPortEventArgs<TIn>> ValueSent;
-    protected virtual TIn OnValueSent() {
-      var args = new OutputInputPortEventArgs<TIn>();
+    public event EventHandler<OutputInputPortEventArgs<TOut, TIn>> ValueSent;
+    protected virtual TIn OnValueSent(TOut value) {
+      var args = new OutputInputPortEventArgs<TOut, TIn>(value);
       var handler = ValueSent;
       if (handler != null) handler(this, args);
Index: /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Plugin.cs.frame
===================================================================
--- /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Plugin.cs.frame	(revision 11405)
+++ /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Plugin.cs.frame	(revision 11406)
@@ -34,4 +34,5 @@
 //  [PluginDependency("HeuristicLab.Data", "3.3")]
 //  [PluginDependency("HeuristicLab.Parameters", "3.3")]
+  [PluginDependency("HeuristicLab.Optimization", "3.3")]
   [PluginDependency("HeuristicLab.Persistence", "3.3")]
   public class HeuristicLabOptimizationNetworksPlugin : PluginBase {
Index: /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Port.cs
===================================================================
--- /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Port.cs	(revision 11405)
+++ /branches/OptimizationNetworks/HeuristicLab.Optimization.Networks/3.3/Port.cs	(revision 11406)
@@ -39,10 +39,8 @@
       get { return value; }
       protected set {
-        if (value != this.value) {
-          DeregisterValueEvents();
-          this.value = value;
-          RegisterValueEvents();
-          OnValueChanged();
-        }
+        DeregisterValueEvents();
+        this.value = value;
+        RegisterValueEvents();
+        OnValueChanged();
       }
     }
@@ -73,5 +71,5 @@
     public event EventHandler ValueChanged;
     protected virtual void OnValueChanged() {
-      EventHandler handler = ValueChanged;
+      var handler = ValueChanged;
       if (handler != null) handler(this, EventArgs.Empty);
       OnToStringChanged();
