Index: branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP.StructureIdentification.TimeSeries/OffspringSelectionGP.cs
===================================================================
--- branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP.StructureIdentification/OffspringSelectionGP.cs	(revision 1239)
+++ branches/CEDMA-Refactoring-Ticket419/HeuristicLab.GP.StructureIdentification.TimeSeries/OffspringSelectionGP.cs	(revision 1245)
@@ -28,264 +28,45 @@
 using System.Diagnostics;
 using HeuristicLab.DataAnalysis;
+using HeuristicLab.Data;
 using HeuristicLab.Operators;
-using HeuristicLab.Random;
-using HeuristicLab.Selection;
-using HeuristicLab.Logging;
-using HeuristicLab.Data;
-using HeuristicLab.Operators.Programmable;
-using HeuristicLab.Selection.OffspringSelection;
 
-namespace HeuristicLab.GP.StructureIdentification {
-  public class OffspringSelectionGP : StandardGP {
-
-    private IntData maxEvaluatedSolutions = new IntData();
-    public int MaxEvaluatedSolutions {
-      get { return maxEvaluatedSolutions.Data; }
-      set { maxEvaluatedSolutions.Data = value; }
+namespace HeuristicLab.GP.StructureIdentification.TimeSeries {
+  public class OffspringSelectionGP : HeuristicLab.GP.StructureIdentification.OffspringSelectionGP {
+    protected override IOperator CreateFunctionLibraryInjector() {
+      return new FunctionLibraryInjector();
     }
 
-    private DoubleData selectionPressureLimit = new DoubleData();
-    public double SelectionPressureLimit {
-      get { return selectionPressureLimit.Data; }
-      set { selectionPressureLimit.Data = value; }
-    }
+    protected override IOperator CreateBestSolutionProcessor() {
+      IOperator seq = base.CreateBestSolutionProcessor();
+      TheilInequalityCoefficientEvaluator trainingTheil = new TheilInequalityCoefficientEvaluator();
+      trainingTheil.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
+      trainingTheil.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
+      trainingTheil.GetVariableInfo("TheilInequalityCoefficient").ActualName = "TrainingTheilInequalityCoefficient";
+      trainingTheil.GetVariableInfo("TheilInequalityCoefficientBias").ActualName = "TrainingTheilInequalityCoefficientBias";
+      trainingTheil.GetVariableInfo("TheilInequalityCoefficientVariance").ActualName = "TrainingTheilInequalityCoefficientVariance";
+      trainingTheil.GetVariableInfo("TheilInequalityCoefficientCovariance").ActualName = "TrainingTheilInequalityCoefficientCovariance";
 
-    private DoubleData comparisonFactor = new DoubleData();
-    public double ComparisonFactor {
-      get { return comparisonFactor.Data; }
-      set { comparisonFactor.Data = value; }
-    }
+      TheilInequalityCoefficientEvaluator validationTheil = new TheilInequalityCoefficientEvaluator();
+      validationTheil.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
+      validationTheil.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
+      validationTheil.GetVariableInfo("TheilInequalityCoefficient").ActualName = "ValidationTheilInequalityCoefficient";
+      validationTheil.GetVariableInfo("TheilInequalityCoefficientBias").ActualName = "ValidationTheilInequalityCoefficientBias";
+      validationTheil.GetVariableInfo("TheilInequalityCoefficientVariance").ActualName = "ValidationTheilInequalityCoefficientVariance";
+      validationTheil.GetVariableInfo("TheilInequalityCoefficientCovariance").ActualName = "ValidationTheilInequalityCoefficientCovariance";
 
-    private DoubleData successRatioLimit = new DoubleData();
-    public double SuccessRatioLimit {
-      get { return successRatioLimit.Data; }
-      set { successRatioLimit.Data = value; }
-    }
+      TheilInequalityCoefficientEvaluator testTheil = new TheilInequalityCoefficientEvaluator();
+      testTheil.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
+      testTheil.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
+      testTheil.GetVariableInfo("TheilInequalityCoefficient").ActualName = "TestTheilInequalityCoefficient";
+      testTheil.GetVariableInfo("TheilInequalityCoefficientBias").ActualName = "TestTheilInequalityCoefficientBias";
+      testTheil.GetVariableInfo("TheilInequalityCoefficientVariance").ActualName = "TestTheilInequalityCoefficientVariance";
+      testTheil.GetVariableInfo("TheilInequalityCoefficientCovariance").ActualName = "TestTheilInequalityCoefficientCovariance";
 
-    public OffspringSelectionGP() : base() {
-      PopulationSize = 1000;
-      Parents = 20;
-      MaxEvaluatedSolutions = 1000000;
-      SelectionPressureLimit = 300;
-      ComparisonFactor = 1.0;
-      SuccessRatioLimit = 1.0;
-    }
-
-    internal override IOperator CreateGlobalInjector() {
-      VariableInjector injector = (VariableInjector)base.CreateGlobalInjector();
-      injector.RemoveVariable("TournamentSize");
-      injector.RemoveVariable("MaxGenerations");
-      injector.AddVariable(new HeuristicLab.Core.Variable("MaxEvaluatedSolutions", maxEvaluatedSolutions));
-      injector.AddVariable(new HeuristicLab.Core.Variable("ComparisonFactor", comparisonFactor));
-      injector.AddVariable(new HeuristicLab.Core.Variable("SelectionPressureLimit", selectionPressureLimit));
-      injector.AddVariable(new HeuristicLab.Core.Variable("SuccessRatioLimit", successRatioLimit));
-      return injector;
-    }
-
-    internal override IOperator CreateSelector() {
-      CombinedOperator selector = new CombinedOperator();
-      selector.Name = "Selector";
-      SequentialProcessor seq = new SequentialProcessor();
-      seq.Name = "Selector";
-      EmptyOperator emptyOp = new EmptyOperator();
-      ProportionalSelector femaleSelector = new ProportionalSelector();
-      femaleSelector.GetVariableInfo("Selected").ActualName = "Parents";
-      femaleSelector.GetVariableValue<BoolData>("CopySelected", null, false).Data = true;
-
-      RandomSelector maleSelector = new RandomSelector();
-      maleSelector.GetVariableInfo("Selected").ActualName = "Parents";
-      maleSelector.GetVariableValue<BoolData>("CopySelected", null, false).Data = true;
-      SequentialSubScopesProcessor seqSubScopesProc = new SequentialSubScopesProcessor();
-      RightChildReducer rightChildReducer = new RightChildReducer();
-      SubScopesMixer mixer = new SubScopesMixer();
-
-      seqSubScopesProc.AddSubOperator(femaleSelector);
-      seqSubScopesProc.AddSubOperator(emptyOp);
-
-      seq.AddSubOperator(maleSelector);
-      seq.AddSubOperator(seqSubScopesProc);
-      seq.AddSubOperator(rightChildReducer);
-      seq.AddSubOperator(mixer);
-
-      selector.OperatorGraph.AddOperator(seq);
-      selector.OperatorGraph.InitialOperator = seq;
-      return selector;
-    }
-
-    internal override IOperator CreateChildCreater() {
-      CombinedOperator childCreater = new CombinedOperator();
-      childCreater.Name = "Create children";
-      SequentialProcessor seq = new SequentialProcessor();
-      SequentialProcessor offspringSelectionSeq = new SequentialProcessor();
-      OperatorExtractor selector = new OperatorExtractor();
-      selector.Name = "Selector (extr.)";
-      selector.GetVariableInfo("Operator").ActualName = "Selector";
-      SequentialSubScopesProcessor seqSubScopesProc = new SequentialSubScopesProcessor();
-      EmptyOperator emptyOp = new EmptyOperator();
-      OffspringSelector offspringSelector = new OffspringSelector();
-      OffspringAnalyzer offspringAnalyzer = new OffspringAnalyzer();
-      SequentialProcessor selectedProc = new SequentialProcessor();
-      OperatorExtractor crossover = new OperatorExtractor();
-      crossover.Name = "Crossover (extr.)";
-      crossover.GetVariableInfo("Operator").ActualName = "Crossover";
-      UniformSequentialSubScopesProcessor individualProc = new UniformSequentialSubScopesProcessor();
-      SequentialProcessor individualSeqProc = new SequentialProcessor();
-      StochasticBranch cond = new StochasticBranch();
-      cond.GetVariableInfo("Probability").ActualName = "MutationRate";
-      OperatorExtractor manipulator = new OperatorExtractor();
-      manipulator.Name = "Manipulator (extr.)";
-      manipulator.GetVariableInfo("Operator").ActualName = "Manipulator";
-      OperatorExtractor evaluator = new OperatorExtractor();
-      evaluator.Name = "Evaluator (extr.)";
-      evaluator.GetVariableInfo("Operator").ActualName = "Evaluator";
-      Counter evalCounter = new Counter();
-      evalCounter.GetVariableInfo("Value").ActualName = "EvaluatedSolutions";
-
-      Sorter sorter = new Sorter();
-      sorter.GetVariableInfo("Descending").ActualName = "Maximization";
-      sorter.GetVariableInfo("Value").ActualName = "Quality";
-
-      UniformSequentialSubScopesProcessor validationEvaluator = new UniformSequentialSubScopesProcessor();
-      MeanSquaredErrorEvaluator validationQualityEvaluator = new MeanSquaredErrorEvaluator();
-      validationQualityEvaluator.Name = "ValidationMeanSquaredErrorEvaluator";
-      validationQualityEvaluator.GetVariableInfo("MSE").ActualName = "ValidationQuality";
-      validationQualityEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
-      validationQualityEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
-
-      seqSubScopesProc.AddSubOperator(emptyOp);
-      seqSubScopesProc.AddSubOperator(offspringAnalyzer);
-
-      seq.AddSubOperator(offspringSelectionSeq);
-      offspringSelectionSeq.AddSubOperator(selector);
-      offspringSelectionSeq.AddSubOperator(seqSubScopesProc);
-      offspringSelectionSeq.AddSubOperator(offspringSelector);
-      offspringSelector.AddSubOperator(offspringSelectionSeq);
-
-      offspringAnalyzer.AddSubOperator(selectedProc);
-      selectedProc.AddSubOperator(crossover);
-      selectedProc.AddSubOperator(individualProc);
-      individualProc.AddSubOperator(individualSeqProc);
-      individualSeqProc.AddSubOperator(cond);
-      cond.AddSubOperator(manipulator);
-      individualSeqProc.AddSubOperator(evaluator);
-      individualSeqProc.AddSubOperator(evalCounter);
-
-      SequentialSubScopesProcessor seqSubScopesProc2 = new SequentialSubScopesProcessor();
-      seq.AddSubOperator(seqSubScopesProc2);
-      seqSubScopesProc2.AddSubOperator(emptyOp);
-
-      SequentialProcessor newGenProc = new SequentialProcessor();
-      newGenProc.AddSubOperator(sorter);
-      newGenProc.AddSubOperator(validationEvaluator);
-      seqSubScopesProc2.AddSubOperator(newGenProc);
-
-      validationEvaluator.AddSubOperator(validationQualityEvaluator);
-
-      childCreater.OperatorGraph.AddOperator(seq);
-      childCreater.OperatorGraph.InitialOperator = seq;
-      return childCreater;
-    }
-
-    internal override IOperator CreateLoopCondition(IOperator loop) {
-      SequentialProcessor seq = new SequentialProcessor();
-      seq.Name = "Loop Condition";
-      LessThanComparator generationsComparator = new LessThanComparator();
-      generationsComparator.GetVariableInfo("LeftSide").ActualName = "EvaluatedSolutions";
-      generationsComparator.GetVariableInfo("RightSide").ActualName = "MaxEvaluatedSolutions";
-      generationsComparator.GetVariableInfo("Result").ActualName = "EvaluatedSolutionsCondition";
-
-      LessThanComparator selPresComparator = new LessThanComparator();
-      selPresComparator.GetVariableInfo("LeftSide").ActualName = "SelectionPressure";
-      selPresComparator.GetVariableInfo("RightSide").ActualName = "SelectionPressureLimit";
-      selPresComparator.GetVariableInfo("Result").ActualName = "SelectionPressureCondition";
-      
-      ConditionalBranch generationsCond = new ConditionalBranch();
-      generationsCond.GetVariableInfo("Condition").ActualName = "EvaluatedSolutionsCondition";
-
-      ConditionalBranch selPresCond = new ConditionalBranch();
-      selPresCond.GetVariableInfo("Condition").ActualName = "SelectionPressureCondition";
-
-      seq.AddSubOperator(generationsComparator);
-      seq.AddSubOperator(selPresComparator);
-      seq.AddSubOperator(generationsCond);
-      generationsCond.AddSubOperator(selPresCond);
-      selPresCond.AddSubOperator(loop);
+      seq.AddSubOperator(trainingTheil);
+      seq.AddSubOperator(validationTheil);
+      seq.AddSubOperator(testTheil);
 
       return seq;
     }
-
-    internal override IOperator CreateLoggingOperator() {
-      CombinedOperator loggingOperator = new CombinedOperator();
-      loggingOperator.Name = "Logging";
-      SequentialProcessor seq = new SequentialProcessor();
-
-      DataCollector collector = new DataCollector();
-      ItemList<StringData> names = collector.GetVariable("VariableNames").GetValue<ItemList<StringData>>();
-      names.Add(new StringData("BestQuality"));
-      names.Add(new StringData("AverageQuality"));
-      names.Add(new StringData("WorstQuality"));
-      names.Add(new StringData("BestValidationQuality"));
-      names.Add(new StringData("AverageValidationQuality"));
-      names.Add(new StringData("WorstValidationQuality"));
-      names.Add(new StringData("EvaluatedSolutions"));
-      names.Add(new StringData("SelectionPressure"));
-      QualityLogger qualityLogger = new QualityLogger();
-      QualityLogger validationQualityLogger = new QualityLogger();
-      validationQualityLogger.Name = "ValidationQualityLogger";
-      validationQualityLogger.GetVariableInfo("Quality").ActualName = "ValidationQuality";
-      validationQualityLogger.GetVariableInfo("QualityLog").ActualName = "ValidationQualityLog";
-
-      seq.AddSubOperator(collector);
-      seq.AddSubOperator(qualityLogger);
-      seq.AddSubOperator(validationQualityLogger);
-
-      loggingOperator.OperatorGraph.AddOperator(seq);
-      loggingOperator.OperatorGraph.InitialOperator = seq;
-      return loggingOperator;
-    }
-
-
-    public override IEditor CreateEditor() {
-      return new OffspringSelectionGpEditor(this);
-    }
-
-    public override IView CreateView() {
-      return new OffspringSelectionGpEditor(this);
-    }
-
-    public override object Clone(IDictionary<Guid, object> clonedObjects) {
-      OffspringSelectionGP clone = (OffspringSelectionGP)base.Clone(clonedObjects);
-      clone.SelectionPressureLimit = SelectionPressureLimit;
-      clone.SuccessRatioLimit = SuccessRatioLimit;
-      clone.ComparisonFactor = ComparisonFactor;
-      return clone;
-    }
-
-    #region SetReferences Method
-    private void SetReferences() {
-      // SGA
-      CombinedOperator co1 = (CombinedOperator)Engine.OperatorGraph.InitialOperator;
-      // SequentialProcessor in SGA
-      SequentialProcessor algorithm = (SequentialProcessor)co1.OperatorGraph.InitialOperator;
-      // RandomInjector
-      RandomInjector ri = (RandomInjector)algorithm.SubOperators[1];
-      // VariableInjector
-      VariableInjector vi = (VariableInjector)algorithm.SubOperators[2];
-      selectionPressureLimit = vi.GetVariable("SelectionPressureLimit").GetValue<DoubleData>();
-      successRatioLimit = vi.GetVariable("SuccessRatioLimit").GetValue<DoubleData>();
-      comparisonFactor = vi.GetVariable("ComparisonFactor").GetValue<DoubleData>();
-    }
-    #endregion
-
-    #region Persistence Methods
-    public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
-      XmlNode node = base.GetXmlNode(name, document, persistedObjects);
-      return node;
-    }
-    public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
-      base.Populate(node, restoredObjects);
-      SetReferences();
-    }
-    #endregion
   }
 }
