Index: trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/NetworkToFunctionTransformer.cs
===================================================================
--- trunk/sources/HeuristicLab.GP.StructureIdentification.Networks/3.2/NetworkToFunctionTransformer.cs	(revision 2673)
+++ 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 2673)
+++ 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;
+    }
   }
 }
Index: trunk/sources/HeuristicLab.GP.Tests/NetworkToFunctionTransformerTest.cs
===================================================================
--- trunk/sources/HeuristicLab.GP.Tests/NetworkToFunctionTransformerTest.cs	(revision 2673)
+++ trunk/sources/HeuristicLab.GP.Tests/NetworkToFunctionTransformerTest.cs	(revision 2674)
@@ -8,4 +8,5 @@
 using HeuristicLab.Random;
 using HeuristicLab.DataAnalysis;
+using HeuristicLab.Common;
 
 namespace HeuristicLab.GP.Test {
@@ -105,49 +106,49 @@
 
       {
-        IFunctionTree tree = importer.Import("(open-+ (open-param - 0) (open-param - 0) (open-param - 0))");
-
-        IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
-
-        IFunctionTree t0 = importer.Import("(+ (variable 1.0 b 0) (variable 1.0 c 0))");
-        IFunctionTree t1 = importer.Import("(- (variable 1.0 a 0) (variable 1.0 c 0))");
-        IFunctionTree t2 = importer.Import("(- (variable 1.0 a 0) (variable 1.0 b 0))");
-
-        CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
-        t0, t1, t2
-      });
-      }
-
-      {
-        IFunctionTree tree = importer.Import("(open-- (open-param - 0) (f1-+ (open-param - 0) 1.0) (f1-* (open-param - 0) 1.0))");
-
-        IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
-
-        IFunctionTree t0 = importer.Import("(- (+ (variable 1.0 b 0) 1.0) (* (variable 1.0 c 0) 1.0 ))");
-        IFunctionTree t1 = importer.Import("(- (+ (variable 1.0 a 0) (* (variable 1.0 c 0) 1.0)) 1.0 )");
-        IFunctionTree t2 = importer.Import("(/ (+ (variable 1.0 a 0) (+ (variable 1.0 b 0) 1.0)) 1.0 )");
-
-        CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
-        t0, t1, t2
-      });
-      }
-
-      {
-        IFunctionTree tree = importer.Import("(cycle (open-* (open-param - 0) (open-param - 0) (open-param - 0)))");
-
-        IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
-
-        IFunctionTree t0 = importer.Import("(* (variable 1.0 b 0) (variable 1.0 c 0))");
-        IFunctionTree t1 = importer.Import("(/ (variable 1.0 a 0) (variable 1.0 c 0))");
-        IFunctionTree t2 = importer.Import("(/ (variable 1.0 a 0) (variable 1.0 b 0))");
-
-
-        CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
-        t0, t1, t2
-      });
-      }
-
-
-      {
-        IFunctionTree tree = importer.Import("(open-- (open-log (open-param - 0)) (open-exp (open-param - 0)) (open-param - 0))");
+        IFunctionTree tree = importer.Import("(open-+ (open-param 1.0 - 0) (open-param 2.0 - 0) (open-param 4.0 - 0))");
+
+        IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
+
+        IFunctionTree t0 = importer.Import("(+ (variable 2.0 b 0) (variable 4.0 c 0))");
+        IFunctionTree t1 = importer.Import("(* (- (variable 1.0 a 0) (variable 4.0 c 0)) 0.5)");
+        IFunctionTree t2 = importer.Import("(* (- (variable 1.0 a 0) (variable 2.0 b 0)) 0.25)");
+
+        CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
+        t0, t1, t2
+      });
+      }
+
+      {
+        IFunctionTree tree = importer.Import("(open-- (open-param 1.0 - 0) (f1-+ (open-param 2.0 - 0) 1.0) (f1-* (open-param 4.0 - 0) 1.0))");
+
+        IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
+
+        IFunctionTree t0 = importer.Import("(- (+ (variable 2.0 b 0) 1.0) (* (variable 4.0 c 0) 1.0 ))");
+        IFunctionTree t1 = importer.Import("(* (- (+ (variable 1.0 a 0) (* (variable 4.0 c 0) 1.0)) 1.0 ) 0.5)");
+        IFunctionTree t2 = importer.Import("(* (/ (+ (variable 1.0 a 0) (+ (variable 2.0 b 0) 1.0)) 1.0 ) 0.25)");
+
+        CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
+        t0, t1, t2
+      });
+      }
+
+      {
+        IFunctionTree tree = importer.Import("(cycle (open-* (open-param 1.0 - 0) (open-param 2.0 - 0) (open-param 4.0 - 0)))");
+
+        IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
+
+        IFunctionTree t0 = importer.Import("(* (* (variable 4.0 b 0) (variable 1.0 c 0)) 0.5)");
+        IFunctionTree t1 = importer.Import("(* (/ (variable 2.0 a 0) (variable 1.0 c 0)) 0.25)");
+        IFunctionTree t2 = importer.Import("(/ (variable 2.0 a 0) (variable 4.0 b 0))");
+
+
+        CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
+        t0, t1, t2
+      });
+      }
+
+
+      {
+        IFunctionTree tree = importer.Import("(open-- (open-log (open-param 1.0 - 0)) (open-exp (open-param 1.0 - 0)) (open-param 1.0 - 0))");
 
         IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
@@ -165,5 +166,5 @@
       }
       {
-        IFunctionTree tree = importer.Import("(open-- (open-log (open-log (open-param - 0))) (open-exp (open-exp (open-param - 0))) (f1-* (open-param - 0) 2.0))");
+        IFunctionTree tree = importer.Import("(open-- (open-log (open-log (open-param 1.0 - 0))) (open-exp (open-exp (open-param 1.0 - 0))) (f1-* (open-param 1.0 - 0) 2.0))");
 
         IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
@@ -181,16 +182,16 @@
       }
       {
-        IFunctionTree tree = importer.Import(@"(open-- (flip (open-log (open-param - 0))) 
-                                                       (flip (f1-* (open-param - 0) 2.0)) 
-                                                       (flip (flip (f1-* (open-param - 0) 2.0))))");
-
-        IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
-
-        IFunctionTree t0 = importer.Import(@"(log (- (/ (variable 1.0 b 0) 2.0)
-                                                     (* (variable 1.0 c 0) 2.0)))");
-        IFunctionTree t1 = importer.Import(@"(* (+ (exp (variable 1.0 a 0))
-                                                   (* (variable 1.0 c 0) 2.0)) 2.0)");
-        IFunctionTree t2 = importer.Import(@"(/ (+ (exp (variable 1.0 a 0))
-                                                   (/ (variable 1.0 b 0) 2.0)) 2.0)");
+        IFunctionTree tree = importer.Import(@"(open-- (flip (open-log (open-param 1.0 - 0))) 
+                                                       (flip (f1-* (open-param 2.0 - 0) 2.0)) 
+                                                       (flip (flip (f1-* (open-param 4.0 - 0) 2.0))))");
+
+        IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
+
+        IFunctionTree t0 = importer.Import(@"(log (- (/ (variable 0.5 b 0) 2.0)
+                                                     (* (variable 4.0 c 0) 2.0)))");
+        IFunctionTree t1 = importer.Import(@"(* (* (+ (exp (variable 1.0 a 0))
+                                                      (* (variable 4.0 c 0) 2.0)) 2.0) 2)");
+        IFunctionTree t2 = importer.Import(@"(* (/ (+ (exp (variable 1.0 a 0))
+                                                      (/ (variable 0.5 b 0) 2.0)) 2.0) 0.25)");
 
         CompareTrees(actualTrees.ToList(), new List<IFunctionTree>() {
@@ -203,7 +204,7 @@
                                                    (flip (f1-- 
                                                      (flip (f1-/ 
-                                                       (open-param - 0) 4.0)) 3.0)) 2.0))
-                                                 (open-param - 0) 
-                                                 (open-param - 0)))");
+                                                       (open-param 1.0 - 0) 4.0)) 3.0)) 2.0))
+                                                 (open-param 1.0 - 0) 
+                                                 (open-param 1.0 - 0)))");
         // -3*4-2 x
         IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
@@ -235,5 +236,5 @@
       {
         // expression with one parameter
-        IFunctionTree tree = importer.Import(@"(f1-* (open-param - 0) (variable 1.0 d 0))");
+        IFunctionTree tree = importer.Import(@"(f1-* (open-param 1.0 - 0) (variable 1.0 d 0))");
 
         IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
@@ -250,5 +251,5 @@
       {
         // expression with one parameter
-        IFunctionTree tree = importer.Import(@"(open-log (open-param - 0))");
+        IFunctionTree tree = importer.Import(@"(open-log (open-param 1.0 - 0))");
 
         IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
@@ -265,5 +266,5 @@
       {
         // expression with flip and one parameter
-        IFunctionTree tree = importer.Import(@"(flip (open-log (open-param - 0)))");
+        IFunctionTree tree = importer.Import(@"(flip (open-log (open-param 1.0 - 0)))");
 
         IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
@@ -281,5 +282,5 @@
       {
         // expression with flip and one parameter
-        IFunctionTree tree = importer.Import(@"(open-param - 0)");
+        IFunctionTree tree = importer.Import(@"(open-param 1.0 - 0)");
 
         IEnumerable<IFunctionTree> actualTrees = NetworkToFunctionTransformer_Accessor.Transform(tree, new List<string>() { "a", "b", "c" });
@@ -297,5 +298,5 @@
 
     private void CompareTrees(List<IFunctionTree> actual, List<IFunctionTree> expected) {
-      var expectedEnumerator = expected.GetEnumerator();      
+      var expectedEnumerator = expected.GetEnumerator();
       foreach (var actualTree in actual) {
         if (!expectedEnumerator.MoveNext()) Assert.Fail();
@@ -312,5 +313,5 @@
             var actualVar = (VariableFunctionTree)a.Current;
             Assert.AreEqual(expectedVar.VariableName, actualVar.VariableName);
-            Assert.AreEqual(expectedVar.Weight, actualVar.Weight);
+            Assert.IsTrue(expectedVar.Weight.IsAlmost(actualVar.Weight));
             Assert.AreEqual(expectedVar.SampleOffset, actualVar.SampleOffset);
           } else if (e.Current.Function is Constant) {
Index: trunk/sources/HeuristicLab.GP.Tests/SymbolicExpressionImporter.cs
===================================================================
--- trunk/sources/HeuristicLab.GP.Tests/SymbolicExpressionImporter.cs	(revision 2673)
+++ trunk/sources/HeuristicLab.GP.Tests/SymbolicExpressionImporter.cs	(revision 2674)
@@ -102,5 +102,5 @@
         } else if (tokens.Peek().StringValue.StartsWith(DIFFSTART)) {
           tree = ParseDifferential(tokens);
-        } else if(tokens.Peek().StringValue.StartsWith(OPENPARAMSTART)) {
+        } else if (tokens.Peek().StringValue.StartsWith(OPENPARAMSTART)) {
           tree = ParseOpenParameter(tokens);
         } else {
@@ -123,5 +123,6 @@
       Token tok = tokens.Dequeue();
       Debug.Assert(tok.StringValue == "open-param");
-      HeuristicLab.GP.StructureIdentification.Networks.OpenParameterFunctionTree t = (HeuristicLab.GP.StructureIdentification.Networks.OpenParameterFunctionTree)openParam.GetTreeNode();      
+      HeuristicLab.GP.StructureIdentification.Networks.OpenParameterFunctionTree t = (HeuristicLab.GP.StructureIdentification.Networks.OpenParameterFunctionTree)openParam.GetTreeNode();
+      t.Weight = tokens.Dequeue().DoubleValue;
       t.VariableName = tokens.Dequeue().StringValue;
       t.SampleOffset = (int)tokens.Dequeue().DoubleValue;
