Index: branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/EfficientGlobalOptimizationAlgorithm.cs
===================================================================
--- branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/EfficientGlobalOptimizationAlgorithm.cs	(revision 14741)
+++ branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/EfficientGlobalOptimizationAlgorithm.cs	(revision 14768)
@@ -24,7 +24,5 @@
 using System.Linq;
 using System.Threading;
-using HeuristicLab.Algorithms.CMAEvolutionStrategy;
 using HeuristicLab.Algorithms.DataAnalysis;
-using HeuristicLab.Algorithms.EGO;
 using HeuristicLab.Analysis;
 using HeuristicLab.Common;
@@ -38,9 +36,9 @@
 using HeuristicLab.Random;
 
-namespace HeuristicLab.Problems.SurrogateProblem {
+namespace HeuristicLab.Algorithms.EGO {
   [StorableClass]
   [Creatable(CreatableAttribute.Categories.Algorithms, Priority = 95)]
   [Item("EfficientGlobalOptimizationAlgortihm", "Solves a problem by sequentially learning a model, solving a subproblem on the model and evaluating the best found solution for this subproblem.")]
-  public class EfficientGlobalOptimizationAlgorithm : BasicAlgorithm {
+  public class EfficientGlobalOptimizationAlgorithm : BasicAlgorithm, ISurrogateAlgorithm<RealVector> {
     #region Basic-Alg-Essentials
     public override bool SupportsPause => true;
@@ -64,4 +62,5 @@
     private const string SeedParameterName = "Seed";
     private const string SetSeedRandomlyParameterName = "SetSeedRandomly";
+    private const string MaximalDataSetSizeParameterName = "MaximalDataSetSize";
     #endregion
 
@@ -93,8 +92,10 @@
     public IValueParameter<IDataAnalysisAlgorithm<IRegressionProblem>> RegressionAlgorithmParameter => Parameters[RegressionAlgorithmParameterName] as IValueParameter<IDataAnalysisAlgorithm<IRegressionProblem>>;
     public IFixedValueParameter<IntValue> SeedParameter => Parameters[SeedParameterName] as IFixedValueParameter<IntValue>;
-    public FixedValueParameter<BoolValue> SetSeedRandomlyParameter => Parameters[SetSeedRandomlyParameterName] as FixedValueParameter<BoolValue>;
+    public IFixedValueParameter<BoolValue> SetSeedRandomlyParameter => Parameters[SetSeedRandomlyParameterName] as IFixedValueParameter<BoolValue>;
+    public IFixedValueParameter<IntValue> MaximalDataSetSizeParameter => Parameters[MaximalDataSetSizeParameterName] as IFixedValueParameter<IntValue>;
     #endregion
 
     #region Properties
+
     public int GenerationSize
     {
@@ -137,4 +138,19 @@
       get { return SetSeedRandomlyParameter.Value.Value; }
     }
+    public int MaximalDatasetSize
+    {
+      get { return MaximalDataSetSizeParameter.Value.Value; }
+    }
+
+    private IEnumerable<Tuple<RealVector, double>> DataSamples
+    {
+      get
+      {
+        return Samples.Count > MaximalDatasetSize && MaximalDatasetSize > 0
+          ? Samples.Skip(Samples.Count - MaximalDatasetSize)
+          : Samples;
+      }
+    }
+
     #endregion
 
@@ -144,4 +160,6 @@
     [Storable]
     private List<Tuple<RealVector, double>> Samples;
+    [Storable]
+    private List<Tuple<RealVector, double>> InitialSamples;
     #endregion
 
@@ -201,9 +219,10 @@
       Random = cloner.Clone(Random);
       if (original.Samples != null) Samples = original.Samples.Select(x => new Tuple<RealVector, double>(cloner.Clone(x.Item1), x.Item2)).ToList();
+      if (original.InitialSamples != null) Samples = original.InitialSamples.Select(x => new Tuple<RealVector, double>(cloner.Clone(x.Item1), x.Item2)).ToList();
       RegisterEventhandlers();
     }
     public override IDeepCloneable Clone(Cloner cloner) { return new EfficientGlobalOptimizationAlgorithm(this, cloner); }
     public EfficientGlobalOptimizationAlgorithm() {
-      var cmaes = new CMAEvolutionStrategy {
+      var cmaes = new CMAEvolutionStrategy.CMAEvolutionStrategy {
         MaximumGenerations = 300,
         PopulationSize = 50
@@ -226,4 +245,6 @@
       InfillCriterionParameter.ValidValues.Add(new ExpectedQuality());
       InfillCriterionParameter.ValidValues.Add(new ConfidenceBound());
+      Parameters.Add(new FixedValueParameter<IntValue>(MaximalDataSetSizeParameterName, "The maximum number of sample points used to generate the model. Set 0 or less to use always all samples ", new IntValue(-1)));
+
       SetInfillProblem();
       RegisterEventhandlers();
@@ -240,9 +261,9 @@
       if (SetSeedRandomly) SeedParameter.Value.Value = new System.Random().Next();
       Random.Reset(Seed);
-      Samples = new List<Tuple<RealVector, double>>();
+      Samples = InitialSamples == null ? new List<Tuple<RealVector, double>>() : InitialSamples.ToList();
 
       //results
       Results.Add(new Result(IterationsResultName, new IntValue(0)));
-      Results.Add(new Result(EvaluatedSoultionsResultName, new IntValue(0)));
+      Results.Add(new Result(EvaluatedSoultionsResultName, new IntValue(Samples.Count)));
       Results.Add(new Result(BestSolutionResultName, new RealVector(1)));
       Results.Add(new Result(BestQualityResultName, new DoubleValue(Problem.Maximization ? double.MinValue : double.MaxValue)));
@@ -254,11 +275,11 @@
       Results.Add(new Result(QualitiesChartResultName, table));
 
-      ResultsQualities.Rows.Add(new DataRow("DEBUG:ModelBuildingIterations"));
-
       //initial samples
-      var points = EgoUtilities.GetUniformRandomDesign(InitialEvaluations, enc.Length, enc.Bounds, Random);
-      foreach (var t in points) {
-        Samples.Add(Evaluate(t));
-        cancellationToken.ThrowIfCancellationRequested();
+      if (Samples.Count < InitialEvaluations) {
+        var points = EgoUtilities.GetUniformRandomDesign(InitialEvaluations - Samples.Count, enc.Length, enc.Bounds, Random);
+        foreach (var t in points) {
+          Samples.Add(Evaluate(t));
+          cancellationToken.ThrowIfCancellationRequested();
+        }
       }
 
@@ -269,5 +290,5 @@
       for (ResultsIterations = 0; ResultsIterations < MaximumIterations; ResultsIterations++) {
         try {
-          ResultsModel = BuildModel();
+          ResultsModel = BuildModel(cancellationToken);
           cancellationToken.ThrowIfCancellationRequested();
           for (var i = 0; i < GenerationSize; i++) {
@@ -285,4 +306,8 @@
     }
 
+    public void SetInitialSamples(RealVector[] individuals, double[] qualities) {
+      InitialSamples = individuals.Zip(qualities, (individual, d) => new Tuple<RealVector, double>(individual, d)).ToList();
+    }
+
     #region Eventhandling
     private void RegisterEventhandlers() {
@@ -324,14 +349,13 @@
       if (ExecutionTime.TotalSeconds > MaximumRuntime) CancellationTokenSource.Cancel();
     }
-    protected override void OnPaused() {
-      base.OnPaused();
+    public override void Pause() {
       if (InfillOptimizationAlgorithm.ExecutionState == ExecutionState.Started) InfillOptimizationAlgorithm.Pause();
       if (RegressionAlgorithm.ExecutionState == ExecutionState.Started) RegressionAlgorithm.Pause();
-
-    }
-    protected override void OnStopped() {
-      base.OnStopped();
-      if (InfillOptimizationAlgorithm.ExecutionState != ExecutionState.Stopped) InfillOptimizationAlgorithm.Stop();
-      if (RegressionAlgorithm.ExecutionState != ExecutionState.Stopped) RegressionAlgorithm.Stop();
+      base.Pause();
+    }
+    public override void Stop() {
+      if (InfillOptimizationAlgorithm.ExecutionState == ExecutionState.Started || InfillOptimizationAlgorithm.ExecutionState == ExecutionState.Paused) InfillOptimizationAlgorithm.Stop();
+      if (RegressionAlgorithm.ExecutionState == ExecutionState.Started || RegressionAlgorithm.ExecutionState == ExecutionState.Paused) RegressionAlgorithm.Stop();
+      base.Stop();
     }
     protected override void OnProblemChanged() {
@@ -351,11 +375,11 @@
       InfillOptimizationAlgorithm.Problem = infillProblem;
     }
-    private IRegressionSolution BuildModel() {
-      var dataset = EgoUtilities.GetDataSet(Samples);
+    private IRegressionSolution BuildModel(CancellationToken cancellationToken) {
+      var dataset = EgoUtilities.GetDataSet(DataSamples.ToList());
       var problemdata = new RegressionProblemData(dataset, dataset.VariableNames.Where(x => !x.Equals("output")), "output");
       problemdata.TrainingPartition.Start = 0;
-      problemdata.TrainingPartition.End = Samples.Count;
-      problemdata.TestPartition.Start = Samples.Count;
-      problemdata.TestPartition.End = Samples.Count;
+      problemdata.TrainingPartition.End = dataset.Rows;
+      problemdata.TestPartition.Start = dataset.Rows;
+      problemdata.TestPartition.End = dataset.Rows;
 
       //train 
@@ -369,7 +393,9 @@
         solution = results.Select(x => x.Value).OfType<IRegressionSolution>().SingleOrDefault();
         r2 = solution?.TrainingRSquared ?? 0;
+        cancellationToken.ThrowIfCancellationRequested();
       }
-      ResultsQualities.Rows["DEBUG:ModelBuildingIterations"].Values.Add(i);
+
       if (solution == null) throw new ArgumentException("The Algorithm did not return a Model");
+      RegressionAlgorithm.Runs.Clear();
       return solution;
     }
@@ -381,4 +407,5 @@
       if (infillProblem.Problem != Problem) throw new ArgumentException("Expensive real problem is not correctly set in InfillProblem. Problem with Eventhandling?");
       infillProblem.RegressionSolution = ResultsModel;
+      if (MaximalDatasetSize > 0 && MaximalDatasetSize < Samples.Count) { infillProblem.Encoding.Bounds = EgoUtilities.GetBoundingBox(DataSamples.Select(x => x.Item1)); }
 
       RealVector bestVector = null;
@@ -406,9 +433,5 @@
     }
     private Tuple<RealVector, double> Evaluate(RealVector point) {
-      var scope = new Scope();
-      scope.Variables.Add(new Variable(Problem.Encoding.Name, point));
-      var ind = new SingleEncodingIndividual(Problem.Encoding, scope);
-      var q = Problem.Evaluate(ind, Random);
-      return new Tuple<RealVector, double>(point, q);
+      return new Tuple<RealVector, double>(point, Problem.Evaluate(GetIndividual(point), Random));
     }
     private void Analyze() {
@@ -422,4 +445,10 @@
       ResultsQualitiesIteration.Values.Add(Samples[Samples.Count - 1].Item2);
       ResultsQualitiesWorst.Values.Add(Samples[Problem.Maximization ? min : max].Item2);
+      Problem.Analyze(Samples.Select(x => GetIndividual(x.Item1)).ToArray(), Samples.Select(x => x.Item2).ToArray(), Results, Random);
+    }
+    private Individual GetIndividual(RealVector r) {
+      var scope = new Scope();
+      scope.Variables.Add(new Variable(Problem.Encoding.Name, r));
+      return new SingleEncodingIndividual(Problem.Encoding, scope);
     }
     #endregion
Index: branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/EgoUtilities.cs
===================================================================
--- branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/EgoUtilities.cs	(revision 14741)
+++ branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/EgoUtilities.cs	(revision 14768)
@@ -52,4 +52,15 @@
 
     public static ResultCollection SyncRunSubAlgorithm(IAlgorithm alg, int random) {
+
+      if (alg.Parameters.ContainsKey("SetSeedRandomly") && alg.Parameters.ContainsKey("Seed")) {
+        var setSeed = alg.Parameters["SetSeedRandomly"].ActualValue as BoolValue;
+        var seed = alg.Parameters["Seed"].ActualValue as IntValue;
+        if (seed == null || setSeed == null) throw new ArgumentException("wrong SeedParametertypes");
+        setSeed.Value = false;
+        seed.Value = random;
+
+      }
+
+
       EventWaitHandle trigger = new AutoResetEvent(false);
       Exception ex = null;
@@ -103,4 +114,18 @@
       return new Dataset(names.Concat(new[] { "output" }).ToArray(), data);
     }
+    public static DoubleMatrix GetBoundingBox(IEnumerable<RealVector> vectors) {
+      DoubleMatrix res = null;
+      foreach (var vector in vectors)
+        if (res == null) {
+          res = new DoubleMatrix(vector.Length, 2);
+          for (var i = 0; i < vector.Length; i++)
+            res[i, 0] = res[i, 1] = vector[i];
+        } else
+          for (var i = 0; i < vector.Length; i++) {
+            res[i, 0] = Math.Min(vector[i], res[i, 0]);
+            res[i, 1] = Math.Max(vector[i], res[i, 1]);
+          }
+      return res;
+    }
   }
 }
Index: branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/HeuristicLab.Algorithms.EGO-3.4.csproj
===================================================================
--- branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/HeuristicLab.Algorithms.EGO-3.4.csproj	(revision 14741)
+++ branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/HeuristicLab.Algorithms.EGO-3.4.csproj	(revision 14768)
@@ -67,4 +67,5 @@
       <HintPath>..\..\..\trunk\sources\bin\HeuristicLab.Encodings.RealVectorEncoding-3.3.dll</HintPath>
     </Reference>
+    <Reference Include="HeuristicLab.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec" />
     <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
       <SpecificVersion>False</SpecificVersion>
@@ -112,4 +113,5 @@
     <Compile Include="InfillCriteria\InfillCriterionBase.cs" />
     <Compile Include="InfillCriteria\ExpectedImprovement.cs" />
+    <Compile Include="Interfaces\ISurrogateAlgorithm.cs" />
     <Compile Include="Interfaces\IInfillCriterion.cs" />
     <Compile Include="Plugin.cs" />
Index: branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/ConfidenceBound.cs
===================================================================
--- branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/ConfidenceBound.cs	(revision 14741)
+++ branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/ConfidenceBound.cs	(revision 14768)
@@ -52,5 +52,4 @@
       get { return ConfidenceWeightParameter.Value.Value; }
     }
-
     #endregion
 
Index: branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/ExpectedImprovement.cs
===================================================================
--- branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/ExpectedImprovement.cs	(revision 14741)
+++ branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/ExpectedImprovement.cs	(revision 14768)
@@ -53,5 +53,4 @@
       get { return ExploitationWeightParameter.Value.Value; }
     }
-
     #endregion
 
Index: branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/RobustImprovement.cs
===================================================================
--- branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/RobustImprovement.cs	(revision 14741)
+++ branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/InfillCriteria/RobustImprovement.cs	(revision 14768)
@@ -52,5 +52,4 @@
       get { return ConfidenceWeightParameter.Value.Value; }
     }
-
     #endregion
 
Index: branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/Interfaces/ISurrogateAlgorithm.cs
===================================================================
--- branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/Interfaces/ISurrogateAlgorithm.cs	(revision 14768)
+++ branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/Interfaces/ISurrogateAlgorithm.cs	(revision 14768)
@@ -0,0 +1,30 @@
+﻿#region License Information
+/* HeuristicLab
+ * Copyright (C) 2002-2016 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
+
+// ReSharper disable once CheckNamespace
+using HeuristicLab.Common;
+using HeuristicLab.Optimization;
+
+namespace HeuristicLab.Algorithms.EGO {
+  public interface ISurrogateAlgorithm<T> : IAlgorithm where T : IDeepCloneable {
+    void SetInitialSamples(T[] i, double[] qualities);
+  }
+}
Index: branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/Plugin.cs.frame
===================================================================
--- branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/Plugin.cs.frame	(revision 14741)
+++ branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/Plugin.cs.frame	(revision 14768)
@@ -38,4 +38,5 @@
   [PluginDependency("HeuristicLab.Data", "3.3")]
   [PluginDependency("HeuristicLab.Encodings.RealVectorEncoding", "3.3")]
+  [PluginDependency("HeuristicLab.Operators","3.3")]
   [PluginDependency("HeuristicLab.Optimization","3.3")]
   [PluginDependency("HeuristicLab.Parameters","3.3")]
Index: branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/Problems/InfillProblem.cs
===================================================================
--- branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/Problems/InfillProblem.cs	(revision 14741)
+++ branches/EfficientGlobalOptimization/HeuristicLab.Algorithms.EGO/Problems/InfillProblem.cs	(revision 14768)
@@ -21,5 +21,4 @@
 
 using System;
-using HeuristicLab.Algorithms.EGO;
 using HeuristicLab.Common;
 using HeuristicLab.Core;
@@ -30,10 +29,9 @@
 using HeuristicLab.Problems.DataAnalysis;
 
-namespace HeuristicLab.Problems.SurrogateProblem {
+namespace HeuristicLab.Algorithms.EGO {
   [StorableClass]
   [Item("InfillProblem", "A problem for finding the most interesing potential new sampling Points by optimizing some InfillCriterion")]
   public sealed class InfillProblem : SingleObjectiveBasicProblem<RealVectorEncoding> {
 
-    [Storable]
     public override bool Maximization => true;
 
@@ -60,4 +58,5 @@
         if (problem == null) return;
         Encoding = problem.Encoding as RealVectorEncoding;
+        SolutionCreator = new UniformRandomRealVectorCreator();//ignore Problem specific Solution Creation
         if (Encoding == null) throw new ArgumentException("EGO can not be performed on non-RealVectorEncodings");
       }
