Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
03/08/09 12:48:18 (16 years ago)
Author:
gkronber
Message:

Merged change sets from CEDMA branch to trunk:

Location:
trunk/sources/HeuristicLab.GP.StructureIdentification
Files:
4 deleted
1 edited
15 copied

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.GP.StructureIdentification/AlgorithmBase.cs

    r1231 r1287  
    3737namespace HeuristicLab.GP.StructureIdentification {
    3838  public abstract class AlgorithmBase : ItemBase {
    39     private DoubleData mutationRate = new DoubleData();
    4039    public virtual double MutationRate {
    41       get { return mutationRate.Data; }
    42       set { mutationRate.Data = value; }
    43     }
    44     private IntData populationSize = new IntData();
     40      get { return GetVariableInjector().GetVariable("MutationRate").GetValue<DoubleData>().Data; }
     41      set { GetVariableInjector().GetVariable("MutationRate").GetValue<DoubleData>().Data = value; }
     42    }
    4543    public virtual int PopulationSize {
    46       get { return populationSize.Data; }
    47       set {
    48         populationSize.Data = value;
    49       }
    50     }
    51 
    52     private BoolData setSeedRandomly = new BoolData();
     44      get { return GetVariableInjector().GetVariable("PopulationSize").GetValue<IntData>().Data; }
     45      set { GetVariableInjector().GetVariable("PopulationSize").GetValue<IntData>().Data = value; }
     46    }
     47
    5348    public virtual bool SetSeedRandomly {
    54       get { return setSeedRandomly.Data; }
    55       set { setSeedRandomly.Data = value; }
    56     }
    57 
    58     private IntData seed = new IntData();
     49      get { return GetRandomInjector().GetVariable("SetSeedRandomly").GetValue<BoolData>().Data; }
     50      set { GetRandomInjector().GetVariable("SetSeedRandomly").GetValue<BoolData>().Data = value; }
     51    }
     52
    5953    public virtual int Seed {
    60       get { return seed.Data; }
    61       set { seed.Data = value; }
     54      get { return GetRandomInjector().GetVariable("Seed").GetValue<IntData>().Data; }
     55      set { GetRandomInjector().GetVariable("Seed").GetValue<IntData>().Data = value; }
    6256    }
    6357
     
    7165    }
    7266
    73     private IntData elites = new IntData();
    7467    public virtual int Elites {
    75       get { return elites.Data; }
    76       set { elites.Data = value; }
    77     }
    78 
    79     private int maxTreeSize = 50;
     68      get { return GetVariableInjector().GetVariable("Elites").GetValue<IntData>().Data; }
     69      set { GetVariableInjector().GetVariable("Elites").GetValue<IntData>().Data = value; }
     70    }
     71
    8072    public virtual int MaxTreeSize {
    81       get { return maxTreeSize; }
    82       set { maxTreeSize = value; }
    83     }
    84 
    85     private int maxTreeHeight = 8;
     73      get { return GetVariableInjector().GetVariable("MaxTreeSize").GetValue<IntData>().Data; }
     74      set { GetVariableInjector().GetVariable("MaxTreeSize").GetValue<IntData>().Data = value; }
     75    }
     76
    8677    public virtual int MaxTreeHeight {
    87       get { return maxTreeHeight; }
    88       set { maxTreeHeight = value; }
    89     }
    90 
    91     private IntData parents = new IntData();
     78      get { return GetVariableInjector().GetVariable("MaxTreeHeight").GetValue<IntData>().Data; }
     79      set { GetVariableInjector().GetVariable("MaxTreeHeight").GetValue<IntData>().Data = value; }
     80    }
     81
    9282    public virtual int Parents {
    93       get { return parents.Data; }
    94       protected set { parents.Data = value; }
    95     }
    96 
    97     private double punishmentFactor = 10.0;
    98     private bool useEstimatedTargetValue = false;
     83      get { return GetVariableInjector().GetVariable("Parents").GetValue<IntData>().Data; }
     84      set { GetVariableInjector().GetVariable("Parents").GetValue<IntData>().Data = value; }
     85    }
     86
     87    public virtual double PunishmentFactor {
     88      get { return GetVariableInjector().GetVariable("PunishmentFactor").GetValue<DoubleData>().Data; }
     89      set { GetVariableInjector().GetVariable("PunishmentFactor").GetValue<DoubleData>().Data = value; }
     90    }
     91
     92    public virtual bool UseEstimatedTargetValue {
     93      get { return GetVariableInjector().GetVariable("UseEstimatedTargetValue").GetValue<BoolData>().Data; }
     94      set { GetVariableInjector().GetVariable("UseEstimatedTargetValue").GetValue<BoolData>().Data = value; }
     95    }
     96
    9997    private IOperator algorithm;
    10098
     
    110108      engine.OperatorGraph.AddOperator(algo);
    111109      engine.OperatorGraph.InitialOperator = algo;
    112     }
    113 
    114     internal virtual CombinedOperator CreateAlgorithm() {
     110      SetSeedRandomly = true;
     111      Elites = 1;
     112      MutationRate = 0.15;
     113      PopulationSize = 1000;
     114      MaxTreeSize = 100;
     115      MaxTreeHeight = 10;
     116      Parents = 2000;
     117      PunishmentFactor = 10;
     118      UseEstimatedTargetValue = false;
     119    }
     120
     121    protected internal virtual CombinedOperator CreateAlgorithm() {
    115122      CombinedOperator algo = new CombinedOperator();
    116123      algo.Name = "GP";
    117124      SequentialProcessor seq = new SequentialProcessor();
    118       EmptyOperator problemInjectorPlaceholder = new EmptyOperator();
     125      IOperator problemInjector = CreateProblemInjector();
    119126
    120127      RandomInjector randomInjector = new RandomInjector();
    121       randomInjector.GetVariable("SetSeedRandomly").Value = setSeedRandomly;
    122       randomInjector.GetVariable("Seed").Value = seed;
    123128      randomInjector.Name = "Random Injector";
    124129
    125130      IOperator globalInjector = CreateGlobalInjector();
    126131      IOperator initialization = CreateInitialization();
    127       IOperator funLibInjector = CreateFunctionLibraryInjector(); 
     132      IOperator funLibInjector = CreateFunctionLibraryInjector();
    128133      IOperator mainLoop = CreateMainLoop();
    129134      mainLoop.Name = "Main loop";
    130135
    131136      IOperator treeCreator = CreateTreeCreator();
    132      
     137
    133138      MeanSquaredErrorEvaluator evaluator = new MeanSquaredErrorEvaluator();
    134139      evaluator.GetVariableInfo("MSE").ActualName = "Quality";
     
    136141      evaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
    137142      evaluator.Name = "Evaluator";
    138      
     143
    139144      IOperator crossover = CreateCrossover();
    140145      IOperator manipulator = CreateManipulator();
     
    143148      LeftReducer cleanUp = new LeftReducer();
    144149
    145       seq.AddSubOperator(problemInjectorPlaceholder);
     150      seq.AddSubOperator(problemInjector);
    146151      seq.AddSubOperator(randomInjector);
    147152      seq.AddSubOperator(globalInjector);
     
    164169    }
    165170
    166     internal abstract IOperator CreateSelector();
    167 
    168     internal abstract IOperator CreateCrossover();
    169 
    170     internal abstract IOperator CreateTreeCreator();
    171 
    172     internal abstract IOperator CreateFunctionLibraryInjector();
    173 
    174     internal virtual IOperator CreateGlobalInjector() {
     171    protected internal virtual IOperator CreateProblemInjector() {
     172      return new EmptyOperator();
     173    }
     174
     175    protected internal abstract IOperator CreateSelector();
     176
     177    protected internal abstract IOperator CreateCrossover();
     178
     179    protected internal abstract IOperator CreateTreeCreator();
     180
     181    protected internal abstract IOperator CreateFunctionLibraryInjector();
     182
     183    protected internal virtual IOperator CreateGlobalInjector() {
    175184      VariableInjector injector = new VariableInjector();
    176185      injector.Name = "Global Injector";
    177186      injector.AddVariable(new HeuristicLab.Core.Variable("Generations", new IntData(0)));
    178       injector.AddVariable(new HeuristicLab.Core.Variable("MutationRate", mutationRate));
    179       injector.AddVariable(new HeuristicLab.Core.Variable("PopulationSize", populationSize));
    180       injector.AddVariable(new HeuristicLab.Core.Variable("Elites", elites));
     187      injector.AddVariable(new HeuristicLab.Core.Variable("MutationRate", new DoubleData()));
     188      injector.AddVariable(new HeuristicLab.Core.Variable("PopulationSize", new IntData()));
     189      injector.AddVariable(new HeuristicLab.Core.Variable("Elites", new IntData()));
    181190      injector.AddVariable(new HeuristicLab.Core.Variable("Maximization", new BoolData(false)));
    182       injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeHeight", new IntData(maxTreeHeight)));
    183       injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeSize", new IntData(maxTreeSize)));
     191      injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeHeight", new IntData()));
     192      injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeSize", new IntData()));
    184193      injector.AddVariable(new HeuristicLab.Core.Variable("EvaluatedSolutions", new IntData(0)));
    185194      injector.AddVariable(new HeuristicLab.Core.Variable("TotalEvaluatedNodes", new DoubleData(0)));
    186       injector.AddVariable(new HeuristicLab.Core.Variable("Parents", parents));
    187       injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(punishmentFactor)));
    188       injector.AddVariable(new HeuristicLab.Core.Variable("UseEstimatedTargetValue", new BoolData(useEstimatedTargetValue)));
     195      injector.AddVariable(new HeuristicLab.Core.Variable("Parents", new IntData()));
     196      injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData()));
     197      injector.AddVariable(new HeuristicLab.Core.Variable("UseEstimatedTargetValue", new BoolData()));
    189198      return injector;
    190199    }
    191200
    192     internal abstract IOperator CreateManipulator();
    193 
    194     internal virtual IOperator CreateInitialization() {
     201    protected internal abstract IOperator CreateManipulator();
     202
     203    protected internal virtual IOperator CreateInitialization() {
    195204      CombinedOperator init = new CombinedOperator();
    196205      init.Name = "Initialization";
     
    231240    }
    232241
    233     internal virtual IOperator CreateMainLoop() {
     242    protected internal virtual IOperator CreateMainLoop() {
    234243      CombinedOperator main = new CombinedOperator();
    235244      SequentialProcessor seq = new SequentialProcessor();
     
    244253      BestAverageWorstQualityCalculator qualityCalculator = new BestAverageWorstQualityCalculator();
    245254      BestAverageWorstQualityCalculator validationQualityCalculator = new BestAverageWorstQualityCalculator();
    246       validationQualityCalculator.Name = "ValidationQualityCalculator";
     255      validationQualityCalculator.Name = "BestAverageWorstValidationQualityCalculator";
     256      validationQualityCalculator.GetVariableInfo("Quality").ActualName = "ValidationQuality";
    247257      validationQualityCalculator.GetVariableInfo("BestQuality").ActualName = "BestValidationQuality";
    248258      validationQualityCalculator.GetVariableInfo("AverageQuality").ActualName = "AverageValidationQuality";
    249259      validationQualityCalculator.GetVariableInfo("WorstQuality").ActualName = "WorstValidationQuality";
    250       DataCollector collector = new DataCollector();
    251       ItemList<StringData> names = collector.GetVariable("VariableNames").GetValue<ItemList<StringData>>();
    252       names.Add(new StringData("BestQuality"));
    253       names.Add(new StringData("AverageQuality"));
    254       names.Add(new StringData("WorstQuality"));
    255       names.Add(new StringData("BestValidationQuality"));
    256       names.Add(new StringData("AverageValidationQuality"));
    257       names.Add(new StringData("WorstValidationQuality"));
    258       LinechartInjector lineChartInjector = new LinechartInjector();
    259       lineChartInjector.GetVariableInfo("Linechart").ActualName = "Quality Linechart";
    260       lineChartInjector.GetVariable("NumberOfLines").GetValue<IntData>().Data = 6;
    261       QualityLogger qualityLogger = new QualityLogger();
    262       QualityLogger validationQualityLogger = new QualityLogger();
    263       validationQualityCalculator.Name = "ValidationQualityLogger";
    264       validationQualityLogger.GetVariableInfo("Quality").ActualName = "ValidationQuality";
    265       validationQualityLogger.GetVariableInfo("QualityLog").ActualName = "ValidationQualityLog";
     260      IOperator loggingOperator = CreateLoggingOperator();
    266261      Counter counter = new Counter();
    267262      counter.GetVariableInfo("Value").ActualName = "Generations";
     263      IOperator loopCondition = CreateLoopCondition(seq);
     264
     265      seq.AddSubOperator(childCreater);
     266      seq.AddSubOperator(replacement);
     267      seq.AddSubOperator(solutionStorer);
     268      seq.AddSubOperator(qualityCalculator);
     269      seq.AddSubOperator(validationQualityCalculator);
     270      seq.AddSubOperator(loggingOperator);
     271      seq.AddSubOperator(counter);
     272      seq.AddSubOperator(loopCondition);
     273
     274      main.OperatorGraph.AddOperator(seq);
     275      main.OperatorGraph.InitialOperator = seq;
     276      return main;
     277    }
     278
     279    protected internal virtual IOperator CreateLoggingOperator() {
     280      return new EmptyOperator();
     281    }
     282
     283    protected internal virtual IOperator CreateLoopCondition(IOperator loop) {
     284      SequentialProcessor seq = new SequentialProcessor();
     285      seq.Name = "Loop Condition";
    268286      LessThanComparator comparator = new LessThanComparator();
    269287      comparator.GetVariableInfo("LeftSide").ActualName = "Generations";
     
    273291      cond.GetVariableInfo("Condition").ActualName = "GenerationsCondition";
    274292
    275       seq.AddSubOperator(childCreater);
    276       seq.AddSubOperator(replacement);
    277       seq.AddSubOperator(solutionStorer);
    278       seq.AddSubOperator(qualityCalculator);
    279       seq.AddSubOperator(validationQualityCalculator);
    280       seq.AddSubOperator(collector);
    281       seq.AddSubOperator(lineChartInjector);
    282       seq.AddSubOperator(qualityLogger);
    283       seq.AddSubOperator(validationQualityLogger);
    284       seq.AddSubOperator(counter);
    285293      seq.AddSubOperator(comparator);
    286294      seq.AddSubOperator(cond);
    287       cond.AddSubOperator(seq);
    288 
    289       main.OperatorGraph.AddOperator(seq);
    290       main.OperatorGraph.InitialOperator = seq;
    291       return main;
    292     }
    293 
    294     internal virtual IOperator CreateBestSolutionProcessor() {
     295
     296      cond.AddSubOperator(loop);
     297      return seq;
     298    }
     299
     300    protected internal virtual IOperator CreateBestSolutionProcessor() {
    295301      return new EmptyOperator();
    296302    }
    297303
    298     internal virtual IOperator CreateReplacement() {
     304    protected internal virtual IOperator CreateReplacement() {
    299305      CombinedOperator replacement = new CombinedOperator();
    300306      replacement.Name = "Replacement";
     
    330336    }
    331337
    332     internal virtual IOperator CreateChildCreater() {
     338    protected internal virtual IOperator CreateChildCreater() {
    333339      CombinedOperator childCreater = new CombinedOperator();
    334340      childCreater.Name = "Create children";
     
    391397    }
    392398
    393     #region SetReferences Method
    394     private void SetReferences() {
    395       // SGA
     399    protected VariableInjector GetVariableInjector() {
    396400      CombinedOperator co1 = (CombinedOperator)Engine.OperatorGraph.InitialOperator;
    397       // SequentialProcessor in SGA
     401      // SequentialProcessor in GP
    398402      algorithm = (SequentialProcessor)co1.OperatorGraph.InitialOperator;
    399       // RandomInjector
    400       RandomInjector ri = (RandomInjector)algorithm.SubOperators[1];
    401       setSeedRandomly = ri.GetVariable("SetSeedRandomly").GetValue<BoolData>();
    402       seed = ri.GetVariable("Seed").GetValue<IntData>();
    403       // VariableInjector
    404       VariableInjector vi = (VariableInjector)algorithm.SubOperators[2];
    405       populationSize = vi.GetVariable("PopulationSize").GetValue<IntData>();
    406       mutationRate = vi.GetVariable("MutationRate").GetValue<DoubleData>();
    407       elites = vi.GetVariable("Elites").GetValue<IntData>();
    408       parents = vi.GetVariable("Parents").GetValue<IntData>();
    409     }
    410     #endregion
     403      return (VariableInjector)algorithm.SubOperators[2];
     404    }
     405
     406    protected RandomInjector GetRandomInjector() {
     407      CombinedOperator co1 = (CombinedOperator)Engine.OperatorGraph.InitialOperator;
     408      // SequentialProcessor in GP
     409      algorithm = (SequentialProcessor)co1.OperatorGraph.InitialOperator;
     410      return (RandomInjector)algorithm.SubOperators[1];
     411    }
    411412
    412413    #region Persistence Methods
     
    419420      base.Populate(node, restoredObjects);
    420421      engine = (SequentialEngine.SequentialEngine)PersistenceManager.Restore(node.SelectSingleNode("Engine"), restoredObjects);
    421       SetReferences();
    422422    }
    423423    #endregion
  • trunk/sources/HeuristicLab.GP.StructureIdentification/FunctionLibraryInjector.cs

    r1053 r1287  
    3636    private const string FUNCTIONLIBRARY = "FunctionLibrary";
    3737
    38     private StructId.Variable variable;
    39     private GPOperatorLibrary operatorLibrary;
    40 
    4138    public override string Description {
    4239      get { return @"Injects a default function library for regression and classification problems."; }
     
    5148
    5249    public override IOperation Apply(IScope scope) {
     50      StructId.Variable variable;
     51      GPOperatorLibrary operatorLibrary;
     52
    5353      ItemList<IntData> allowedFeatures = GetVariableValue<ItemList<IntData>>(ALLOWEDFEATURES, scope, true);
    5454      int targetVariable = GetVariableValue<IntData>(TARGETVARIABLE, scope, true).Data;
     
    5656      // remove the target-variable in case it occures in allowed features
    5757      List<IntData> ts = allowedFeatures.FindAll(d => d.Data == targetVariable);
    58       foreach(IntData t in ts) allowedFeatures.Remove(t);
    59 
    60       InitDefaultOperatorLibrary();
    61 
    62       int[] allowedIndexes = new int[allowedFeatures.Count];
    63       for(int i = 0; i < allowedIndexes.Length; i++) {
    64         allowedIndexes[i] = allowedFeatures[i].Data;
    65       }
    66 
    67       variable.SetConstraints(allowedIndexes, 0, 0);
    68 
    69       scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), operatorLibrary));
    70       return null;
    71     }
    72 
    73     private void InitDefaultOperatorLibrary() {
     58      foreach (IntData t in ts) allowedFeatures.Remove(t);
     59
    7460      variable = new StructId.Variable();
    7561      StructId.Constant constant = new StructId.Constant();
     
    173159      operatorLibrary.GPOperatorGroup.AddOperator(tangens);
    174160      operatorLibrary.GPOperatorGroup.AddOperator(xor);
     161
     162      int[] allowedIndexes = new int[allowedFeatures.Count];
     163      for (int i = 0; i < allowedIndexes.Length; i++) {
     164        allowedIndexes[i] = allowedFeatures[i].Data;
     165      }
     166
     167      variable.SetConstraints(allowedIndexes, 0, 0);
     168
     169      scope.AddVariable(new HeuristicLab.Core.Variable(scope.TranslateName(FUNCTIONLIBRARY), operatorLibrary));
     170      return null;
    175171    }
    176172
    177173    private void SetAllowedSubOperators(IFunction f, IFunction[] gs) {
    178       foreach(IConstraint c in f.Constraints) {
    179         if(c is SubOperatorTypeConstraint) {
     174      foreach (IConstraint c in f.Constraints) {
     175        if (c is SubOperatorTypeConstraint) {
    180176          SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint;
    181177          typeConstraint.Clear();
    182           foreach(IFunction g in gs) {
     178          foreach (IFunction g in gs) {
    183179            typeConstraint.AddOperator(g);
    184180          }
    185         } else if(c is AllSubOperatorsTypeConstraint) {
     181        } else if (c is AllSubOperatorsTypeConstraint) {
    186182          AllSubOperatorsTypeConstraint typeConstraint = c as AllSubOperatorsTypeConstraint;
    187183          typeConstraint.Clear();
    188           foreach(IFunction g in gs) {
     184          foreach (IFunction g in gs) {
    189185            typeConstraint.AddOperator(g);
    190186          }
     
    194190
    195191    private void SetAllowedSubOperators(IFunction f, int p, IFunction[] gs) {
    196       foreach(IConstraint c in f.Constraints) {
    197         if(c is SubOperatorTypeConstraint) {
     192      foreach (IConstraint c in f.Constraints) {
     193        if (c is SubOperatorTypeConstraint) {
    198194          SubOperatorTypeConstraint typeConstraint = c as SubOperatorTypeConstraint;
    199           if(typeConstraint.SubOperatorIndex.Data == p) {
     195          if (typeConstraint.SubOperatorIndex.Data == p) {
    200196            typeConstraint.Clear();
    201             foreach(IFunction g in gs) {
     197            foreach (IFunction g in gs) {
    202198              typeConstraint.AddOperator(g);
    203199            }
  • trunk/sources/HeuristicLab.GP.StructureIdentification/HeuristicLab.GP.StructureIdentification.csproj

    r852 r1287  
    7171    <Compile Include="BakedTreeEvaluator.cs" />
    7272    <Compile Include="Constant.cs" />
     73    <Compile Include="AlgorithmBase.cs" />
     74    <Compile Include="Evaluators\MeanAbsolutePercentageOfRangeErrorEvaluator.cs" />
     75    <Compile Include="FunctionLibraryInjector.cs" />
     76    <Compile Include="OffspringSelectionGP.cs" />
     77    <Compile Include="OffSpringSelectionGpEditor.cs">
     78      <SubType>UserControl</SubType>
     79    </Compile>
     80    <Compile Include="OffSpringSelectionGpEditor.Designer.cs">
     81      <DependentUpon>OffSpringSelectionGpEditor.cs</DependentUpon>
     82    </Compile>
     83    <Compile Include="ProblemInjector.cs" />
     84    <Compile Include="ProblemInjectorView.cs">
     85      <SubType>UserControl</SubType>
     86    </Compile>
     87    <Compile Include="ProblemInjectorView.Designer.cs">
     88      <DependentUpon>ProblemInjectorView.cs</DependentUpon>
     89    </Compile>
     90    <Compile Include="StandardGpEditor.cs">
     91      <SubType>UserControl</SubType>
     92    </Compile>
     93    <Compile Include="StandardGpEditor.Designer.cs">
     94      <DependentUpon>StandardGpEditor.cs</DependentUpon>
     95    </Compile>
     96    <Compile Include="StandardGP.cs" />
    7397    <Compile Include="Cosinus.cs" />
    7498    <Compile Include="Differential.cs" />
     
    98122    <Compile Include="Sinus.cs" />
    99123    <Compile Include="Sqrt.cs" />
    100     <Compile Include="StructIdProblemInjector.cs" />
    101     <Compile Include="StructIdProblemInjectorView.cs">
    102       <SubType>UserControl</SubType>
    103     </Compile>
    104     <Compile Include="StructIdProblemInjectorView.Designer.cs">
    105       <DependentUpon>StructIdProblemInjectorView.cs</DependentUpon>
    106     </Compile>
    107124    <Compile Include="Subtraction.cs" />
    108125    <Compile Include="SymbolicExpressionExporter.cs" />
     
    129146      <Name>HeuristicLab.Data</Name>
    130147    </ProjectReference>
     148    <ProjectReference Include="..\HeuristicLab.Evolutionary\HeuristicLab.Evolutionary.csproj">
     149      <Project>{F5614C53-153C-4A37-A608-121E1C087F07}</Project>
     150      <Name>HeuristicLab.Evolutionary</Name>
     151    </ProjectReference>
    131152    <ProjectReference Include="..\HeuristicLab.GP\HeuristicLab.GP.csproj">
    132153      <Project>{1F1CF3ED-374C-4288-995B-93F6B872F571}</Project>
    133154      <Name>HeuristicLab.GP</Name>
    134155    </ProjectReference>
     156    <ProjectReference Include="..\HeuristicLab.Logging\HeuristicLab.Logging.csproj">
     157      <Project>{4095C92C-5A4C-44BC-9963-5F384CF5CC3F}</Project>
     158      <Name>HeuristicLab.Logging</Name>
     159    </ProjectReference>
     160    <ProjectReference Include="..\HeuristicLab.Operators.Programmable\HeuristicLab.Operators.Programmable.csproj">
     161      <Project>{E3CCBFC6-900C-41B6-AFB8-6646DB097435}</Project>
     162      <Name>HeuristicLab.Operators.Programmable</Name>
     163    </ProjectReference>
    135164    <ProjectReference Include="..\HeuristicLab.Operators\HeuristicLab.Operators.csproj">
    136165      <Project>{A9983BA2-B3B2-475E-8E2C-62050B71D1C5}</Project>
     
    145174      <Name>HeuristicLab.Random</Name>
    146175    </ProjectReference>
    147   </ItemGroup>
    148   <ItemGroup>
    149     <EmbeddedResource Include="StructIdProblemInjectorView.resx">
    150       <DependentUpon>StructIdProblemInjectorView.cs</DependentUpon>
     176    <ProjectReference Include="..\HeuristicLab.Selection.OffspringSelection\HeuristicLab.Selection.OffspringSelection.csproj">
     177      <Project>{205898D3-2717-4686-AF17-52409B7EC0C6}</Project>
     178      <Name>HeuristicLab.Selection.OffspringSelection</Name>
     179    </ProjectReference>
     180    <ProjectReference Include="..\HeuristicLab.Selection\HeuristicLab.Selection.csproj">
     181      <Project>{F7CF0571-25CB-43D5-8443-0843A1E2861A}</Project>
     182      <Name>HeuristicLab.Selection</Name>
     183    </ProjectReference>
     184    <ProjectReference Include="..\HeuristicLab.SequentialEngine\HeuristicLab.SequentialEngine.csproj">
     185      <Project>{B4BE8E53-BA06-4237-9A01-24255F880201}</Project>
     186      <Name>HeuristicLab.SequentialEngine</Name>
     187    </ProjectReference>
     188  </ItemGroup>
     189  <ItemGroup>
     190    <EmbeddedResource Include="OffSpringSelectionGpEditor.resx">
     191      <DependentUpon>OffSpringSelectionGpEditor.cs</DependentUpon>
     192    </EmbeddedResource>
     193    <EmbeddedResource Include="ProblemInjectorView.resx">
     194      <DependentUpon>ProblemInjectorView.cs</DependentUpon>
     195    </EmbeddedResource>
     196    <EmbeddedResource Include="StandardGpEditor.resx">
     197      <DependentUpon>StandardGpEditor.cs</DependentUpon>
    151198      <SubType>Designer</SubType>
    152199    </EmbeddedResource>
  • trunk/sources/HeuristicLab.GP.StructureIdentification/OffSpringSelectionGpEditor.Designer.cs

    r1156 r1287  
    4949      this.tabControl = new System.Windows.Forms.TabControl();
    5050      this.parametersTabPage = new System.Windows.Forms.TabPage();
     51      this.selectionPressureTextBox = new System.Windows.Forms.TextBox();
     52      this.selectionPressureLabel = new System.Windows.Forms.Label();
    5153      this.viewProblemInitializationButton = new System.Windows.Forms.Button();
    5254      this.setProblemInitializationButton = new System.Windows.Forms.Button();
     
    5860      this.mutationRateTextBox = new System.Windows.Forms.TextBox();
    5961      this.mutationRateLabel = new System.Windows.Forms.Label();
    60       this.maximumGenerationsTextBox = new System.Windows.Forms.TextBox();
    61       this.maximumGenerationsLabel = new System.Windows.Forms.Label();
     62      this.maximumEvaluatedSolutionsTextBox = new System.Windows.Forms.TextBox();
     63      this.maxEvaluatedSolutionsLabel = new System.Windows.Forms.Label();
    6264      this.randomSeedTextBox = new System.Windows.Forms.TextBox();
    6365      this.populationSizeTextBox = new System.Windows.Forms.TextBox();
     
    101103      // parametersTabPage
    102104      //
     105      this.parametersTabPage.Controls.Add(this.selectionPressureTextBox);
     106      this.parametersTabPage.Controls.Add(this.selectionPressureLabel);
    103107      this.parametersTabPage.Controls.Add(this.viewProblemInitializationButton);
    104108      this.parametersTabPage.Controls.Add(this.setProblemInitializationButton);
     
    110114      this.parametersTabPage.Controls.Add(this.mutationRateTextBox);
    111115      this.parametersTabPage.Controls.Add(this.mutationRateLabel);
    112       this.parametersTabPage.Controls.Add(this.maximumGenerationsTextBox);
    113       this.parametersTabPage.Controls.Add(this.maximumGenerationsLabel);
     116      this.parametersTabPage.Controls.Add(this.maximumEvaluatedSolutionsTextBox);
     117      this.parametersTabPage.Controls.Add(this.maxEvaluatedSolutionsLabel);
    114118      this.parametersTabPage.Controls.Add(this.randomSeedTextBox);
    115119      this.parametersTabPage.Controls.Add(this.populationSizeTextBox);
     
    125129      this.parametersTabPage.UseVisualStyleBackColor = true;
    126130      //
     131      // selectionPressureTextBox
     132      //
     133      this.selectionPressureTextBox.Anchor = System.Windows.Forms.AnchorStyles.None;
     134      this.selectionPressureTextBox.Location = new System.Drawing.Point(218, 130);
     135      this.selectionPressureTextBox.Name = "selectionPressureTextBox";
     136      this.selectionPressureTextBox.Size = new System.Drawing.Size(186, 20);
     137      this.selectionPressureTextBox.TabIndex = 17;
     138      //
     139      // selectionPressureLabel
     140      //
     141      this.selectionPressureLabel.Anchor = System.Windows.Forms.AnchorStyles.None;
     142      this.selectionPressureLabel.AutoSize = true;
     143      this.selectionPressureLabel.Location = new System.Drawing.Point(65, 133);
     144      this.selectionPressureLabel.Name = "selectionPressureLabel";
     145      this.selectionPressureLabel.Size = new System.Drawing.Size(145, 13);
     146      this.selectionPressureLabel.TabIndex = 16;
     147      this.selectionPressureLabel.Text = "Maximum &Selection Pressure:";
     148      //
    127149      // viewProblemInitializationButton
    128150      //
    129151      this.viewProblemInitializationButton.Anchor = System.Windows.Forms.AnchorStyles.None;
    130       this.viewProblemInitializationButton.Location = new System.Drawing.Point(410, 208);
     152      this.viewProblemInitializationButton.Location = new System.Drawing.Point(410, 241);
    131153      this.viewProblemInitializationButton.Name = "viewProblemInitializationButton";
    132154      this.viewProblemInitializationButton.Size = new System.Drawing.Size(53, 20);
     
    139161      //
    140162      this.setProblemInitializationButton.Anchor = System.Windows.Forms.AnchorStyles.None;
    141       this.setProblemInitializationButton.Location = new System.Drawing.Point(469, 208);
     163      this.setProblemInitializationButton.Location = new System.Drawing.Point(469, 241);
    142164      this.setProblemInitializationButton.Name = "setProblemInitializationButton";
    143165      this.setProblemInitializationButton.Size = new System.Drawing.Size(43, 20);
     
    150172      //
    151173      this.problemInitializationTextBox.Anchor = System.Windows.Forms.AnchorStyles.None;
    152       this.problemInitializationTextBox.Location = new System.Drawing.Point(218, 208);
     174      this.problemInitializationTextBox.Location = new System.Drawing.Point(218, 241);
    153175      this.problemInitializationTextBox.Name = "problemInitializationTextBox";
    154176      this.problemInitializationTextBox.ReadOnly = true;
     
    165187      this.setRandomSeedRandomlyCheckBox.TabIndex = 1;
    166188      this.setRandomSeedRandomlyCheckBox.UseVisualStyleBackColor = true;
     189      this.setRandomSeedRandomlyCheckBox.CheckedChanged += new System.EventHandler(this.setRandomSeedRandomlyCheckBox_CheckedChanged);
    167190      //
    168191      // elitesTextBox
    169192      //
    170193      this.elitesTextBox.Anchor = System.Windows.Forms.AnchorStyles.None;
    171       this.elitesTextBox.Location = new System.Drawing.Point(218, 156);
     194      this.elitesTextBox.Location = new System.Drawing.Point(218, 182);
    172195      this.elitesTextBox.Name = "elitesTextBox";
    173196      this.elitesTextBox.Size = new System.Drawing.Size(186, 20);
     
    178201      this.problemInitializationLabel.Anchor = System.Windows.Forms.AnchorStyles.None;
    179202      this.problemInitializationLabel.AutoSize = true;
    180       this.problemInitializationLabel.Location = new System.Drawing.Point(65, 211);
     203      this.problemInitializationLabel.Location = new System.Drawing.Point(65, 244);
    181204      this.problemInitializationLabel.Name = "problemInitializationLabel";
    182205      this.problemInitializationLabel.Size = new System.Drawing.Size(105, 13);
     
    188211      this.elitesLabel.Anchor = System.Windows.Forms.AnchorStyles.None;
    189212      this.elitesLabel.AutoSize = true;
    190       this.elitesLabel.Location = new System.Drawing.Point(65, 159);
     213      this.elitesLabel.Location = new System.Drawing.Point(66, 185);
    191214      this.elitesLabel.Name = "elitesLabel";
    192215      this.elitesLabel.Size = new System.Drawing.Size(35, 13);
     
    197220      //
    198221      this.mutationRateTextBox.Anchor = System.Windows.Forms.AnchorStyles.None;
    199       this.mutationRateTextBox.Location = new System.Drawing.Point(218, 130);
     222      this.mutationRateTextBox.Location = new System.Drawing.Point(218, 156);
    200223      this.mutationRateTextBox.Name = "mutationRateTextBox";
    201224      this.mutationRateTextBox.Size = new System.Drawing.Size(186, 20);
     
    206229      this.mutationRateLabel.Anchor = System.Windows.Forms.AnchorStyles.None;
    207230      this.mutationRateLabel.AutoSize = true;
    208       this.mutationRateLabel.Location = new System.Drawing.Point(65, 133);
     231      this.mutationRateLabel.Location = new System.Drawing.Point(66, 159);
    209232      this.mutationRateLabel.Name = "mutationRateLabel";
    210233      this.mutationRateLabel.Size = new System.Drawing.Size(77, 13);
     
    212235      this.mutationRateLabel.Text = "&Mutation Rate:";
    213236      //
    214       // maximumGenerationsTextBox
    215       //
    216       this.maximumGenerationsTextBox.Anchor = System.Windows.Forms.AnchorStyles.None;
    217       this.maximumGenerationsTextBox.Location = new System.Drawing.Point(218, 104);
    218       this.maximumGenerationsTextBox.Name = "maximumGenerationsTextBox";
    219       this.maximumGenerationsTextBox.Size = new System.Drawing.Size(186, 20);
    220       this.maximumGenerationsTextBox.TabIndex = 7;
    221       //
    222       // maximumGenerationsLabel
    223       //
    224       this.maximumGenerationsLabel.Anchor = System.Windows.Forms.AnchorStyles.None;
    225       this.maximumGenerationsLabel.AutoSize = true;
    226       this.maximumGenerationsLabel.Location = new System.Drawing.Point(65, 107);
    227       this.maximumGenerationsLabel.Name = "maximumGenerationsLabel";
    228       this.maximumGenerationsLabel.Size = new System.Drawing.Size(114, 13);
    229       this.maximumGenerationsLabel.TabIndex = 6;
    230       this.maximumGenerationsLabel.Text = "Maximum &Generations:";
     237      // maximumEvaluatedSolutionsTextBox
     238      //
     239      this.maximumEvaluatedSolutionsTextBox.Anchor = System.Windows.Forms.AnchorStyles.None;
     240      this.maximumEvaluatedSolutionsTextBox.Location = new System.Drawing.Point(218, 104);
     241      this.maximumEvaluatedSolutionsTextBox.Name = "maximumEvaluatedSolutionsTextBox";
     242      this.maximumEvaluatedSolutionsTextBox.Size = new System.Drawing.Size(186, 20);
     243      this.maximumEvaluatedSolutionsTextBox.TabIndex = 7;
     244      //
     245      // maxEvaluatedSolutionsLabel
     246      //
     247      this.maxEvaluatedSolutionsLabel.Anchor = System.Windows.Forms.AnchorStyles.None;
     248      this.maxEvaluatedSolutionsLabel.AutoSize = true;
     249      this.maxEvaluatedSolutionsLabel.Location = new System.Drawing.Point(65, 107);
     250      this.maxEvaluatedSolutionsLabel.Name = "maxEvaluatedSolutionsLabel";
     251      this.maxEvaluatedSolutionsLabel.Size = new System.Drawing.Size(130, 13);
     252      this.maxEvaluatedSolutionsLabel.TabIndex = 6;
     253      this.maxEvaluatedSolutionsLabel.Text = "Max. E&valuated Solutions:";
    231254      //
    232255      // randomSeedTextBox
     
    331354      this.cloneEngineButton.Click += new System.EventHandler(this.cloneEngineButton_Click);
    332355      //
    333       // StandardGpEditor
     356      // OffspringSelectionGpEditor
    334357      //
    335358      this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
     
    340363      this.Controls.Add(this.abortButton);
    341364      this.Controls.Add(this.executeButton);
    342       this.Name = "StandardGpEditor";
     365      this.Name = "OffspringSelectionGpEditor";
    343366      this.Size = new System.Drawing.Size(526, 419);
    344367      this.tabControl.ResumeLayout(false);
     
    353376
    354377    private System.Windows.Forms.Button executeButton;
    355     private System.Windows.Forms.TabControl tabControl;
    356     private System.Windows.Forms.TabPage parametersTabPage;
     378    protected System.Windows.Forms.TabControl tabControl;
     379    protected System.Windows.Forms.TabPage parametersTabPage;
    357380    private System.Windows.Forms.Button abortButton;
    358381    private System.Windows.Forms.Button resetButton;
     
    362385    private System.Windows.Forms.Label populationSizeLabel;
    363386    private System.Windows.Forms.TabPage scopesTabPage;
    364     private System.Windows.Forms.TextBox maximumGenerationsTextBox;
    365     private System.Windows.Forms.Label maximumGenerationsLabel;
     387    private System.Windows.Forms.TextBox maximumEvaluatedSolutionsTextBox;
     388    private System.Windows.Forms.Label maxEvaluatedSolutionsLabel;
    366389    private System.Windows.Forms.TextBox elitesTextBox;
    367390    private System.Windows.Forms.Label elitesLabel;
     
    376399    private HeuristicLab.Core.ScopeView scopeView;
    377400    private System.Windows.Forms.Button viewProblemInitializationButton;
     401    private System.Windows.Forms.TextBox selectionPressureTextBox;
     402    private System.Windows.Forms.Label selectionPressureLabel;
    378403  }
    379404}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/OffSpringSelectionGpEditor.cs

    r1156 r1287  
    3434    private ChooseOperatorDialog chooseOperatorDialog;
    3535
    36     public OffspringSelectionGpEditor OffspringSelectionGpEditor {
    37       get { return (OffspringSelectionGpEditor)Item; }
     36    public OffspringSelectionGP OffspringSelectionGP {
     37      get { return (OffspringSelectionGP)Item; }
    3838      set { base.Item = value; }
    3939    }
     
    4242      InitializeComponent();
    4343    }
    44     public OffspringSelectionGpEditor(OffspringSelectionGpEditor osgp)
     44    public OffspringSelectionGpEditor(OffspringSelectionGP osgp)
    4545      : this() {
    46       OffspringSelectionGpEditor = osgp;
     46      OffspringSelectionGP = osgp;
    4747    }
    4848
    4949    protected override void RemoveItemEvents() {
    50       OffspringSelectionGpEditor.Engine.ExceptionOccurred -= new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred);
    51       OffspringSelectionGpEditor.Engine.Finished -= new EventHandler(Engine_Finished);
     50      OffspringSelectionGP.Engine.ExceptionOccurred -= new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred);
     51      OffspringSelectionGP.Engine.Finished -= new EventHandler(Engine_Finished);
    5252      scopeView.Scope = null;
    5353      base.RemoveItemEvents();
    5454    }
     55
    5556    protected override void AddItemEvents() {
    5657      base.AddItemEvents();
    57       OffspringSelectionGpEditor.Engine.ExceptionOccurred += new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred);
    58       OffspringSelectionGpEditor.Engine.Finished += new EventHandler(Engine_Finished);
     58      OffspringSelectionGP.Engine.ExceptionOccurred += new EventHandler<ExceptionEventArgs>(Engine_ExceptionOccurred);
     59      OffspringSelectionGP.Engine.Finished += new EventHandler(Engine_Finished);
    5960      SetDataBinding();
    60       scopeView.Scope = OffspringSelectionGpEditor.Engine.GlobalScope;
     61      scopeView.Scope = OffspringSelectionGP.Engine.GlobalScope;
    6162    }
    6263
    6364    protected override void UpdateControls() {
    6465      base.UpdateControls();
    65       if (OffspringSelectionGpEditor == null) {
     66      if (OffspringSelectionGP == null) {
    6667        tabControl.Enabled = false;
    6768      } else {
    6869        tabControl.Enabled = true;
    69         problemInitializationTextBox.Text = OffspringSelectionGpEditor.ProblemInjector.GetType().Name;
     70        problemInitializationTextBox.Text = OffspringSelectionGP.ProblemInjector.GetType().Name;
    7071      }
    7172    }
    7273
    73     private void SetDataBinding() {
    74       setRandomSeedRandomlyCheckBox.DataBindings.Add("Checked", OffspringSelectionGpEditor, "SetSeedRandomly");
    75       randomSeedTextBox.DataBindings.Add("Text", OffspringSelectionGpEditor, "Seed");
    76       populationSizeTextBox.DataBindings.Add("Text", OffspringSelectionGpEditor, "PopulationSize");
    77       maximumGenerationsTextBox.DataBindings.Add("Text", OffspringSelectionGpEditor, "MaxGenerations");
    78       mutationRateTextBox.DataBindings.Add("Text", OffspringSelectionGpEditor, "MutationRate");
    79       elitesTextBox.DataBindings.Add("Text", OffspringSelectionGpEditor, "Elites");
     74    protected virtual void SetDataBinding() {
     75      setRandomSeedRandomlyCheckBox.DataBindings.Add("Checked", OffspringSelectionGP, "SetSeedRandomly");
     76      randomSeedTextBox.DataBindings.Add("Text", OffspringSelectionGP, "Seed");
     77      populationSizeTextBox.DataBindings.Add("Text", OffspringSelectionGP, "PopulationSize");
     78      maximumEvaluatedSolutionsTextBox.DataBindings.Add("Text", OffspringSelectionGP, "MaxEvaluatedSolutions");
     79      selectionPressureTextBox.DataBindings.Add("Text", OffspringSelectionGP, "SelectionPressureLimit");
     80      mutationRateTextBox.DataBindings.Add("Text", OffspringSelectionGP, "MutationRate");
     81      elitesTextBox.DataBindings.Add("Text", OffspringSelectionGP, "Elites");
    8082    }
    8183
    8284    #region Button Events
    8385    private void viewProblemInjectorButton_Click(object sender, EventArgs e) {
    84       IView view = OffspringSelectionGpEditor.ProblemInjector.CreateView();
     86      IView view = OffspringSelectionGP.ProblemInjector.CreateView();
    8587      if(view != null)
    8688        PluginManager.ControlManager.ShowControl(view);
     
    9092      if (chooseOperatorDialog == null) chooseOperatorDialog = new ChooseOperatorDialog();
    9193      if (chooseOperatorDialog.ShowDialog(this) == DialogResult.OK) {
    92         OffspringSelectionGpEditor.ProblemInjector = chooseOperatorDialog.Operator;
    93         problemInitializationTextBox.Text = OffspringSelectionGpEditor.ProblemInjector.GetType().Name;
     94        OffspringSelectionGP.ProblemInjector = chooseOperatorDialog.Operator;
     95        problemInitializationTextBox.Text = OffspringSelectionGP.ProblemInjector.GetType().Name;
    9496      }
    9597    }
     
    9799      executeButton.Enabled = false;
    98100      abortButton.Enabled = true;
    99       OffspringSelectionGpEditor.Engine.Execute();
     101      resetButton.Enabled = false;
     102      OffspringSelectionGP.Engine.Execute();
    100103    }
    101104    private void abortButton_Click(object sender, EventArgs e) {
    102       StandardGP.Engine.Abort();
     105      OffspringSelectionGP.Engine.Abort();
    103106    }
    104107    private void resetButton_Click(object sender, EventArgs e) {
    105       StandardGP.Engine.Reset();
     108      OffspringSelectionGP.Engine.Reset();
    106109    }
    107110    private void cloneEngineButton_Click(object sender, EventArgs e) {
    108       IEngine clone = (IEngine)StandardGP.Engine.Clone();
     111      IEngine clone = (IEngine)OffspringSelectionGP.Engine.Clone();
    109112      IEditor editor = ((IEditable)clone).CreateEditor();
    110113      PluginManager.ControlManager.ShowControl(editor);
     
    127130        executeButton.Enabled = true;
    128131        abortButton.Enabled = false;
     132        resetButton.Enabled = true;
    129133      }
    130134    }
    131135    #endregion
    132136
    133 
     137    private void setRandomSeedRandomlyCheckBox_CheckedChanged(object sender, EventArgs e) {
     138      randomSeedTextBox.Enabled = !setRandomSeedRandomlyCheckBox.Checked;
     139      randomSeedLabel.Enabled = !setRandomSeedRandomlyCheckBox.Checked;
     140    }
    134141  }
    135142}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/OffspringSelectionGP.cs

    r1156 r1287  
    3434using HeuristicLab.Data;
    3535using HeuristicLab.Operators.Programmable;
     36using HeuristicLab.Selection.OffspringSelection;
    3637
    3738namespace HeuristicLab.GP.StructureIdentification {
    38   public class OffspringSelectionGP : ItemBase, IEditable {
    39     private IntData maxGenerations = new IntData();
    40     public int MaxGenerations {
    41       get { return maxGenerations.Data; }
    42       set { maxGenerations.Data = value; }
    43     }
    44 
    45     private DoubleData mutationRate = new DoubleData();
    46     public double MutationRate {
    47       get { return mutationRate.Data; }
    48       set { mutationRate.Data = value; }
    49     }
    50 
    51     private IntData parents = new IntData();
    52     private IntData populationSize = new IntData();
    53     public int PopulationSize {
    54       get { return populationSize.Data; }
    55       set {
    56         populationSize.Data = value;
    57         parents.Data = value * 2;
    58       }
    59     }
    60 
    61     private BoolData setSeedRandomly = new BoolData();
    62     public bool SetSeedRandomly {
    63       get { return setSeedRandomly.Data; }
    64       set { setSeedRandomly.Data = value; }
    65     }
    66 
    67     private IntData seed = new IntData();
    68     public int Seed {
    69       get { return seed.Data; }
    70       set { seed.Data = value; }
    71     }
    72 
    73     public IOperator ProblemInjector {
    74       get { return algorithm.SubOperators[0]; }
    75       set {
    76         value.Name = "ProblemInjector";
    77         algorithm.RemoveSubOperator(0);
    78         algorithm.AddSubOperator(value, 0);
    79       }
    80     }
    81 
    82     private IntData elites = new IntData();
    83     public int Elites {
    84       get { return elites.Data; }
    85       set { elites.Data = value; }
    86     }
    87 
    88     private IntData maxTreeSize;
    89     public int MaxTreeSize {
    90       get { return maxTreeSize.Data; }
    91       set { maxTreeSize.Data = value; }
    92     }
    93 
    94     private IntData maxTreeHeight;
    95     public int MaxTreeHeight {
    96       get { return maxTreeHeight.Data; }
    97       set { maxTreeHeight.Data = value; }
    98     }
    99 
    100     private DoubleData maxSelectionPressure;
    101     public double MaxSelectionPressure {
    102       get { return maxSelectionPressure.Data; }
    103       set { maxSelectionPressure.Data = value; }
    104     }
    105 
    106     private double punishmentFactor = 10.0;
    107     private bool useEstimatedTargetValue = false;
    108     private double fullTreeShakingFactor = 0.1;
    109     private double onepointShakingFactor = 1.0;
    110     private IOperator algorithm;
    111 
    112     private SequentialEngine.SequentialEngine engine;
    113     public IEngine Engine {
    114       get { return engine; }
    115     }
    116 
    117     public OffspringSelectionGP() {
     39  public class OffspringSelectionGP : StandardGP {
     40
     41    public virtual int MaxEvaluatedSolutions {
     42      get { return GetVariableInjector().GetVariable("MaxEvaluatedSolutions").GetValue<IntData>().Data; }
     43      set { GetVariableInjector().GetVariable("MaxEvaluatedSolutions").GetValue<IntData>().Data = value; }
     44    }
     45
     46    public virtual double SelectionPressureLimit {
     47      get { return GetVariableInjector().GetVariable("SelectionPressureLimit").GetValue<DoubleData>().Data; }
     48      set { GetVariableInjector().GetVariable("SelectionPressureLimit").GetValue<DoubleData>().Data = value; }
     49    }
     50
     51    public virtual double ComparisonFactor {
     52      get { return GetVariableInjector().GetVariable("ComparisonFactor").GetValue<DoubleData>().Data; }
     53      set { GetVariableInjector().GetVariable("ComparisonFactor").GetValue<DoubleData>().Data = value; }
     54    }
     55
     56    public virtual double SuccessRatioLimit {
     57      get { return GetVariableInjector().GetVariable("SuccessRatioLimit").GetValue<DoubleData>().Data; }
     58      set { GetVariableInjector().GetVariable("SuccessRatioLimit").GetValue<DoubleData>().Data = value; }
     59    }
     60
     61    public override int MaxGenerations {
     62      get { throw new NotSupportedException(); }
     63      set { /* ignore */ }
     64    }
     65
     66    public override int TournamentSize {
     67      get { throw new NotSupportedException(); }
     68      set { /* ignore */ }
     69    }
     70
     71    public OffspringSelectionGP()
     72      : base() {
    11873      PopulationSize = 1000;
    119       MaxGenerations = 100;
    120       MutationRate = 0.15;
    121       Elites = 1;
    122       MaxSelectionPressure = 300;
    123       MaxTreeHeight = 10;
    124       MaxTreeSize = 100;
    125       engine = new SequentialEngine.SequentialEngine();
    126       CombinedOperator algo = CreateAlgorithm();
    127       engine.OperatorGraph.AddOperator(algo);
    128       engine.OperatorGraph.InitialOperator = algo;
    129     }
    130 
    131     private CombinedOperator CreateAlgorithm() {
    132       CombinedOperator algo = new CombinedOperator();
    133       algo.Name = "StandardGP";
    134       SequentialProcessor seq = new SequentialProcessor();
    135       EmptyOperator problemInjectorPlaceholder = new EmptyOperator();
    136       RandomInjector randomInjector = new RandomInjector();
    137       randomInjector.GetVariable("SetSeedRandomly").Value = setSeedRandomly;
    138       randomInjector.GetVariable("Seed").Value = seed;
    139       randomInjector.Name = "Random Injector";
    140       VariableInjector globalInjector = CreateGlobalInjector();
    141       CombinedOperator initialization = CreateInialization();
    142       initialization.Name = "Initialization";
    143       FunctionLibraryInjector funLibInjector = new FunctionLibraryInjector();
    144       CombinedOperator mainLoop = CreateMainLoop();
    145       mainLoop.Name = "Main loop";
    146 
    147       ProbabilisticTreeCreator treeCreator = new ProbabilisticTreeCreator();
    148       treeCreator.Name = "Tree generator";
    149       treeCreator.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    150       treeCreator.GetVariableInfo("MinTreeSize").Local = true;
    151       treeCreator.AddVariable(new HeuristicLab.Core.Variable("MinTreeSize", new IntData(3)));
    152       MeanSquaredErrorEvaluator evaluator = new MeanSquaredErrorEvaluator();
    153       evaluator.GetVariableInfo("MSE").ActualName = "Quality";
    154       evaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
    155       evaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
    156       evaluator.Name = "Evaluator";
    157       StandardCrossOver crossover = new StandardCrossOver();
    158       crossover.Name = "Crossover";
    159       crossover.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    160       CombinedOperator manipulator = CreateManipulator();
    161       manipulator.Name = "Manipulator";
    162       TournamentSelector selector = new TournamentSelector();
     74      Parents = 20;
     75      MaxEvaluatedSolutions = 1000000;
     76      SelectionPressureLimit = 300;
     77      ComparisonFactor = 1.0;
     78      SuccessRatioLimit = 1.0;
     79    }
     80
     81    protected internal override IOperator CreateGlobalInjector() {
     82      VariableInjector injector = (VariableInjector)base.CreateGlobalInjector();
     83      injector.RemoveVariable("TournamentSize");
     84      injector.RemoveVariable("MaxGenerations");
     85      injector.AddVariable(new HeuristicLab.Core.Variable("MaxEvaluatedSolutions", new IntData()));
     86      injector.AddVariable(new HeuristicLab.Core.Variable("ComparisonFactor", new DoubleData()));
     87      injector.AddVariable(new HeuristicLab.Core.Variable("SelectionPressureLimit", new DoubleData()));
     88      injector.AddVariable(new HeuristicLab.Core.Variable("SuccessRatioLimit", new DoubleData()));
     89      return injector;
     90    }
     91
     92    protected internal override IOperator CreateSelector() {
     93      CombinedOperator selector = new CombinedOperator();
    16394      selector.Name = "Selector";
    164       selector.GetVariableInfo("Selected").ActualName = "Parents";
    165       selector.GetVariableInfo("GroupSize").Local = false;
    166       selector.RemoveVariable("GroupSize");
    167       selector.GetVariableInfo("GroupSize").ActualName = "TournamentSize";
    168       LeftReducer cleanUp = new LeftReducer();
    169 
    170       seq.AddSubOperator(problemInjectorPlaceholder);
    171       seq.AddSubOperator(randomInjector);
    172       seq.AddSubOperator(globalInjector);
    173       seq.AddSubOperator(funLibInjector);
    174       seq.AddSubOperator(initialization);
    175       seq.AddSubOperator(mainLoop);
    176       seq.AddSubOperator(cleanUp);
    177 
    178       initialization.AddSubOperator(treeCreator);
    179       initialization.AddSubOperator(evaluator);
    180 
    181       mainLoop.AddSubOperator(selector);
    182       mainLoop.AddSubOperator(crossover);
    183       mainLoop.AddSubOperator(manipulator);
    184       mainLoop.AddSubOperator(evaluator);
    185       algo.OperatorGraph.AddOperator(seq);
    186       algo.OperatorGraph.InitialOperator = seq;
    187       this.algorithm = seq;
    188       return algo;
    189     }
    190 
    191     private VariableInjector CreateGlobalInjector() {
    192       VariableInjector injector = new VariableInjector();
    193       injector.Name = "Global Injector";
    194       injector.AddVariable(new HeuristicLab.Core.Variable("Generations", new IntData(0)));
    195       injector.AddVariable(new HeuristicLab.Core.Variable("MaxGenerations", maxGenerations));
    196       injector.AddVariable(new HeuristicLab.Core.Variable("MutationRate", mutationRate));
    197       injector.AddVariable(new HeuristicLab.Core.Variable("PopulationSize", populationSize));
    198       injector.AddVariable(new HeuristicLab.Core.Variable("Parents", parents));
    199       injector.AddVariable(new HeuristicLab.Core.Variable("Elites", elites));
    200       injector.AddVariable(new HeuristicLab.Core.Variable("Maximization", new BoolData(false)));
    201       injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeHeight", maxTreeHeight));
    202       injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeSize", maxTreeSize));
    203       injector.AddVariable(new HeuristicLab.Core.Variable("EvaluatedSolutions", new IntData(0)));
    204       injector.AddVariable(new HeuristicLab.Core.Variable("TotalEvaluatedNodes", new DoubleData(0)));
    205       injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(punishmentFactor)));
    206       injector.AddVariable(new HeuristicLab.Core.Variable("UseEstimatedTargetValue", new BoolData(useEstimatedTargetValue)));
    207       return injector;
    208     }
    209 
    210     private CombinedOperator CreateManipulator() {
    211       CombinedOperator manipulator = new CombinedOperator();
    212       StochasticMultiBranch multibranch = new StochasticMultiBranch();
    213       FullTreeShaker fullTreeShaker = new FullTreeShaker();
    214       fullTreeShaker.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    215       fullTreeShaker.GetVariableInfo("ShakingFactor").Local = true;
    216       fullTreeShaker.AddVariable(new HeuristicLab.Core.Variable("ShakingFactor", new DoubleData(fullTreeShakingFactor)));
    217 
    218       OnePointShaker onepointShaker = new OnePointShaker();
    219       onepointShaker.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    220       onepointShaker.GetVariableInfo("ShakingFactor").Local = true;
    221       onepointShaker.AddVariable(new HeuristicLab.Core.Variable("ShakingFactor", new DoubleData(onepointShakingFactor)));
    222       ChangeNodeTypeManipulation changeNodeTypeManipulation = new ChangeNodeTypeManipulation();
    223       changeNodeTypeManipulation.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    224       CutOutNodeManipulation cutOutNodeManipulation = new CutOutNodeManipulation();
    225       cutOutNodeManipulation.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    226       DeleteSubTreeManipulation deleteSubTreeManipulation = new DeleteSubTreeManipulation();
    227       deleteSubTreeManipulation.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    228       SubstituteSubTreeManipulation substituteSubTreeManipulation = new SubstituteSubTreeManipulation();
    229       substituteSubTreeManipulation.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    230 
    231       IOperator[] manipulators = new IOperator[] {
    232         onepointShaker, fullTreeShaker,
    233         changeNodeTypeManipulation,
    234         cutOutNodeManipulation,
    235         deleteSubTreeManipulation,
    236         substituteSubTreeManipulation};
    237 
    238       DoubleArrayData probabilities = new DoubleArrayData(new double[manipulators.Length]);
    239       for (int i = 0; i < manipulators.Length; i++) {
    240         probabilities.Data[i] = 1.0;
    241         multibranch.AddSubOperator(manipulators[i]);
    242       }
    243       multibranch.GetVariableInfo("Probabilities").Local = true;
    244       multibranch.AddVariable(new HeuristicLab.Core.Variable("Probabilities", probabilities));
    245 
    246       manipulator.OperatorGraph.AddOperator(multibranch);
    247       manipulator.OperatorGraph.InitialOperator = multibranch;
    248       return manipulator;
    249     }
    250 
    251     private CombinedOperator CreateInialization() {
    252       CombinedOperator init = new CombinedOperator();
    253       SequentialProcessor seq = new SequentialProcessor();
    254       SubScopesCreater subScopesCreater = new SubScopesCreater();
    255       subScopesCreater.GetVariableInfo("SubScopes").ActualName = "PopulationSize";
    256       UniformSequentialSubScopesProcessor subScopesProc = new UniformSequentialSubScopesProcessor();
    257       SequentialProcessor individualSeq = new SequentialProcessor();
    258       OperatorExtractor treeCreater = new OperatorExtractor();
    259       treeCreater.Name = "Tree generator (extr.)";
    260       treeCreater.GetVariableInfo("Operator").ActualName = "Tree generator";
    261       OperatorExtractor evaluator = new OperatorExtractor();
    262       evaluator.Name = "Evaluator (extr.)";
    263       evaluator.GetVariableInfo("Operator").ActualName = "Evaluator";
    264       MeanSquaredErrorEvaluator validationEvaluator = new MeanSquaredErrorEvaluator();
    265       validationEvaluator.GetVariableInfo("MSE").ActualName = "ValidationQuality";
    266       validationEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    267       validationEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    268       Counter evalCounter = new Counter();
    269       evalCounter.GetVariableInfo("Value").ActualName = "EvaluatedSolutions";
    270 
    271       seq.AddSubOperator(subScopesCreater);
    272       seq.AddSubOperator(subScopesProc);
    273       subScopesProc.AddSubOperator(individualSeq);
    274       individualSeq.AddSubOperator(treeCreater);
    275       individualSeq.AddSubOperator(evaluator);
    276       individualSeq.AddSubOperator(validationEvaluator);
    277       individualSeq.AddSubOperator(evalCounter);
    278 
    279       init.OperatorGraph.AddOperator(seq);
    280       init.OperatorGraph.InitialOperator = seq;
    281       return init;
    282     }
    283 
    284     private CombinedOperator CreateMainLoop() {
    285       CombinedOperator main = new CombinedOperator();
    286       SequentialProcessor seq = new SequentialProcessor();
    287       CombinedOperator childCreater = CreateChildCreater();
     95      SequentialProcessor seq = new SequentialProcessor();
     96      seq.Name = "Selector";
     97      EmptyOperator emptyOp = new EmptyOperator();
     98      ProportionalSelector femaleSelector = new ProportionalSelector();
     99      femaleSelector.GetVariableInfo("Selected").ActualName = "Parents";
     100      femaleSelector.GetVariableValue<BoolData>("CopySelected", null, false).Data = true;
     101
     102      RandomSelector maleSelector = new RandomSelector();
     103      maleSelector.GetVariableInfo("Selected").ActualName = "Parents";
     104      maleSelector.GetVariableValue<BoolData>("CopySelected", null, false).Data = true;
     105      SequentialSubScopesProcessor seqSubScopesProc = new SequentialSubScopesProcessor();
     106      RightChildReducer rightChildReducer = new RightChildReducer();
     107      SubScopesMixer mixer = new SubScopesMixer();
     108
     109      seqSubScopesProc.AddSubOperator(femaleSelector);
     110      seqSubScopesProc.AddSubOperator(emptyOp);
     111
     112      seq.AddSubOperator(maleSelector);
     113      seq.AddSubOperator(seqSubScopesProc);
     114      seq.AddSubOperator(rightChildReducer);
     115      seq.AddSubOperator(mixer);
     116
     117      selector.OperatorGraph.AddOperator(seq);
     118      selector.OperatorGraph.InitialOperator = seq;
     119      return selector;
     120    }
     121
     122    protected internal override IOperator CreateChildCreater() {
     123      CombinedOperator childCreater = new CombinedOperator();
    288124      childCreater.Name = "Create children";
    289       CombinedOperator replacement = CreateReplacement();
    290       replacement.Name = "Replacement";
    291       BestSolutionStorer solutionStorer = CreateBestSolutionStorer();
    292       BestAverageWorstQualityCalculator qualityCalculator = new BestAverageWorstQualityCalculator();
    293       BestAverageWorstQualityCalculator validationQualityCalculator = new BestAverageWorstQualityCalculator();
    294       validationQualityCalculator.Name = "ValidationQualityCalculator";
    295       validationQualityCalculator.GetVariableInfo("BestQuality").ActualName = "BestValidationQuality";
    296       validationQualityCalculator.GetVariableInfo("AverageQuality").ActualName = "AverageValidationQuality";
    297       validationQualityCalculator.GetVariableInfo("WorstQuality").ActualName = "WorstValidationQuality";
    298       DataCollector collector = new DataCollector();
    299       ItemList<StringData> names = collector.GetVariable("VariableNames").GetValue<ItemList<StringData>>();
    300       names.Add(new StringData("BestQuality"));
    301       names.Add(new StringData("AverageQuality"));
    302       names.Add(new StringData("WorstQuality"));
    303       names.Add(new StringData("BestValidationQuality"));
    304       names.Add(new StringData("AverageValidationQuality"));
    305       names.Add(new StringData("WorstValidationQuality"));
    306       LinechartInjector lineChartInjector = new LinechartInjector();
    307       lineChartInjector.GetVariableInfo("Linechart").ActualName = "Quality Linechart";
    308       lineChartInjector.GetVariable("NumberOfLines").GetValue<IntData>().Data = 6;
    309       QualityLogger qualityLogger = new QualityLogger();
    310       QualityLogger validationQualityLogger = new QualityLogger();
    311       validationQualityCalculator.Name = "ValidationQualityLogger";
    312       validationQualityLogger.GetVariableInfo("Quality").ActualName = "ValidationQuality";
    313       validationQualityLogger.GetVariableInfo("QualityLog").ActualName = "ValidationQualityLog";
    314       Counter counter = new Counter();
    315       counter.GetVariableInfo("Value").ActualName = "Generations";
    316       LessThanComparator comparator = new LessThanComparator();
    317       comparator.GetVariableInfo("LeftSide").ActualName = "Generations";
    318       comparator.GetVariableInfo("RightSide").ActualName = "MaxGenerations";
    319       comparator.GetVariableInfo("Result").ActualName = "GenerationsCondition";
    320       ConditionalBranch cond = new ConditionalBranch();
    321       cond.GetVariableInfo("Condition").ActualName = "GenerationsCondition";
    322 
    323       seq.AddSubOperator(childCreater);
    324       seq.AddSubOperator(replacement);
    325       seq.AddSubOperator(solutionStorer);
    326       seq.AddSubOperator(qualityCalculator);
    327       seq.AddSubOperator(validationQualityCalculator);
    328       seq.AddSubOperator(collector);
    329       seq.AddSubOperator(lineChartInjector);
    330       seq.AddSubOperator(qualityLogger);
    331       seq.AddSubOperator(validationQualityLogger);
    332       seq.AddSubOperator(counter);
    333       seq.AddSubOperator(comparator);
    334       seq.AddSubOperator(cond);
    335       cond.AddSubOperator(seq);
    336 
    337       main.OperatorGraph.AddOperator(seq);
    338       main.OperatorGraph.InitialOperator = seq;
    339       return main;
    340     }
    341 
    342     private BestSolutionStorer CreateBestSolutionStorer() {
    343       BestSolutionStorer solutionStorer = new BestSolutionStorer();
    344       solutionStorer.GetVariableInfo("Quality").ActualName = "ValidationQuality";
    345       solutionStorer.GetVariableInfo("BestSolution").ActualName = "BestValidationSolution";
    346       SequentialProcessor bestSolutionProcessor = new SequentialProcessor();
    347       MeanAbsolutePercentageErrorEvaluator trainingMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator();
    348       trainingMapeEvaluator.Name = "ValidationMapeEvaluator";
    349       trainingMapeEvaluator.GetVariableInfo("MAPE").ActualName = "TrainingMAPE";
    350       trainingMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
    351       trainingMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
    352       MeanAbsolutePercentageErrorEvaluator validationMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator();
    353       validationMapeEvaluator.Name = "ValidationMapeEvaluator";
    354       validationMapeEvaluator.GetVariableInfo("MAPE").ActualName = "ValidationMAPE";
    355       validationMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    356       validationMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    357       ProgrammableOperator progOperator = new ProgrammableOperator();
    358       progOperator.RemoveVariableInfo("Result");
    359       progOperator.AddVariableInfo(new HeuristicLab.Core.VariableInfo("EvaluatedSolutions", "", typeof(IntData), VariableKind.In));
    360       progOperator.Code = @"
    361 int evalSolutions = EvaluatedSolutions.Data;
    362 scope.AddVariable(new Variable(""EvaluatedSolutions"", new IntData(evalSolutions)));
    363 ";
    364       solutionStorer.AddSubOperator(bestSolutionProcessor);
    365       bestSolutionProcessor.AddSubOperator(trainingMapeEvaluator);
    366       bestSolutionProcessor.AddSubOperator(validationMapeEvaluator);
    367       bestSolutionProcessor.AddSubOperator(progOperator);
    368       return solutionStorer;
    369     }
    370 
    371     private CombinedOperator CreateReplacement() {
    372       CombinedOperator replacement = new CombinedOperator();
    373       SequentialProcessor seq = new SequentialProcessor();
    374       SequentialSubScopesProcessor seqScopeProc = new SequentialSubScopesProcessor();
    375       SequentialProcessor selectedProc = new SequentialProcessor();
    376       LeftSelector leftSelector = new LeftSelector();
    377       leftSelector.GetVariableInfo("Selected").ActualName = "Elites";
    378       RightReducer rightReducer = new RightReducer();
    379 
    380       SequentialProcessor remainingProc = new SequentialProcessor();
    381       RightSelector rightSelector = new RightSelector();
    382       rightSelector.GetVariableInfo("Selected").ActualName = "Elites";
    383       LeftReducer leftReducer = new LeftReducer();
    384       MergingReducer mergingReducer = new MergingReducer();
    385       Sorter sorter = new Sorter();
    386       sorter.GetVariableInfo("Descending").ActualName = "Maximization";
    387       sorter.GetVariableInfo("Value").ActualName = "Quality";
    388 
    389       seq.AddSubOperator(seqScopeProc);
    390       seqScopeProc.AddSubOperator(selectedProc);
    391       selectedProc.AddSubOperator(leftSelector);
    392       selectedProc.AddSubOperator(rightReducer);
    393 
    394       seqScopeProc.AddSubOperator(remainingProc);
    395       remainingProc.AddSubOperator(rightSelector);
    396       remainingProc.AddSubOperator(leftReducer);
    397       seq.AddSubOperator(mergingReducer);
    398       seq.AddSubOperator(sorter);
    399       replacement.OperatorGraph.AddOperator(seq);
    400       replacement.OperatorGraph.InitialOperator = seq;
    401       return replacement;
    402     }
    403 
    404     private CombinedOperator CreateChildCreater() {
    405       CombinedOperator childCreater = new CombinedOperator();
    406       SequentialProcessor seq = new SequentialProcessor();
     125      SequentialProcessor seq = new SequentialProcessor();
     126      SequentialProcessor offspringSelectionSeq = new SequentialProcessor();
    407127      OperatorExtractor selector = new OperatorExtractor();
    408128      selector.Name = "Selector (extr.)";
    409129      selector.GetVariableInfo("Operator").ActualName = "Selector";
    410       SequentialSubScopesProcessor seqScopesProc = new SequentialSubScopesProcessor();
    411       EmptyOperator emptyOpt = new EmptyOperator();
     130      SequentialSubScopesProcessor seqSubScopesProc = new SequentialSubScopesProcessor();
     131      EmptyOperator emptyOp = new EmptyOperator();
     132      OffspringSelector offspringSelector = new OffspringSelector();
     133      OffspringAnalyzer offspringAnalyzer = new OffspringAnalyzer();
    412134      SequentialProcessor selectedProc = new SequentialProcessor();
    413135      OperatorExtractor crossover = new OperatorExtractor();
     
    424146      evaluator.Name = "Evaluator (extr.)";
    425147      evaluator.GetVariableInfo("Operator").ActualName = "Evaluator";
    426       MeanSquaredErrorEvaluator validationEvaluator = new MeanSquaredErrorEvaluator();
    427       validationEvaluator.GetVariableInfo("MSE").ActualName = "ValidationQuality";
    428       validationEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    429       validationEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    430148      Counter evalCounter = new Counter();
    431149      evalCounter.GetVariableInfo("Value").ActualName = "EvaluatedSolutions";
     
    435153      sorter.GetVariableInfo("Value").ActualName = "Quality";
    436154
    437 
    438       seq.AddSubOperator(selector);
    439       seq.AddSubOperator(seqScopesProc);
    440       seqScopesProc.AddSubOperator(emptyOpt);
    441       seqScopesProc.AddSubOperator(selectedProc);
     155      UniformSequentialSubScopesProcessor validationEvaluator = new UniformSequentialSubScopesProcessor();
     156      MeanSquaredErrorEvaluator validationQualityEvaluator = new MeanSquaredErrorEvaluator();
     157      validationQualityEvaluator.Name = "ValidationMeanSquaredErrorEvaluator";
     158      validationQualityEvaluator.GetVariableInfo("MSE").ActualName = "ValidationQuality";
     159      validationQualityEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
     160      validationQualityEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
     161
     162      seqSubScopesProc.AddSubOperator(emptyOp);
     163      seqSubScopesProc.AddSubOperator(offspringAnalyzer);
     164
     165      seq.AddSubOperator(offspringSelectionSeq);
     166      offspringSelectionSeq.AddSubOperator(selector);
     167      offspringSelectionSeq.AddSubOperator(seqSubScopesProc);
     168      offspringSelectionSeq.AddSubOperator(offspringSelector);
     169      offspringSelector.AddSubOperator(offspringSelectionSeq);
     170
     171      offspringAnalyzer.AddSubOperator(selectedProc);
    442172      selectedProc.AddSubOperator(crossover);
    443173      selectedProc.AddSubOperator(individualProc);
     
    446176      cond.AddSubOperator(manipulator);
    447177      individualSeqProc.AddSubOperator(evaluator);
    448       individualSeqProc.AddSubOperator(validationEvaluator);
    449178      individualSeqProc.AddSubOperator(evalCounter);
    450       selectedProc.AddSubOperator(sorter);
     179
     180      SequentialSubScopesProcessor seqSubScopesProc2 = new SequentialSubScopesProcessor();
     181      seq.AddSubOperator(seqSubScopesProc2);
     182      seqSubScopesProc2.AddSubOperator(emptyOp);
     183
     184      SequentialProcessor newGenProc = new SequentialProcessor();
     185      newGenProc.AddSubOperator(sorter);
     186      newGenProc.AddSubOperator(validationEvaluator);
     187      seqSubScopesProc2.AddSubOperator(newGenProc);
     188
     189      validationEvaluator.AddSubOperator(validationQualityEvaluator);
    451190
    452191      childCreater.OperatorGraph.AddOperator(seq);
     
    455194    }
    456195
    457     public IEditor CreateEditor() {
    458       return new OffSpringSelectionGpEditor(this);
     196    protected internal override IOperator CreateLoopCondition(IOperator loop) {
     197      SequentialProcessor seq = new SequentialProcessor();
     198      seq.Name = "Loop Condition";
     199      LessThanComparator generationsComparator = new LessThanComparator();
     200      generationsComparator.GetVariableInfo("LeftSide").ActualName = "EvaluatedSolutions";
     201      generationsComparator.GetVariableInfo("RightSide").ActualName = "MaxEvaluatedSolutions";
     202      generationsComparator.GetVariableInfo("Result").ActualName = "EvaluatedSolutionsCondition";
     203
     204      LessThanComparator selPresComparator = new LessThanComparator();
     205      selPresComparator.GetVariableInfo("LeftSide").ActualName = "SelectionPressure";
     206      selPresComparator.GetVariableInfo("RightSide").ActualName = "SelectionPressureLimit";
     207      selPresComparator.GetVariableInfo("Result").ActualName = "SelectionPressureCondition";
     208
     209      ConditionalBranch generationsCond = new ConditionalBranch();
     210      generationsCond.GetVariableInfo("Condition").ActualName = "EvaluatedSolutionsCondition";
     211
     212      ConditionalBranch selPresCond = new ConditionalBranch();
     213      selPresCond.GetVariableInfo("Condition").ActualName = "SelectionPressureCondition";
     214
     215      seq.AddSubOperator(generationsComparator);
     216      seq.AddSubOperator(selPresComparator);
     217      seq.AddSubOperator(generationsCond);
     218      generationsCond.AddSubOperator(selPresCond);
     219      selPresCond.AddSubOperator(loop);
     220
     221      return seq;
     222    }
     223
     224    protected internal override IOperator CreateLoggingOperator() {
     225      CombinedOperator loggingOperator = new CombinedOperator();
     226      loggingOperator.Name = "Logging";
     227      SequentialProcessor seq = new SequentialProcessor();
     228
     229      DataCollector collector = new DataCollector();
     230      ItemList<StringData> names = collector.GetVariable("VariableNames").GetValue<ItemList<StringData>>();
     231      names.Add(new StringData("BestQuality"));
     232      names.Add(new StringData("AverageQuality"));
     233      names.Add(new StringData("WorstQuality"));
     234      names.Add(new StringData("BestValidationQuality"));
     235      names.Add(new StringData("AverageValidationQuality"));
     236      names.Add(new StringData("WorstValidationQuality"));
     237      names.Add(new StringData("EvaluatedSolutions"));
     238      names.Add(new StringData("SelectionPressure"));
     239      QualityLogger qualityLogger = new QualityLogger();
     240      QualityLogger validationQualityLogger = new QualityLogger();
     241      validationQualityLogger.Name = "ValidationQualityLogger";
     242      validationQualityLogger.GetVariableInfo("Quality").ActualName = "ValidationQuality";
     243      validationQualityLogger.GetVariableInfo("QualityLog").ActualName = "ValidationQualityLog";
     244
     245      seq.AddSubOperator(collector);
     246      seq.AddSubOperator(qualityLogger);
     247      seq.AddSubOperator(validationQualityLogger);
     248
     249      loggingOperator.OperatorGraph.AddOperator(seq);
     250      loggingOperator.OperatorGraph.InitialOperator = seq;
     251      return loggingOperator;
     252    }
     253
     254
     255    public override IEditor CreateEditor() {
     256      return new OffspringSelectionGpEditor(this);
    459257    }
    460258
     
    464262
    465263    public override object Clone(IDictionary<Guid, object> clonedObjects) {
    466       OffspringSelectionGP clone = new OffspringSelectionGP();
    467       clonedObjects.Add(Guid, clone);
    468       clone.engine = (SequentialEngine.SequentialEngine)Auxiliary.Clone(Engine, clonedObjects);
     264      OffspringSelectionGP clone = (OffspringSelectionGP)base.Clone(clonedObjects);
     265      clone.SelectionPressureLimit = SelectionPressureLimit;
     266      clone.SuccessRatioLimit = SuccessRatioLimit;
     267      clone.ComparisonFactor = ComparisonFactor;
    469268      return clone;
    470269    }
    471     #region SetReferences Method
    472     private void SetReferences() {
    473       // SGA
    474       CombinedOperator co1 = (CombinedOperator)Engine.OperatorGraph.InitialOperator;
    475       // SequentialProcessor in SGA
    476       algorithm = (SequentialProcessor)co1.OperatorGraph.InitialOperator;
    477       // RandomInjector
    478       RandomInjector ri = (RandomInjector)algorithm.SubOperators[1];
    479       setSeedRandomly = ri.GetVariable("SetSeedRandomly").GetValue<BoolData>();
    480       seed = ri.GetVariable("Seed").GetValue<IntData>();
    481       // VariableInjector
    482       VariableInjector vi = (VariableInjector)algorithm.SubOperators[2];
    483       populationSize = vi.GetVariable("PopulationSize").GetValue<IntData>();
    484       parents = vi.GetVariable("Parents").GetValue<IntData>();
    485       maxGenerations = vi.GetVariable("MaxGenerations").GetValue<IntData>();
    486       mutationRate = vi.GetVariable("MutationRate").GetValue<DoubleData>();
    487       elites = vi.GetVariable("Elites").GetValue<IntData>();
    488       maxTreeSize = vi.GetVariable("MaxTreeSize").GetValue<IntData>();
    489       maxTreeHeight = vi.GetVariable("MaxTreeHeight").GetValue<IntData>();
    490     }
    491     #endregion
    492 
    493     #region Persistence Methods
    494     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    495       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    496       node.AppendChild(PersistenceManager.Persist("Engine", Engine, document, persistedObjects));
    497       return node;
    498     }
    499     public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    500       base.Populate(node, restoredObjects);
    501       engine = (SequentialEngine.SequentialEngine)PersistenceManager.Restore(node.SelectSingleNode("Engine"), restoredObjects);
    502       SetReferences();
    503     }
    504     #endregion
    505270  }
    506271}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/StandardGP.cs

    r1053 r1287  
    3636
    3737namespace HeuristicLab.GP.StructureIdentification {
    38   public class StandardGP : ItemBase, IEditable {
    39     private IntData maxGenerations = new IntData();
    40     public int MaxGenerations {
    41       get { return maxGenerations.Data; }
    42       set { maxGenerations.Data = value; }
    43     }
    44 
    45     private IntData tournamentSize = new IntData();
    46     public int TournamentSize {
    47       get { return tournamentSize.Data; }
    48       set { tournamentSize.Data = value; }
    49     }
    50     private DoubleData mutationRate = new DoubleData();
    51     public double MutationRate {
    52       get { return mutationRate.Data; }
    53       set { mutationRate.Data = value; }
    54     }
    55     private IntData parents = new IntData();
    56     private IntData populationSize = new IntData();
    57     public int PopulationSize {
    58       get { return populationSize.Data; }
     38  public class StandardGP : AlgorithmBase, IEditable {
     39
     40    public virtual int MaxGenerations {
     41      get { return GetVariableInjector().GetVariable("MaxGenerations").GetValue<IntData>().Data; }
     42      set { GetVariableInjector().GetVariable("MaxGenerations").GetValue<IntData>().Data = value; }
     43    }
     44
     45    public virtual int TournamentSize {
     46      get { return GetVariableInjector().GetVariable("TournamentSize").GetValue<IntData>().Data; }
     47      set { GetVariableInjector().GetVariable("TournamentSize").GetValue<IntData>().Data = value; }
     48    }
     49
     50    public double FullTreeShakingFactor {
     51      get { return GetVariableInjector().GetVariable("FullTreeShakingFactor").GetValue<DoubleData>().Data; }
     52      set { GetVariableInjector().GetVariable("FullTreeShakingFactor").GetValue<DoubleData>().Data = value; }
     53    }
     54
     55    public double OnePointShakingFactor {
     56      get { return GetVariableInjector().GetVariable("OnePointShakingFactor").GetValue<DoubleData>().Data; }
     57      set { GetVariableInjector().GetVariable("OnePointShakingFactor").GetValue<DoubleData>().Data = value; }
     58    }
     59
     60    public int MinInitialTreeSize {
     61      get { return GetVariableInjector().GetVariable("MinInitialTreeSize").GetValue<IntData>().Data; }
     62      set { GetVariableInjector().GetVariable("MinInitialTreeSize").GetValue<IntData>().Data = value; }
     63    }
     64
     65    public override int MaxTreeSize {
     66      get {
     67        return base.MaxTreeSize;
     68      }
    5969      set {
    60         populationSize.Data = value;
    61         parents.Data = value * 2;
    62       }
    63     }
    64 
    65     private BoolData setSeedRandomly = new BoolData();
    66     public bool SetSeedRandomly {
    67       get { return setSeedRandomly.Data; }
    68       set { setSeedRandomly.Data = value; }
    69     }
    70 
    71     private IntData seed = new IntData();
    72     public int Seed {
    73       get { return seed.Data; }
    74       set { seed.Data = value; }
    75     }
    76 
    77     public IOperator ProblemInjector {
    78       get { return algorithm.SubOperators[0]; }
     70        base.MaxTreeSize = value;
     71        MinInitialTreeSize = value / 2;
     72      }
     73    }
     74
     75    public override int PopulationSize {
     76      get {
     77        return base.PopulationSize;
     78      }
    7979      set {
    80         value.Name = "ProblemInjector";
    81         algorithm.RemoveSubOperator(0);
    82         algorithm.AddSubOperator(value, 0);
    83       }
    84     }
    85 
    86     private IntData elites = new IntData();
    87     public int Elites {
    88       get { return elites.Data; }
    89       set { elites.Data = value; }
    90     }
    91 
    92     private int maxTreeSize = 50;
    93     private int maxTreeHeight = 8;
    94     private double punishmentFactor = 10.0;
    95     private bool useEstimatedTargetValue = false;
    96     private double fullTreeShakingFactor = 0.1;
    97     private double onepointShakingFactor = 1.0;
    98     private IOperator algorithm;
    99     private SequentialEngine.SequentialEngine engine;
    100 
    101     public IEngine Engine {
    102       get { return engine; }
    103     }
    104 
    105     public StandardGP() {
    106       PopulationSize = 100;
     80        base.PopulationSize = value;
     81        Parents = 2 * value;
     82      }
     83    }
     84
     85    public StandardGP()
     86      : base() {
     87      PopulationSize = 10000;
    10788      MaxGenerations = 100;
    10889      TournamentSize = 7;
    10990      MutationRate = 0.15;
    11091      Elites = 1;
    111       engine = new SequentialEngine.SequentialEngine();
    112       CombinedOperator algo = CreateAlgorithm();
    113       engine.OperatorGraph.AddOperator(algo);
    114       engine.OperatorGraph.InitialOperator = algo;
    115     }
    116 
    117     private CombinedOperator CreateAlgorithm() {
    118       CombinedOperator algo = new CombinedOperator();
    119       algo.Name = "StandardGP";
    120       SequentialProcessor seq = new SequentialProcessor();
    121       EmptyOperator problemInjectorPlaceholder = new EmptyOperator();
    122       RandomInjector randomInjector = new RandomInjector();
    123       randomInjector.GetVariable("SetSeedRandomly").Value = setSeedRandomly;
    124       randomInjector.GetVariable("Seed").Value = seed;
    125       randomInjector.Name = "Random Injector";
    126       VariableInjector globalInjector = CreateGlobalInjector();
    127       CombinedOperator initialization = CreateInialization();
    128       initialization.Name = "Initialization";
    129       FunctionLibraryInjector funLibInjector = new FunctionLibraryInjector();
    130       CombinedOperator mainLoop = CreateMainLoop();
    131       mainLoop.Name = "Main loop";
    132 
    133       ProbabilisticTreeCreator treeCreator = new ProbabilisticTreeCreator();
    134       treeCreator.Name = "Tree generator";
    135       treeCreator.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    136       treeCreator.GetVariableInfo("MinTreeSize").Local = true;
    137       treeCreator.AddVariable(new HeuristicLab.Core.Variable("MinTreeSize", new IntData(3)));
    138       MeanSquaredErrorEvaluator evaluator = new MeanSquaredErrorEvaluator();
    139       evaluator.GetVariableInfo("MSE").ActualName = "Quality";
    140       evaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
    141       evaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
    142       evaluator.Name = "Evaluator";
    143       StandardCrossOver crossover = new StandardCrossOver();
    144       crossover.Name = "Crossover";
    145       crossover.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    146       CombinedOperator manipulator = CreateManipulator();
    147       manipulator.Name = "Manipulator";
     92      MaxTreeSize = 100;
     93      MaxTreeHeight = 10;
     94      FullTreeShakingFactor = 0.1;
     95      OnePointShakingFactor = 1.0;
     96      PunishmentFactor = 10.0;
     97      UseEstimatedTargetValue = false;
     98      SetSeedRandomly = true;
     99    }
     100
     101    protected internal override IOperator CreateProblemInjector() {
     102      return new ProblemInjector();
     103    }
     104
     105    protected internal override IOperator CreateSelector() {
    148106      TournamentSelector selector = new TournamentSelector();
    149107      selector.Name = "Selector";
     
    152110      selector.RemoveVariable("GroupSize");
    153111      selector.GetVariableInfo("GroupSize").ActualName = "TournamentSize";
    154 
    155       seq.AddSubOperator(problemInjectorPlaceholder);
    156       seq.AddSubOperator(randomInjector);
    157       seq.AddSubOperator(globalInjector);
    158       seq.AddSubOperator(funLibInjector);
    159       seq.AddSubOperator(initialization);
    160       seq.AddSubOperator(mainLoop);
    161 
    162       initialization.AddSubOperator(treeCreator);
    163       initialization.AddSubOperator(evaluator);
    164 
    165       mainLoop.AddSubOperator(selector);
    166       mainLoop.AddSubOperator(crossover);
    167       mainLoop.AddSubOperator(manipulator);
    168       mainLoop.AddSubOperator(evaluator);
    169       algo.OperatorGraph.AddOperator(seq);
    170       algo.OperatorGraph.InitialOperator = seq;
    171       this.algorithm = seq;
    172       return algo;
    173     }
    174 
    175     private VariableInjector CreateGlobalInjector() {
    176       VariableInjector injector = new VariableInjector();
    177       injector.Name = "Global Injector";
    178       injector.AddVariable(new HeuristicLab.Core.Variable("Generations", new IntData(0)));
    179       injector.AddVariable(new HeuristicLab.Core.Variable("MaxGenerations", maxGenerations));
    180       injector.AddVariable(new HeuristicLab.Core.Variable("MutationRate", mutationRate));
    181       injector.AddVariable(new HeuristicLab.Core.Variable("PopulationSize", populationSize));
    182       injector.AddVariable(new HeuristicLab.Core.Variable("Parents", parents));
    183       injector.AddVariable(new HeuristicLab.Core.Variable("Elites", elites));
    184       injector.AddVariable(new HeuristicLab.Core.Variable("TournamentSize", tournamentSize));
    185       injector.AddVariable(new HeuristicLab.Core.Variable("Maximization", new BoolData(false)));
    186       injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeHeight", new IntData(maxTreeHeight)));
    187       injector.AddVariable(new HeuristicLab.Core.Variable("MaxTreeSize", new IntData(maxTreeSize)));
    188       injector.AddVariable(new HeuristicLab.Core.Variable("EvaluatedSolutions", new IntData(0)));
    189       injector.AddVariable(new HeuristicLab.Core.Variable("TotalEvaluatedNodes", new DoubleData(0)));
    190       injector.AddVariable(new HeuristicLab.Core.Variable("PunishmentFactor", new DoubleData(punishmentFactor)));
    191       injector.AddVariable(new HeuristicLab.Core.Variable("UseEstimatedTargetValue", new BoolData(useEstimatedTargetValue)));
    192       return injector;
    193     }
    194 
    195     private CombinedOperator CreateManipulator() {
     112      return selector;
     113    }
     114
     115    protected internal override IOperator CreateGlobalInjector() {
     116      VariableInjector globalInjector = (VariableInjector)base.CreateGlobalInjector();
     117      globalInjector.AddVariable(new HeuristicLab.Core.Variable("TournamentSize", new IntData()));
     118      globalInjector.AddVariable(new HeuristicLab.Core.Variable("MaxGenerations", new IntData()));
     119      globalInjector.AddVariable(new HeuristicLab.Core.Variable("FullTreeShakingFactor", new DoubleData()));
     120      globalInjector.AddVariable(new HeuristicLab.Core.Variable("OnePointShakingFactor", new DoubleData()));
     121      globalInjector.AddVariable(new HeuristicLab.Core.Variable("MinInitialTreeSize", new IntData()));
     122      return globalInjector;
     123    }
     124
     125    protected internal override IOperator CreateCrossover() {
     126      StandardCrossOver crossover = new StandardCrossOver();
     127      crossover.Name = "Crossover";
     128      crossover.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
     129      return crossover;
     130    }
     131
     132    protected internal override IOperator CreateTreeCreator() {
     133      ProbabilisticTreeCreator treeCreator = new ProbabilisticTreeCreator();
     134      treeCreator.Name = "Tree generator";
     135      treeCreator.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
     136      treeCreator.GetVariableInfo("MinTreeSize").ActualName = "MinInitialTreeSize";
     137      return treeCreator;
     138    }
     139
     140    protected internal override IOperator CreateFunctionLibraryInjector() {
     141      return new FunctionLibraryInjector();
     142    }
     143
     144    protected internal override IOperator CreateManipulator() {
    196145      CombinedOperator manipulator = new CombinedOperator();
     146      manipulator.Name = "Manipulator";
    197147      StochasticMultiBranch multibranch = new StochasticMultiBranch();
    198148      FullTreeShaker fullTreeShaker = new FullTreeShaker();
    199149      fullTreeShaker.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    200       fullTreeShaker.GetVariableInfo("ShakingFactor").Local = true;
    201       fullTreeShaker.AddVariable(new HeuristicLab.Core.Variable("ShakingFactor", new DoubleData(fullTreeShakingFactor)));
     150      fullTreeShaker.GetVariableInfo("ShakingFactor").ActualName = "FullTreeShakingFactor";
    202151
    203152      OnePointShaker onepointShaker = new OnePointShaker();
    204153      onepointShaker.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
    205       onepointShaker.GetVariableInfo("ShakingFactor").Local = true;
    206       onepointShaker.AddVariable(new HeuristicLab.Core.Variable("ShakingFactor", new DoubleData(onepointShakingFactor)));
     154      onepointShaker.GetVariableInfo("ShakingFactor").ActualName = "OnePointShakingFactor";
    207155      ChangeNodeTypeManipulation changeNodeTypeManipulation = new ChangeNodeTypeManipulation();
    208156      changeNodeTypeManipulation.GetVariableInfo("OperatorLibrary").ActualName = "FunctionLibrary";
     
    222170
    223171      DoubleArrayData probabilities = new DoubleArrayData(new double[manipulators.Length]);
    224       for(int i=0;i<manipulators.Length;i++) {
     172      for (int i = 0; i < manipulators.Length; i++) {
    225173        probabilities.Data[i] = 1.0;
    226174        multibranch.AddSubOperator(manipulators[i]);
     
    234182    }
    235183
    236     private CombinedOperator CreateInialization() {
    237       CombinedOperator init = new CombinedOperator();
     184    protected internal override IOperator CreateBestSolutionProcessor() {
     185      SequentialProcessor bestSolutionProcessor = new SequentialProcessor();
     186      MeanSquaredErrorEvaluator testMseEvaluator = new MeanSquaredErrorEvaluator();
     187      testMseEvaluator.Name = "TestMeanSquaredErrorEvaluator";
     188      testMseEvaluator.GetVariableInfo("MSE").ActualName = "TestQuality";
     189      testMseEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
     190      testMseEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
     191      MeanAbsolutePercentageErrorEvaluator trainingMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator();
     192      trainingMapeEvaluator.Name = "TrainingMapeEvaluator";
     193      trainingMapeEvaluator.GetVariableInfo("MAPE").ActualName = "TrainingMAPE";
     194      trainingMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
     195      trainingMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
     196      MeanAbsolutePercentageErrorEvaluator validationMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator();
     197      validationMapeEvaluator.Name = "ValidationMapeEvaluator";
     198      validationMapeEvaluator.GetVariableInfo("MAPE").ActualName = "ValidationMAPE";
     199      validationMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
     200      validationMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
     201      MeanAbsolutePercentageErrorEvaluator testMapeEvaluator = new MeanAbsolutePercentageErrorEvaluator();
     202      testMapeEvaluator.Name = "TestMapeEvaluator";
     203      testMapeEvaluator.GetVariableInfo("MAPE").ActualName = "TestMAPE";
     204      testMapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
     205      testMapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
     206      MeanAbsolutePercentageOfRangeErrorEvaluator trainingMapreEvaluator = new MeanAbsolutePercentageOfRangeErrorEvaluator();
     207      trainingMapreEvaluator.Name = "TrainingMapreEvaluator";
     208      trainingMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "TrainingMAPRE";
     209      trainingMapreEvaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
     210      trainingMapreEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
     211      MeanAbsolutePercentageOfRangeErrorEvaluator validationMapreEvaluator = new MeanAbsolutePercentageOfRangeErrorEvaluator();
     212      validationMapreEvaluator.Name = "ValidationMapreEvaluator";
     213      validationMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "ValidationMAPRE";
     214      validationMapreEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
     215      validationMapreEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
     216      MeanAbsolutePercentageOfRangeErrorEvaluator testMapreEvaluator = new MeanAbsolutePercentageOfRangeErrorEvaluator();
     217      testMapreEvaluator.Name = "TestMapreEvaluator";
     218      testMapreEvaluator.GetVariableInfo("MAPRE").ActualName = "TestMAPRE";
     219      testMapreEvaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
     220      testMapreEvaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
     221      CoefficientOfDeterminationEvaluator trainingR2Evaluator = new CoefficientOfDeterminationEvaluator();
     222      trainingR2Evaluator.Name = "TrainingR2Evaluator";
     223      trainingR2Evaluator.GetVariableInfo("R2").ActualName = "TrainingR2";
     224      trainingR2Evaluator.GetVariableInfo("SamplesStart").ActualName = "TrainingSamplesStart";
     225      trainingR2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "TrainingSamplesEnd";
     226      CoefficientOfDeterminationEvaluator validationR2Evaluator = new CoefficientOfDeterminationEvaluator();
     227      validationR2Evaluator.Name = "ValidationR2Evaluator";
     228      validationR2Evaluator.GetVariableInfo("R2").ActualName = "ValidationR2";
     229      validationR2Evaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
     230      validationR2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
     231      CoefficientOfDeterminationEvaluator testR2Evaluator = new CoefficientOfDeterminationEvaluator();
     232      testR2Evaluator.Name = "TestR2Evaluator";
     233      testR2Evaluator.GetVariableInfo("R2").ActualName = "TestR2";
     234      testR2Evaluator.GetVariableInfo("SamplesStart").ActualName = "TestSamplesStart";
     235      testR2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "TestSamplesEnd";
     236      ProgrammableOperator progOperator = new ProgrammableOperator();
     237      progOperator.RemoveVariableInfo("Result");
     238      progOperator.AddVariableInfo(new HeuristicLab.Core.VariableInfo("EvaluatedSolutions", "", typeof(IntData), VariableKind.In));
     239      progOperator.Code = @"
     240int evalSolutions = EvaluatedSolutions.Data;
     241scope.AddVariable(new Variable(""EvaluatedSolutions"", new IntData(evalSolutions)));
     242";
     243      bestSolutionProcessor.AddSubOperator(testMseEvaluator);
     244      bestSolutionProcessor.AddSubOperator(trainingMapeEvaluator);
     245      bestSolutionProcessor.AddSubOperator(validationMapeEvaluator);
     246      bestSolutionProcessor.AddSubOperator(testMapeEvaluator);
     247      bestSolutionProcessor.AddSubOperator(trainingMapreEvaluator);
     248      bestSolutionProcessor.AddSubOperator(validationMapreEvaluator);
     249      bestSolutionProcessor.AddSubOperator(testMapreEvaluator);
     250      bestSolutionProcessor.AddSubOperator(trainingR2Evaluator);
     251      bestSolutionProcessor.AddSubOperator(validationR2Evaluator);
     252      bestSolutionProcessor.AddSubOperator(testR2Evaluator);
     253      bestSolutionProcessor.AddSubOperator(progOperator);
     254      return bestSolutionProcessor;
     255    }
     256
     257    protected internal override IOperator CreateLoggingOperator() {
     258      CombinedOperator loggingOperator = new CombinedOperator();
     259      loggingOperator.Name = "Logging";
    238260      SequentialProcessor seq = new SequentialProcessor();
    239       SubScopesCreater subScopesCreater = new SubScopesCreater();
    240       subScopesCreater.GetVariableInfo("SubScopes").ActualName = "PopulationSize";
    241       UniformSequentialSubScopesProcessor subScopesProc = new UniformSequentialSubScopesProcessor();
    242       SequentialProcessor individualSeq = new SequentialProcessor();
    243       OperatorExtractor treeCreater = new OperatorExtractor();
    244       treeCreater.Name = "Tree generator (extr.)";
    245       treeCreater.GetVariableInfo("Operator").ActualName = "Tree generator";
    246       OperatorExtractor evaluator = new OperatorExtractor();
    247       evaluator.Name = "Evaluator (extr.)";
    248       evaluator.GetVariableInfo("Operator").ActualName = "Evaluator";
    249       MeanSquaredErrorEvaluator validationEvaluator = new MeanSquaredErrorEvaluator();
    250       validationEvaluator.GetVariableInfo("MSE").ActualName = "ValidationQuality";
    251       validationEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    252       validationEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    253       Counter evalCounter = new Counter();
    254       evalCounter.GetVariableInfo("Value").ActualName = "EvaluatedSolutions";
    255 
    256       seq.AddSubOperator(subScopesCreater);
    257       seq.AddSubOperator(subScopesProc);
    258       subScopesProc.AddSubOperator(individualSeq);
    259       individualSeq.AddSubOperator(treeCreater);
    260       individualSeq.AddSubOperator(evaluator);
    261       individualSeq.AddSubOperator(validationEvaluator);
    262       individualSeq.AddSubOperator(evalCounter);
    263 
    264       init.OperatorGraph.AddOperator(seq);
    265       init.OperatorGraph.InitialOperator = seq;
    266       return init;
    267     }
    268 
    269     private CombinedOperator CreateMainLoop() {
    270       CombinedOperator main = new CombinedOperator();
    271       SequentialProcessor seq = new SequentialProcessor();
    272       CombinedOperator childCreater = CreateChildCreater();
    273       childCreater.Name = "Create children";
    274       CombinedOperator replacement = CreateReplacement();
    275       replacement.Name = "Replacement";
    276       BestSolutionStorer solutionStorer = CreateBestSolutionStorer();
    277       BestAverageWorstQualityCalculator qualityCalculator = new BestAverageWorstQualityCalculator();
    278       BestAverageWorstQualityCalculator validationQualityCalculator = new BestAverageWorstQualityCalculator();
    279       validationQualityCalculator.Name = "ValidationQualityCalculator";
    280       validationQualityCalculator.GetVariableInfo("BestQuality").ActualName = "BestValidationQuality";
    281       validationQualityCalculator.GetVariableInfo("AverageQuality").ActualName = "AverageValidationQuality";
    282       validationQualityCalculator.GetVariableInfo("WorstQuality").ActualName = "WorstValidationQuality";
     261
    283262      DataCollector collector = new DataCollector();
    284263      ItemList<StringData> names = collector.GetVariable("VariableNames").GetValue<ItemList<StringData>>();
     
    294273      QualityLogger qualityLogger = new QualityLogger();
    295274      QualityLogger validationQualityLogger = new QualityLogger();
    296       validationQualityCalculator.Name = "ValidationQualityLogger";
     275      validationQualityLogger.Name = "ValidationQualityLogger";
    297276      validationQualityLogger.GetVariableInfo("Quality").ActualName = "ValidationQuality";
    298277      validationQualityLogger.GetVariableInfo("QualityLog").ActualName = "ValidationQualityLog";
    299       Counter counter = new Counter();
    300       counter.GetVariableInfo("Value").ActualName = "Generations";
    301       LessThanComparator comparator = new LessThanComparator();
    302       comparator.GetVariableInfo("LeftSide").ActualName = "Generations";
    303       comparator.GetVariableInfo("RightSide").ActualName = "MaxGenerations";
    304       comparator.GetVariableInfo("Result").ActualName = "GenerationsCondition";
    305       ConditionalBranch cond = new ConditionalBranch();
    306       cond.GetVariableInfo("Condition").ActualName = "GenerationsCondition";
    307 
    308       seq.AddSubOperator(childCreater);
    309       seq.AddSubOperator(replacement);
    310       seq.AddSubOperator(solutionStorer);
    311       seq.AddSubOperator(qualityCalculator);
    312       seq.AddSubOperator(validationQualityCalculator);
     278
    313279      seq.AddSubOperator(collector);
    314280      seq.AddSubOperator(lineChartInjector);
    315281      seq.AddSubOperator(qualityLogger);
    316282      seq.AddSubOperator(validationQualityLogger);
    317       seq.AddSubOperator(counter);
    318       seq.AddSubOperator(comparator);
    319       seq.AddSubOperator(cond);
    320       cond.AddSubOperator(seq);
    321 
    322       main.OperatorGraph.AddOperator(seq);
    323       main.OperatorGraph.InitialOperator = seq;
    324       return main;
    325     }
    326 
    327     private BestSolutionStorer CreateBestSolutionStorer() {
    328       BestSolutionStorer solutionStorer = new BestSolutionStorer();
    329       solutionStorer.GetVariableInfo("Quality").ActualName = "ValidationQuality";
    330       solutionStorer.GetVariableInfo("BestSolution").ActualName = "BestValidationSolution";
    331       SequentialProcessor bestSolutionProcessor = new SequentialProcessor();
    332       MeanAbsolutePercentageErrorEvaluator mapeEvaluator = new MeanAbsolutePercentageErrorEvaluator();
    333       mapeEvaluator.Name = "ValidationMapeEvaluator";
    334       mapeEvaluator.GetVariableInfo("MAPE").ActualName = "ValidationMAPE";
    335       mapeEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    336       mapeEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    337       CoefficientOfDeterminationEvaluator r2Evaluator = new CoefficientOfDeterminationEvaluator();
    338       r2Evaluator.Name = "ValidationR2Evaluator";
    339       r2Evaluator.GetVariableInfo("R2").ActualName = "ValidationR2";
    340       r2Evaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    341       r2Evaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    342       ProgrammableOperator progOperator = new ProgrammableOperator();
    343       progOperator.RemoveVariableInfo("Result");
    344       progOperator.AddVariableInfo(new HeuristicLab.Core.VariableInfo("EvaluatedSolutions", "", typeof(IntData), VariableKind.In));
    345       progOperator.Code = @"
    346 int evalSolutions = EvaluatedSolutions.Data;
    347 scope.AddVariable(new Variable(""EvaluatedSolutions"", new IntData(evalSolutions)));
    348 ";
    349       solutionStorer.AddSubOperator(bestSolutionProcessor);
    350       bestSolutionProcessor.AddSubOperator(mapeEvaluator);
    351       bestSolutionProcessor.AddSubOperator(r2Evaluator);
    352       bestSolutionProcessor.AddSubOperator(progOperator);
    353       return solutionStorer;
    354     }
    355 
    356     private CombinedOperator CreateReplacement() {
    357       CombinedOperator replacement = new CombinedOperator();
    358       SequentialProcessor seq = new SequentialProcessor();
    359       SequentialSubScopesProcessor seqScopeProc = new SequentialSubScopesProcessor();
    360       SequentialProcessor selectedProc = new SequentialProcessor();
    361       LeftSelector leftSelector = new LeftSelector();
    362       leftSelector.GetVariableInfo("Selected").ActualName = "Elites";
    363       RightReducer rightReducer = new RightReducer();
    364 
    365       SequentialProcessor remainingProc = new SequentialProcessor();
    366       RightSelector rightSelector = new RightSelector();
    367       rightSelector.GetVariableInfo("Selected").ActualName = "Elites";
    368       LeftReducer leftReducer = new LeftReducer();
    369       MergingReducer mergingReducer = new MergingReducer();
    370       Sorter sorter = new Sorter();
    371       sorter.GetVariableInfo("Descending").ActualName = "Maximization";
    372       sorter.GetVariableInfo("Value").ActualName = "Quality";
    373 
    374       seq.AddSubOperator(seqScopeProc);
    375       seqScopeProc.AddSubOperator(selectedProc);
    376       selectedProc.AddSubOperator(leftSelector);
    377       selectedProc.AddSubOperator(rightReducer);
    378 
    379       seqScopeProc.AddSubOperator(remainingProc);
    380       remainingProc.AddSubOperator(rightSelector);
    381       remainingProc.AddSubOperator(leftReducer);
    382       seq.AddSubOperator(mergingReducer);
    383       seq.AddSubOperator(sorter);
    384       replacement.OperatorGraph.AddOperator(seq);
    385       replacement.OperatorGraph.InitialOperator = seq;
    386       return replacement;
    387     }
    388 
    389     private CombinedOperator CreateChildCreater() {
    390       CombinedOperator childCreater = new CombinedOperator();
    391       SequentialProcessor seq = new SequentialProcessor();
    392       OperatorExtractor selector = new OperatorExtractor();
    393       selector.Name = "Selector (extr.)";
    394       selector.GetVariableInfo("Operator").ActualName = "Selector";
    395       SequentialSubScopesProcessor seqScopesProc = new SequentialSubScopesProcessor();
    396       EmptyOperator emptyOpt = new EmptyOperator();
    397       SequentialProcessor selectedProc = new SequentialProcessor();
    398       OperatorExtractor crossover = new OperatorExtractor();
    399       crossover.Name = "Crossover (extr.)";
    400       crossover.GetVariableInfo("Operator").ActualName = "Crossover";
    401       UniformSequentialSubScopesProcessor individualProc = new UniformSequentialSubScopesProcessor();
    402       SequentialProcessor individualSeqProc = new SequentialProcessor();
    403       StochasticBranch cond = new StochasticBranch();
    404       cond.GetVariableInfo("Probability").ActualName = "MutationRate";
    405       OperatorExtractor manipulator = new OperatorExtractor();
    406       manipulator.Name = "Manipulator (extr.)";
    407       manipulator.GetVariableInfo("Operator").ActualName = "Manipulator";
    408       OperatorExtractor evaluator = new OperatorExtractor();
    409       evaluator.Name = "Evaluator (extr.)";
    410       evaluator.GetVariableInfo("Operator").ActualName = "Evaluator";
    411       MeanSquaredErrorEvaluator validationEvaluator = new MeanSquaredErrorEvaluator();
    412       validationEvaluator.GetVariableInfo("MSE").ActualName = "ValidationQuality";
    413       validationEvaluator.GetVariableInfo("SamplesStart").ActualName = "ValidationSamplesStart";
    414       validationEvaluator.GetVariableInfo("SamplesEnd").ActualName = "ValidationSamplesEnd";
    415       Counter evalCounter = new Counter();
    416       evalCounter.GetVariableInfo("Value").ActualName = "EvaluatedSolutions";
    417 
    418       Sorter sorter = new Sorter();
    419       sorter.GetVariableInfo("Descending").ActualName = "Maximization";
    420       sorter.GetVariableInfo("Value").ActualName = "Quality";
    421 
    422 
    423       seq.AddSubOperator(selector);
    424       seq.AddSubOperator(seqScopesProc);
    425       seqScopesProc.AddSubOperator(emptyOpt);
    426       seqScopesProc.AddSubOperator(selectedProc);
    427       selectedProc.AddSubOperator(crossover);
    428       selectedProc.AddSubOperator(individualProc);
    429       individualProc.AddSubOperator(individualSeqProc);
    430       individualSeqProc.AddSubOperator(cond);
    431       cond.AddSubOperator(manipulator);
    432       individualSeqProc.AddSubOperator(evaluator);
    433       individualSeqProc.AddSubOperator(validationEvaluator);
    434       individualSeqProc.AddSubOperator(evalCounter);
    435       selectedProc.AddSubOperator(sorter);
    436 
    437       childCreater.OperatorGraph.AddOperator(seq);
    438       childCreater.OperatorGraph.InitialOperator = seq;
    439       return childCreater;
    440     }
    441 
    442     public IEditor CreateEditor() {
     283
     284      loggingOperator.OperatorGraph.AddOperator(seq);
     285      loggingOperator.OperatorGraph.InitialOperator = seq;
     286      return loggingOperator;
     287    }
     288
     289    public virtual IEditor CreateEditor() {
    443290      return new StandardGpEditor(this);
    444291    }
     
    447294      return new StandardGpEditor(this);
    448295    }
    449 
    450     public override object Clone(IDictionary<Guid, object> clonedObjects) {
    451       StandardGP clone = new StandardGP();
    452       clonedObjects.Add(Guid, clone);
    453       clone.engine = (SequentialEngine.SequentialEngine)Auxiliary.Clone(Engine, clonedObjects);
    454       return clone;
    455     }
    456     #region SetReferences Method
    457     private void SetReferences() {
    458       // SGA
    459       CombinedOperator co1 = (CombinedOperator)Engine.OperatorGraph.InitialOperator;
    460       // SequentialProcessor in SGA
    461       algorithm = (SequentialProcessor)co1.OperatorGraph.InitialOperator;
    462       // RandomInjector
    463       RandomInjector ri = (RandomInjector)algorithm.SubOperators[1];
    464       setSeedRandomly = ri.GetVariable("SetSeedRandomly").GetValue<BoolData>();
    465       seed = ri.GetVariable("Seed").GetValue<IntData>();
    466       // VariableInjector
    467       VariableInjector vi = (VariableInjector)algorithm.SubOperators[2];
    468       populationSize = vi.GetVariable("PopulationSize").GetValue<IntData>();
    469       parents = vi.GetVariable("Parents").GetValue<IntData>();
    470       maxGenerations = vi.GetVariable("MaxGenerations").GetValue<IntData>();
    471       mutationRate = vi.GetVariable("MutationRate").GetValue<DoubleData>();
    472       elites = vi.GetVariable("Elites").GetValue<IntData>();
    473     }
    474     #endregion
    475 
    476     #region Persistence Methods
    477     public override XmlNode GetXmlNode(string name, XmlDocument document, IDictionary<Guid, IStorable> persistedObjects) {
    478       XmlNode node = base.GetXmlNode(name, document, persistedObjects);
    479       node.AppendChild(PersistenceManager.Persist("Engine", Engine, document, persistedObjects));
    480       return node;
    481     }
    482     public override void Populate(XmlNode node, IDictionary<Guid, IStorable> restoredObjects) {
    483       base.Populate(node, restoredObjects);
    484       engine = (SequentialEngine.SequentialEngine)PersistenceManager.Restore(node.SelectSingleNode("Engine"), restoredObjects);
    485       SetReferences();
    486     }
    487     #endregion
    488296  }
    489297}
  • trunk/sources/HeuristicLab.GP.StructureIdentification/StandardGpEditor.Designer.cs

    r1053 r1287  
    165165      this.setRandomSeedRandomlyCheckBox.TabIndex = 1;
    166166      this.setRandomSeedRandomlyCheckBox.UseVisualStyleBackColor = true;
     167      this.setRandomSeedRandomlyCheckBox.CheckedChanged += new System.EventHandler(this.setRandomSeedRandomlyCheckBox_CheckedChanged);
    167168      //
    168169      // elitesTextBox
     
    353354
    354355    private System.Windows.Forms.Button executeButton;
    355     private System.Windows.Forms.TabControl tabControl;
    356     private System.Windows.Forms.TabPage parametersTabPage;
     356    protected System.Windows.Forms.TabControl tabControl;
     357    protected System.Windows.Forms.TabPage parametersTabPage;
    357358    private System.Windows.Forms.Button abortButton;
    358359    private System.Windows.Forms.Button resetButton;
  • trunk/sources/HeuristicLab.GP.StructureIdentification/StandardGpEditor.cs

    r1053 r1287  
    7171    }
    7272
    73     private void SetDataBinding() {
     73    protected virtual void SetDataBinding() {
    7474      setRandomSeedRandomlyCheckBox.DataBindings.Add("Checked", StandardGP, "SetSeedRandomly");
    7575      randomSeedTextBox.DataBindings.Add("Text", StandardGP, "Seed");
     
    9797      executeButton.Enabled = false;
    9898      abortButton.Enabled = true;
     99      resetButton.Enabled = false;
    99100      StandardGP.Engine.Execute();
    100101    }
     
    127128        executeButton.Enabled = true;
    128129        abortButton.Enabled = false;
     130        resetButton.Enabled = true;
    129131      }
    130132    }
    131133    #endregion
    132134
    133 
     135    private void setRandomSeedRandomlyCheckBox_CheckedChanged(object sender, EventArgs e) {
     136      randomSeedTextBox.Enabled = !setRandomSeedRandomlyCheckBox.Checked;
     137      randomSeedLabel.Enabled = !setRandomSeedRandomlyCheckBox.Checked;
     138    }
    134139  }
    135140}
Note: See TracChangeset for help on using the changeset viewer.