Index: /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeVectorInterpreter.cs
===================================================================
--- /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeVectorInterpreter.cs	(revision 18229)
+++ /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Interpreter/SymbolicDataAnalysisExpressionTreeVectorInterpreter.cs	(revision 18230)
@@ -728,50 +728,54 @@
           }
         case OpCodes.SubVector: {
-          DoubleVector SubVector(DoubleVector v , double start, double end) {
-            int size = v.Count;
-            int startIdx = Math.Abs((int)Math.Round(start * (size - 1)) % size);
-            int endIdx = Math.Abs((int)Math.Round(end * (size - 1)) % size);
-            if (startIdx < endIdx) {
-              return v.SubVector(startIdx, count: endIdx - startIdx);
-            } else { // wrap around
-              var resultVector = DoubleVector.Build.Dense(size: size - (startIdx - endIdx));
-              v.CopySubVectorTo(resultVector, startIdx, 0, size - startIdx); // copy [startIdx:size] to [0:size-startIdx]
-              v.CopySubVectorTo(resultVector, 0, size - startIdx, endIdx);   // copy [0:endIdx]      to [size-startIdx:size]
-              return resultVector;
+            DoubleVector SubVector(DoubleVector v , double start, double end) { 
+              int size = v.Count;
+              int ToIdx(double x) {
+                int idx = (int)Math.Round(x * (size - 1));
+                return (idx % size + size) % size; // positive mod
+              }
+              int startIdx = ToIdx(start);
+              int endIdx = ToIdx(end);
+              if (startIdx <= endIdx) {
+                return v.SubVector(startIdx, count: endIdx - startIdx + 1); // incl end
+              } else { // wrap around
+                var resultVector = DoubleVector.Build.Dense(size: size - (startIdx - endIdx) + 1);
+                v.CopySubVectorTo(resultVector, sourceIndex: startIdx, targetIndex: 0,               count: size - startIdx); // copy [startIdx:size] to [0:size-startIdx]
+                v.CopySubVectorTo(resultVector, sourceIndex: 0,        targetIndex: size - startIdx, count: endIdx);          // copy [0:endIdx]      to [size-startIdx:size]
+                return resultVector;
+              }
             }
-          }
-          var cur = Evaluate(dataset, ref row, state, traceDict);
-          TraceEvaluation(currentInstr, cur);
-          return FunctionApply(cur,
-            s => s,
-            v => {
-              var node = (IWindowedSymbolTreeNode)currentInstr.dynamicNode;
-              return SubVector(v, node.Offset, node.Length);
-            });
+            var cur = Evaluate(dataset, ref row, state, traceDict);
+            TraceEvaluation(currentInstr, cur);
+            return FunctionApply(cur,
+              s => s,
+              v => {
+                var node = (IWindowedSymbolTreeNode)currentInstr.dynamicNode;
+                return SubVector(v, node.Offset, node.Length);
+              });
           }
         case OpCodes.SubVectorSubtree: {
-          DoubleVector SubVector(DoubleVector v, double start, double end) {
-            int Mod(int x, int m) => (x % m + m) % m;
-            int startIdx = Mod((int)Math.Round(start * v.Count), v.Count);
-            int endIdx = Mod((int)Math.Round(end * v.Count), v.Count);
-            int size = v.Count;
-            if (startIdx < endIdx) {
-              return v.SubVector(startIdx, count: endIdx - startIdx);
-            } else { // wrap around
-              var resultVector = DoubleVector.Build.Dense(size: size - (startIdx - endIdx));
-              v.CopySubVectorTo(resultVector, startIdx, 0, size - startIdx); // copy [startIdx:size] to [0:size-startIdx]
-              v.CopySubVectorTo(resultVector, 0, size - startIdx, endIdx);   // copy [0:endIdx]      to [size-startIdx:size]
-              return resultVector;
+            DoubleVector SubVector(DoubleVector v, double start, double end) {
+              int Mod(int x, int m) => (x % m + m) % m;
+              int startIdx = Mod((int)Math.Round(start * v.Count), v.Count);
+              int endIdx = Mod((int)Math.Round(end * v.Count), v.Count);
+              int size = v.Count;
+              if (startIdx < endIdx) {
+                return v.SubVector(startIdx, count: endIdx - startIdx);
+              } else { // wrap around
+                var resultVector = DoubleVector.Build.Dense(size: size - (startIdx - endIdx));
+                v.CopySubVectorTo(resultVector, startIdx, 0, size - startIdx); // copy [startIdx:size] to [0:size-startIdx]
+                v.CopySubVectorTo(resultVector, 0, size - startIdx, endIdx);   // copy [0:endIdx]      to [size-startIdx:size]
+                return resultVector;
+              }
             }
-          }
-          var cur = Evaluate(dataset, ref row, state, traceDict);
-          var offset = Evaluate(dataset, ref row, state, traceDict);
-          var length = Evaluate(dataset, ref row, state, traceDict);
-          TraceEvaluation(currentInstr, cur);
-          return FunctionApply(cur,
-            s => s,
-            v => SubVector(v, offset.Scalar, length.Scalar)
-          );
-        }
+            var cur = Evaluate(dataset, ref row, state, traceDict);
+            var offset = Evaluate(dataset, ref row, state, traceDict);
+            var length = Evaluate(dataset, ref row, state, traceDict);
+            TraceEvaluation(currentInstr, cur);
+            return FunctionApply(cur,
+              s => s,
+              v => SubVector(v, offset.Scalar, length.Scalar)
+            );
+          }
         case OpCodes.Variable: {
             if (row < 0 || row >= dataset.Rows) return EvaluationResult.NaN;
Index: /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Mutators/NestedOptimizerSubVectorImprovementManipulator.cs
===================================================================
--- /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Mutators/NestedOptimizerSubVectorImprovementManipulator.cs	(revision 18229)
+++ /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/Mutators/NestedOptimizerSubVectorImprovementManipulator.cs	(revision 18230)
@@ -94,6 +94,6 @@
 
     #region Parameter Properties
-    public IConstrainedValueParameter<IAlgorithm> NestedOptimizerParameter {
-      get { return (IConstrainedValueParameter<IAlgorithm>)Parameters["NestedOptimizer"]; }
+    public OptionalConstrainedValueParameter<IAlgorithm> NestedOptimizerParameter {
+      get { return (OptionalConstrainedValueParameter<IAlgorithm>)Parameters["NestedOptimizer"]; }
     }
 
@@ -119,6 +119,6 @@
       var rs = new RandomSearchAlgorithm() {
         Problem = problem,
-        BatchSize = 10,
-        MaximumEvaluatedSolutions = 100
+        BatchSize = 100,
+        MaximumEvaluatedSolutions = 1000
       };
 
@@ -126,5 +126,5 @@
         Problem = problem,
         PlusSelection = new BoolValue(true),
-        PopulationSize = new IntValue(1),
+        PopulationSize = new IntValue(10),
         Children = new IntValue(10),
         MaximumGenerations = new IntValue(100)
@@ -158,5 +158,5 @@
       var optimizers = new ItemSet<IAlgorithm>() { rs, es, ga, osga };
 
-      Parameters.Add(new ConstrainedValueParameter<IAlgorithm>("NestedOptimizer", optimizers, rs));
+      Parameters.Add(new OptionalConstrainedValueParameter<IAlgorithm>("NestedOptimizer", optimizers, rs));
       Parameters.Add(new FixedValueParameter<PercentValue>("PercentOptimizedSubVectorNodes", new PercentValue(1.0)));
     }
@@ -170,6 +170,20 @@
     [StorableConstructor]
     private NestedOptimizerSubVectorImprovementManipulator(StorableConstructorFlag _) : base(_) { }
+    [StorableHook(HookType.AfterDeserialization)]
+    private void AfterDeserialization() {
+      if (Parameters.TryGetValue("NestedOptimizer", out var param)) {
+        if (param is ConstrainedValueParameter<IAlgorithm> constrainedParam) {
+          Parameters.Remove("NestedOptimizer");
+          Parameters.Add(new OptionalConstrainedValueParameter<IAlgorithm>("NestedOptimizer", 
+            new ItemSet<IAlgorithm>(constrainedParam.ValidValues), constrainedParam.Value)
+          );
+        }
+      }
+    }
 
     public override void Manipulate(IRandom random, ISymbolicExpressionTree symbolicExpressionTree) {
+      if (NestedOptimizer == null)
+        return;
+      
       int vectorLengths = GetVectorLengths(ProblemDataParameter.ActualValue);
       
@@ -183,7 +197,11 @@
       algorithm.Start(CancellationToken);
 
-      if (algorithm.ExecutionState != ExecutionState.Stopped)
-        throw new InvalidOperationException("Nested Algorithm did not finish.");
-
+      //if (algorithm.ExecutionState != ExecutionState.Stopped)
+      //  return;
+
+      if (!algorithm.Results.ContainsKey(BestSolutionParameterName))
+        return; 
+      
+      // use the latest best result
       var solution = (IntegerVector)algorithm.Results[BestSolutionParameterName].Value;
       UpdateFromVector(symbolicExpressionTree, selectedSubVectorNodes, solution, vectorLengths);
@@ -204,5 +222,5 @@
     }
 
-    private static int GetVectorLengths(T problemData) {  // ToDo evaluate a tree to get vector length per node
+    private static int GetVectorLengths(T problemData) { // ToDo evaluate a tree to get vector length per node
       var vectorLengths = problemData.Dataset.DoubleVectorVariables
         .Select(v => problemData.Dataset.GetDoubleVectorValue(v, row: 0).Count)
@@ -217,6 +235,6 @@
       foreach (var nodeIdx in selectedNodes) {
         var node = nodes[nodeIdx];
-        node.Offset = (double)solution[i++] / (vectorLength - 1);
-        node.Length = (double)solution[i++] / (vectorLength - 1);
+        node.Offset = (double)solution[i++] / (vectorLength - 1); // round in case of float
+        node.Length = (double)solution[i++] / (vectorLength - 1); // round in case of float
       }
     }
@@ -231,5 +249,4 @@
       return tree.Root.GetSubtree(0).GetSubtree(0);
     }
-
   }
 }
Index: /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SegmentOptimization/SegmentOptimizationProblem.cs
===================================================================
--- /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SegmentOptimization/SegmentOptimizationProblem.cs	(revision 18229)
+++ /branches/3040_VectorBasedGP/HeuristicLab.Problems.DataAnalysis.Symbolic/3.4/SegmentOptimization/SegmentOptimizationProblem.cs	(revision 18230)
@@ -173,19 +173,19 @@
     }
 
-    private static double BoundedAggregation(DoubleArray data, IntRange bounds, Aggregation aggregation) {
-      var matrix = new DoubleMatrix(1, data.Length);
-      for (int i = 0; i < data.Length; i++) matrix[0, i] = data[i];
-      return BoundedAggregation(matrix, bounds, aggregation);
-    }
+    //private static double BoundedAggregation(DoubleArray data, IntRange bounds, Aggregation aggregation) {
+    //  var matrix = new DoubleMatrix(1, data.Length);
+    //  for (int i = 0; i < data.Length; i++) matrix[0, i] = data[i];
+    //  return BoundedAggregation(matrix, bounds, aggregation);
+    //}
 
     private static double BoundedAggregation(DoubleMatrix data, IntRange bounds, Aggregation aggregation) {
-      if (bounds.Size == 0) {
-        return 0;
-      }
+      //if (bounds.Size == 0) {
+      //  return 0;
+      //}
 
       var resultValues = new double[data.Rows];
       for (int row = 0; row < data.Rows; row++) {
         var vector = data.GetRow(row);
-        var segment = vector.Skip(bounds.Start).Take(bounds.Size);
+        var segment = vector.Skip(bounds.Start).Take(bounds.Size + 1); // exclusive end
         switch (aggregation) {
           case Aggregation.Sum:
