Index: trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/NetworkToFunctionTransformer.cs
===================================================================
--- trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/NetworkToFunctionTransformer.cs	(revision 2635)
+++ trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/NetworkToFunctionTransformer.cs	(revision 2674)
@@ -30,4 +30,5 @@
 using HeuristicLab.DataAnalysis;
 using System.Diagnostics;
+using HeuristicLab.Common;
 
 namespace HeuristicLab.GP.StructureIdentification.Networks {
@@ -93,6 +94,9 @@
       } else if (tree.Function is Flip) {
         var partiallyAppliedBranch = ApplyFlips(tree.SubTrees[0]);
-        if (partiallyAppliedBranch.Function is OpenParameter) return partiallyAppliedBranch;
-        else return InvertChain(partiallyAppliedBranch);
+        if (partiallyAppliedBranch.Function is OpenParameter) {
+          var openParFunTree = (OpenParameterFunctionTree)partiallyAppliedBranch;
+          openParFunTree.Weight = 1.0 / openParFunTree.Weight;
+          return partiallyAppliedBranch;
+        } else return InvertChain(partiallyAppliedBranch);
       } else {
         List<IFunctionTree> subTrees = new List<IFunctionTree>(tree.SubTrees);
@@ -116,5 +120,5 @@
       // get a list of function trees from bottom to top
       List<IFunctionTree> reversedChain = new List<IFunctionTree>(currentChain.Reverse<IFunctionTree>().Skip(1));
-      IFunctionTree openParam = currentChain.Last();
+      OpenParameterFunctionTree openParam = (OpenParameterFunctionTree)currentChain.Last();
 
       // build new tree by inverting every function in the reversed chain and keeping f0 branches untouched.
@@ -136,4 +140,6 @@
         }
       }
+      // invert factor of openParam
+      openParam.Weight = 1.0 / openParam.Weight;
       // append open param at the end
       invParent.InsertSubTree(0, openParam);
@@ -195,10 +201,10 @@
 
 
-    private static IFunctionTree AppendLeft(IFunctionTree tree, IFunctionTree node) {
-      IFunctionTree originalTree = tree;
-      while (!IsBottomLeft(tree)) tree = tree.SubTrees[0];
-      tree.InsertSubTree(0, node);
-      return originalTree;
-    }
+    //private static IFunctionTree AppendLeft(IFunctionTree tree, IFunctionTree node) {
+    //  IFunctionTree originalTree = tree;
+    //  while (!IsBottomLeft(tree)) tree = tree.SubTrees[0];
+    //  tree.InsertSubTree(0, node);
+    //  return originalTree;
+    //}
 
     private static bool IsBottomLeft(IFunctionTree tree) {
@@ -265,12 +271,29 @@
             combinator.AddSubTree(subTrees[i]);
         }
-        if (subTrees[targetIndex].Function is Variable) return combinator;
+        if (subTrees[targetIndex].Function is Variable) return MakeMultiplication(combinator, 1.0 / GetTargetVariableWeight(subTrees[targetIndex]));
         else {
           IFunctionTree bottomLeft;
           IFunctionTree targetChain = InvertF0Chain(subTrees[targetIndex], out bottomLeft);
           bottomLeft.InsertSubTree(0, combinator);
-          return targetChain;
-        }
-      }
+          return MakeMultiplication(targetChain, 1.0 / GetTargetVariableWeight(subTrees[targetIndex]));
+        }
+      }
+    }
+
+    private static IFunctionTree MakeMultiplication(IFunctionTree tree, double p) {
+      if (p.IsAlmost(1.0)) return tree;
+      var mul = (new Multiplication()).GetTreeNode();
+      var constP = (ConstantFunctionTree)(new Constant()).GetTreeNode();
+      constP.Value = p;
+      mul.AddSubTree(tree);
+      mul.AddSubTree(constP);
+      return mul;
+    }
+
+    private static double GetTargetVariableWeight(IFunctionTree tree) {
+      while (tree.SubTrees.Count > 0) {
+        tree = tree.SubTrees[0];
+      }
+      return ((VariableFunctionTree)tree).Weight;
     }
 
@@ -377,5 +400,5 @@
         varTreeNode.VariableName = targetVariables.Current;
         varTreeNode.SampleOffset = ((OpenParameterFunctionTree)tree).SampleOffset;
-        varTreeNode.Weight = 1.0;
+        varTreeNode.Weight = ((OpenParameterFunctionTree)tree).Weight;
         return varTreeNode;
         //} else if (matchingFunction is Power) {
Index: trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/Symbols/OpenParameterFunctionTree.cs
===================================================================
--- trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/Symbols/OpenParameterFunctionTree.cs	(revision 2635)
+++ trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/Symbols/OpenParameterFunctionTree.cs	(revision 2674)
@@ -30,7 +30,9 @@
     public string VariableName { get; set; }
     public int SampleOffset { get; set; }
+    public double Weight { get; set; }
 
     public OpenParameterFunctionTree(OpenParameter openParameter)
       : base(openParameter) {
+      this.Weight = 1.0;
     }
 
@@ -39,4 +41,5 @@
       VariableName = original.VariableName;
       SampleOffset = original.SampleOffset;
+      Weight = original.Weight;
     }
 
@@ -51,4 +54,5 @@
       scope.AddSubScope(myVariableScope);
       myVariableScope.AddVariable(CreateSampleOffsetVariable());
+      myVariableScope.AddVariable(CreateWeightVariable());
       return new AtomicOperation(Function.Manipulator, myVariableScope);
     }
@@ -58,4 +62,5 @@
       scope.AddSubScope(myVariableScope);
       myVariableScope.AddVariable(CreateSampleOffsetVariable());
+      myVariableScope.AddVariable(CreateWeightVariable());
       return new AtomicOperation(Function.Initializer, myVariableScope);
     }
@@ -72,8 +77,11 @@
     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<System.Guid, IStorable> persistedObjects) {
       XmlNode node = document.CreateElement(name);
+      XmlAttribute weightAttr = document.CreateAttribute("Weight");
+      weightAttr.Value = XmlConvert.ToString(Weight);
       XmlAttribute variableAttr = document.CreateAttribute("Variable");
       variableAttr.Value = VariableName;
       XmlAttribute sampleOffsetAttr = document.CreateAttribute("SampleOffset");
       sampleOffsetAttr.Value = XmlConvert.ToString(SampleOffset);
+      node.Attributes.Append(weightAttr);
       node.Attributes.Append(sampleOffsetAttr);
       node.Attributes.Append(variableAttr);
@@ -83,4 +91,5 @@
     public override void Populate(XmlNode node, IDictionary<System.Guid, IStorable> restoredObjects) {
       base.Populate(node, restoredObjects);
+      Weight = XmlConvert.ToDouble(node.Attributes["Weight"].Value);
       SampleOffset = XmlConvert.ToInt32(node.Attributes["SampleOffset"].Value);
       VariableName = node.Attributes["Variable"].Value;
@@ -103,4 +112,12 @@
       return variable;
     }
+
+    private IVariable CreateWeightVariable() {
+      DoubleData data = new DoubleData(Weight);
+      data.Changed += (sender, args) => Weight = data.Data;
+      var variable = new HeuristicLab.Core.Variable(Variable.WEIGHT, data);
+      variable.ValueChanged += (sender, args) => Weight = ((DoubleData)variable.Value).Data;
+      return variable;
+    }
   }
 }
