Changeset 13124


Ignore:
Timestamp:
11/05/15 16:20:55 (4 years ago)
Author:
pfleck
Message:

#2269

  • Implemented full wiring of ALPS.
  • Created new AlpsGeneticAlgorithmMainOperator instead of using a modified GeneticAlgorithmMainLoop because of wiring issues.
  • Separated LayerCreator into generic LastScopeCloner and ResultsHistoryWiper.
Location:
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3
Files:
1 added
6 edited
1 moved

Legend:

Unmodified
Added
Removed
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithm.cs

    r13117 r13124  
    114114      get { return (IValueParameter<IntValue>)Parameters["MatingPoolRange"]; }
    115115    }
     116    private IValueParameter<BoolValue> ReduceToPopulationSizeParameter {
     117      get { return (IValueParameter<BoolValue>)Parameters["ReduceToPopulationSize"]; }
     118    }
    116119
    117120    private IValueParameter<MultiTerminator> TerminatorParameter {
     
    290293      Parameters.Add(new ValueParameter<IntValue>("AgeGap", "The frequency of reseeding the lowest layer and scaling factor for the age-limits for the layers", new IntValue(20)));
    291294      Parameters.Add(new ValueParameter<DoubleValue>("AgeInheritance", "A weight that determines the age of a child after crossover based on the older (1.0) and younger (0.0) parent.", new DoubleValue(1.0)) { Hidden = true });
    292       Parameters.Add(new ValueParameter<IntArray>("AgeLimits", new IntArray(new int[0])) { Hidden = true });
     295      Parameters.Add(new ValueParameter<IntArray>("AgeLimits", "The maximum ages for the Layers.", new IntArray(new int[0])) { Hidden = true });
    293296
    294297      Parameters.Add(new ValueParameter<IntValue>("MatingPoolRange", "The range of layers used for creating a mating pool. (1 = current + previous layer)", new IntValue(1)) { Hidden = true });
     
    357360      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions"));
    358361      resultsCollector.Successor = mainLoop;
     362
     363      mainLoop.GlobalRandomParameter.ActualName = "GlobalRandom";
     364      mainLoop.LocalRandomParameter.ActualName = "LocalRandom";
     365      mainLoop.EvaluatedSolutionsParameter.ActualName = "EvaluatedSolutions";
     366      mainLoop.AnalyzerParameter.ActualName = AnalyzerParameter.Name;
     367      mainLoop.LayerAnalyzerParameter.ActualName = LayerAnalyzerParameter.Name;
     368      mainLoop.NumberOfLayersParameter.ActualName = NumberOfLayersParameter.Name;
     369      mainLoop.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
     370      mainLoop.CurrentPopulationSizeParameter.ActualName = "CurrentPopulationSize";
     371      mainLoop.SelectorParameter.ActualName = SelectorParameter.Name;
     372      mainLoop.CrossoverParameter.ActualName = CrossoverParameter.Name;
     373      mainLoop.MutatorParameter.ActualName = MutatorParameter.Name;
     374      mainLoop.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
     375      mainLoop.ElitesParameter.ActualName = ElitesParameter.Name;
     376      mainLoop.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
     377      mainLoop.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name;
     378      mainLoop.AgeParameter.ActualName = "Age";
     379      mainLoop.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
     380      mainLoop.AgeLimitsParameter.ActualName = AgeLimitsParameter.Name;
     381      mainLoop.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name;
     382      mainLoop.ReduceToPopulationSizeParameter.ActualName = ReduceToPopulationSizeParameter.Name;
    359383      #endregion
    360384
     
    364388      var defaultSelector = SelectorParameter.ValidValues.OfType<GeneralizedRankSelector>().FirstOrDefault();
    365389      if (defaultSelector != null) {
    366         defaultSelector.PressureParameter.Value = new DoubleValue(4);
     390        defaultSelector.PressureParameter.Value = new DoubleValue(4.0);
    367391        SelectorParameter.Value = defaultSelector;
    368392      }
     
    546570    }
    547571    private void ParameterizeMainLoop() {
     572      MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
     573      MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    548574      MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    549       MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    550       MainLoop.MainOperator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
    551       MainLoop.MainOperator.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    552       MainLoop.MainOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    553575    }
    554576    private void ParameterizeAnalyzers() {
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs

    r13117 r13124  
    2020#endregion
    2121
    22 using System.Linq;
    23 using HeuristicLab.Algorithms.GeneticAlgorithm;
    2422using HeuristicLab.Common;
    2523using HeuristicLab.Core;
     
    3836  public sealed class AlpsGeneticAlgorithmMainLoop : AlgorithmOperator {
    3937    #region Parameter Properties
    40     public ValueLookupParameter<BoolValue> MaximizationParameter {
    41       get { return (ValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
    42     }
    43     public ScopeTreeLookupParameter<DoubleValue> QualityParameter {
    44       get { return (ScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    45     }
     38    public IValueLookupParameter<IRandom> GlobalRandomParameter {
     39      get { return (IValueLookupParameter<IRandom>)Parameters["GlobalRandom"]; }
     40    }
     41    public IValueLookupParameter<IRandom> LocalRandomParameter {
     42      get { return (IValueLookupParameter<IRandom>)Parameters["LocalRandom"]; }
     43    }
     44
     45    public IValueLookupParameter<IOperator> EvaluatorParameter {
     46      get { return (IValueLookupParameter<IOperator>)Parameters["Evaluator"]; }
     47    }
     48    public IValueLookupParameter<IntValue> EvaluatedSolutionsParameter {
     49      get { return (IValueLookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
     50    }
     51    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
     52      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
     53    }
     54    public IValueLookupParameter<BoolValue> MaximizationParameter {
     55      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     56    }
     57
    4658    public ILookupParameter<IOperator> AnalyzerParameter {
    4759      get { return (ILookupParameter<IOperator>)Parameters["Analyzer"]; }
     
    5062      get { return (ILookupParameter<IOperator>)Parameters["LayerAnalyzer"]; }
    5163    }
     64
     65    public IValueLookupParameter<IntValue> NumberOfLayersParameter {
     66      get { return (IValueLookupParameter<IntValue>)Parameters["NumberOfLayers"]; }
     67    }
     68    public IValueLookupParameter<IntValue> PopulationSizeParameter {
     69      get { return (IValueLookupParameter<IntValue>)Parameters["PopulationSize"]; }
     70    }
     71    public ILookupParameter<IntValue> CurrentPopulationSizeParameter {
     72      get { return (ILookupParameter<IntValue>)Parameters["CurrentPopulationSize"]; }
     73    }
     74
     75    public IValueLookupParameter<IOperator> SelectorParameter {
     76      get { return (IValueLookupParameter<IOperator>)Parameters["Selector"]; }
     77    }
     78    public IValueLookupParameter<IOperator> CrossoverParameter {
     79      get { return (IValueLookupParameter<IOperator>)Parameters["Crossover"]; }
     80    }
     81    public IValueLookupParameter<IOperator> MutatorParameter {
     82      get { return (IValueLookupParameter<IOperator>)Parameters["Mutator"]; }
     83    }
     84    public IValueLookupParameter<PercentValue> MutationProbabilityParameter {
     85      get { return (IValueLookupParameter<PercentValue>)Parameters["MutationProbability"]; }
     86    }
     87    public IValueLookupParameter<IntValue> ElitesParameter {
     88      get { return (IValueLookupParameter<IntValue>)Parameters["Elites"]; }
     89    }
     90    public IValueLookupParameter<BoolValue> ReevaluateElitesParameter {
     91      get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; }
     92    }
     93    public IValueLookupParameter<BoolValue> PlusSelectionParameter {
     94      get { return (IValueLookupParameter<BoolValue>)Parameters["PlusSelection"]; }
     95    }
     96
     97    public IScopeTreeLookupParameter<DoubleValue> AgeParameter {
     98      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Age"]; }
     99    }
     100    public IValueLookupParameter<DoubleValue> AgeInheritanceParameter {
     101      get { return (IValueLookupParameter<DoubleValue>)Parameters["AgeInheritance"]; }
     102    }
     103    public IValueLookupParameter<IntArray> AgeLimitsParameter {
     104      get { return (IValueLookupParameter<IntArray>)Parameters["AgeLimits"]; }
     105    }
     106
     107    public IValueLookupParameter<IntValue> MatingPoolRangeParameter {
     108      get { return (IValueLookupParameter<IntValue>)Parameters["MatingPoolRange"]; }
     109    }
     110    public IValueLookupParameter<BoolValue> ReduceToPopulationSizeParameter {
     111      get { return (IValueLookupParameter<BoolValue>)Parameters["ReduceToPopulationSize"]; }
     112    }
    52113    #endregion
    53 
    54     public GeneticAlgorithmMainLoop MainOperator {
    55       get { return OperatorGraph.Iterate().OfType<GeneticAlgorithmMainLoop>().First(); }
    56     }
    57114
    58115    [StorableConstructor]
     
    66123    public AlpsGeneticAlgorithmMainLoop()
    67124      : base() {
    68       Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false.") { Hidden = true });
     125      Parameters.Add(new ValueLookupParameter<IRandom>("GlobalRandom", "A pseudo random number generator."));
     126      Parameters.Add(new ValueLookupParameter<IRandom>("LocalRandom", "A pseudo random number generator."));
     127
     128      Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization."));
     129      Parameters.Add(new ValueLookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
    69130      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
    70       Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations that the algorithm should process."));
    71       Parameters.Add(new LookupParameter<IOperator>("Analyzer", "The operator used to the analyze all individuals."));
    72       Parameters.Add(new LookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each layer."));
     131      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
     132
     133      Parameters.Add(new ValueLookupParameter<IOperator>("Analyzer", "The operator used to analyze the islands."));
     134      Parameters.Add(new ValueLookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each layer."));
     135
     136      Parameters.Add(new ValueLookupParameter<IntValue>("NumberOfLayers", "The number of layers."));
     137      Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population."));
     138      Parameters.Add(new LookupParameter<IntValue>("CurrentPopulationSize", "The current size of the population."));
     139
     140      Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
     141      Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
     142      Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
     143      Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
     144      Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
     145      Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
     146      Parameters.Add(new ValueLookupParameter<BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation."));
     147
     148      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Age", "The age of individuals."));
     149      Parameters.Add(new ValueLookupParameter<DoubleValue>("AgeInheritance", "A weight that determines the age of a child after crossover based on the older (1.0) and younger (0.0) parent."));
     150      Parameters.Add(new ValueLookupParameter<IntArray>("AgeLimits", "The maximum ages for the Layers."));
     151
     152      Parameters.Add(new ValueLookupParameter<IntValue>("MatingPoolRange", "The range of sub - populations used for creating a mating pool. (1 = current + previous sub-population)"));
     153      Parameters.Add(new ValueLookupParameter<BoolValue>("ReduceToPopulationSize", "Reduce the LayerPopulationSize after elder migration to PopulationSize"));
     154
    73155
    74156      var variableCreator = new VariableCreator() { Name = "Initialize" };
     
    81163      var matingPoolProcessor = new UniformSubScopesProcessor() { Name = "Process Mating Pools" };
    82164      var initializeLayer = new Assigner() { Name = "Reset LayerEvaluatedSolutions" };
    83       var mainOperator = AlpsGeneticAlgorithmMainOperator.Create();
     165      var mainOperator = new AlpsGeneticAlgorithmMainOperator();
    84166      var generationsIcrementor = new IntCounter() { Name = "Increment Generations" };
    85167      var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" };
     
    112194
    113195      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
    114       resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each layer", "LayerResults"));
     196      resultsCollector.CollectedValues.Add(new ScopeTreeLookupParameter<ResultCollection>("LayerResults", "Result set for each Layer", "LayerResults"));
    115197      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
    116198      resultsCollector.CopyValue = new BoolValue(false);
    117199      resultsCollector.Successor = matingPoolCreator;
    118200
     201      matingPoolCreator.MatingPoolRangeParameter.Value = null;
     202      matingPoolCreator.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name;
    119203      matingPoolCreator.Successor = matingPoolProcessor;
    120204
     
    127211      initializeLayer.Successor = mainOperator;
    128212
     213      mainOperator.RandomParameter.ActualName = LocalRandomParameter.Name;
     214      mainOperator.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
     215      mainOperator.EvaluatedSolutionsParameter.ActualName = "LayerEvaluatedSolutions";
     216      mainOperator.QualityParameter.ActualName = QualityParameter.Name;
     217      mainOperator.MaximizationParameter.ActualName = MaximizationParameter.Name;
     218      mainOperator.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
     219      mainOperator.SelectorParameter.ActualName = SelectorParameter.Name;
     220      mainOperator.CrossoverParameter.ActualName = CrossoverParameter.Name;
     221      mainOperator.MutatorParameter.ActualName = MutatorParameter.ActualName;
     222      mainOperator.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
     223      mainOperator.ElitesParameter.ActualName = ElitesParameter.Name;
     224      mainOperator.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
     225      mainOperator.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name;
     226      mainOperator.AgeParameter.ActualName = AgeParameter.Name;
     227      mainOperator.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
     228      mainOperator.AgeIncrementParameter.Value = new DoubleValue(1.0);
     229      mainOperator.Successor = null;
     230
    129231      generationsIcrementor.ValueParameter.ActualName = "Generations";
    130232      generationsIcrementor.Increment = new IntValue(1);
     
    132234
    133235      evaluatedSolutionsReducer.ParameterToReduce.ActualName = "LayerEvaluatedSolutions";
    134       evaluatedSolutionsReducer.TargetParameter.ActualName = "EvaluatedSolutions";
     236      evaluatedSolutionsReducer.TargetParameter.ActualName = EvaluatedSolutionsParameter.Name;
    135237      evaluatedSolutionsReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
    136238      evaluatedSolutionsReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
     
    154256    }
    155257
    156     private static CombinedOperator CreateEldersEmigrator() {
     258    private CombinedOperator CreateEldersEmigrator() {
    157259      var eldersEmigrator = new CombinedOperator() { Name = "Emigrate Elders" };
    158260      var selectorProsessor = new UniformSubScopesProcessor();
     
    163265      var subScopesCounter = new SubScopesCounter();
    164266      var reduceToPopulationSizeBranch = new ConditionalBranch() { Name = "ReduceToPopulationSize?" };
    165       var countCalculator = new ExpressionCalculator() { Name = "LayerPopulationSize = Min(LayerPopulationSize, PopulationSize)" };
     267      var countCalculator = new ExpressionCalculator() { Name = "CurrentPopulationSize = Min(CurrentPopulationSize, PopulationSize)" };
    166268      var bestSelector = new BestSelector();
    167269      var rightReducer = new RightReducer();
     
    179281      mergingReducer.Successor = subScopesCounter;
    180282
    181       subScopesCounter.ValueParameter.ActualName = "LayerPopulationSize";
     283      subScopesCounter.ValueParameter.ActualName = CurrentPopulationSizeParameter.Name;
    182284      subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
    183285      subScopesCounter.Successor = reduceToPopulationSizeBranch;
    184286
    185       reduceToPopulationSizeBranch.ConditionParameter.ActualName = "ReduceToPopulationSize";
     287      reduceToPopulationSizeBranch.ConditionParameter.ActualName = ReduceToPopulationSizeParameter.Name;
    186288      reduceToPopulationSizeBranch.TrueBranch = countCalculator;
    187289
    188       countCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize"));
    189       countCalculator.CollectedValues.Add(new LookupParameter<IntValue>("LayerPopulationSize"));
    190       countCalculator.ExpressionParameter.Value = new StringValue("LayerPopulationSize PopulationSize LayerPopulationSize PopulationSize < if toint");
    191       countCalculator.ExpressionResultParameter.ActualName = "LayerPopulationSize";
     290      countCalculator.CollectedValues.Add(new LookupParameter<IntValue>(PopulationSizeParameter.Name));
     291      countCalculator.CollectedValues.Add(new LookupParameter<IntValue>(CurrentPopulationSizeParameter.Name));
     292      countCalculator.ExpressionParameter.Value = new StringValue("CurrentPopulationSize PopulationSize CurrentPopulationSize PopulationSize < if toint");
     293      countCalculator.ExpressionResultParameter.ActualName = CurrentPopulationSizeParameter.Name;
    192294      countCalculator.Successor = bestSelector;
    193295
    194       bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "LayerPopulationSize";
     296      bestSelector.NumberOfSelectedSubScopesParameter.ActualName = CurrentPopulationSizeParameter.Name;
    195297      bestSelector.CopySelected = new BoolValue(false);
    196298      bestSelector.Successor = rightReducer;
     
    199301    }
    200302
    201     private static CombinedOperator CreateLayerOpener() {
     303    private CombinedOperator CreateLayerOpener() {
    202304      var layerOpener = new CombinedOperator() { Name = "Open new Layer if needed" };
    203305      var maxLayerReached = new Comparator() { Name = "MaxLayersReached = OpenLayers >= NumberOfLayers" };
     
    205307      var openNewLayerCalculator = new ExpressionCalculator() { Name = "OpenNewLayer = Generations >= AgeLimits[OpenLayers - 1]" };
    206308      var openNewLayerBranch = new ConditionalBranch() { Name = "OpenNewLayer?" };
    207       var layerCreator = new LayerCreator() { Name = "Create Layer" };
    208       var createChildrenViaCrossover = AlpsGeneticAlgorithmMainOperator.Create();
     309      var layerCreator = new LastScopeCloner() { Name = "Create Layer" };
     310      var updateLayerNumber = new Assigner() { Name = "Layer = OpenLayers" };
     311      var historyWiper = new ResultsHistoryWiper() { Name = "Clear History in Results" };
     312      var createChildrenViaCrossover = new AlpsGeneticAlgorithmMainOperator();
    209313      var incrEvaluatedSolutionsForNewLayer = new SubScopesCounter() { Name = "Update EvaluatedSolutions" };
    210314      var incrOpenLayers = new IntCounter() { Name = "Incr. OpenLayers" };
     
    214318
    215319      maxLayerReached.LeftSideParameter.ActualName = "OpenLayers";
    216       maxLayerReached.RightSideParameter.ActualName = "NumberOfLayers";
     320      maxLayerReached.RightSideParameter.ActualName = NumberOfLayersParameter.Name;
    217321      maxLayerReached.ResultParameter.ActualName = "MaxLayerReached";
    218322      maxLayerReached.Comparison = new Comparison(ComparisonType.GreaterOrEqual);
     
    222326      maxLayerReachedBranch.FalseBranch = openNewLayerCalculator;
    223327
    224       openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntArray>("AgeLimits"));
     328      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntArray>(AgeLimitsParameter.Name));
    225329      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Generations"));
    226       openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("NumberOfLayers"));
     330      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>(NumberOfLayersParameter.Name));
    227331      openNewLayerCalculator.CollectedValues.Add(new LookupParameter<IntValue>("OpenLayers"));
    228332      openNewLayerCalculator.ExpressionResultParameter.ActualName = "OpenNewLayer";
     
    233337      openNewLayerBranch.TrueBranch = layerCreator;
    234338
    235       layerCreator.NewLayerOperator = createChildrenViaCrossover;
     339      layerCreator.NewScopeOperator = updateLayerNumber;
    236340      layerCreator.Successor = incrOpenLayers;
    237341
     342      updateLayerNumber.LeftSideParameter.ActualName = "Layer";
     343      updateLayerNumber.RightSideParameter.ActualName = "OpenLayers";
     344      updateLayerNumber.Successor = historyWiper;
     345
     346      historyWiper.ResultsParameter.ActualName = "LayerResults";
     347      historyWiper.Successor = createChildrenViaCrossover;
     348
     349      // Maybe use only crossover and no elitism instead of "default operator"
     350      createChildrenViaCrossover.RandomParameter.ActualName = LocalRandomParameter.Name;
     351      createChildrenViaCrossover.EvaluatorParameter.ActualName = EvaluatorParameter.Name;
     352      createChildrenViaCrossover.EvaluatedSolutionsParameter.ActualName = "LayerEvaluatedSolutions";
     353      createChildrenViaCrossover.QualityParameter.ActualName = QualityParameter.Name;
     354      createChildrenViaCrossover.MaximizationParameter.ActualName = MaximizationParameter.Name;
     355      createChildrenViaCrossover.PopulationSizeParameter.ActualName = PopulationSizeParameter.Name;
     356      createChildrenViaCrossover.SelectorParameter.ActualName = SelectorParameter.Name;
     357      createChildrenViaCrossover.CrossoverParameter.ActualName = CrossoverParameter.Name;
     358      createChildrenViaCrossover.MutatorParameter.ActualName = MutatorParameter.Name;
     359      createChildrenViaCrossover.MutationProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
     360      createChildrenViaCrossover.ElitesParameter.ActualName = ElitesParameter.Name;
     361      createChildrenViaCrossover.ReevaluateElitesParameter.ActualName = ReevaluateElitesParameter.Name;
     362      createChildrenViaCrossover.PlusSelectionParameter.ActualName = PlusSelectionParameter.Name;
     363      createChildrenViaCrossover.AgeParameter.ActualName = AgeParameter.Name;
     364      createChildrenViaCrossover.AgeInheritanceParameter.ActualName = AgeInheritanceParameter.Name;
     365      createChildrenViaCrossover.AgeIncrementParameter.Value = new DoubleValue(0.0);
    238366      createChildrenViaCrossover.Successor = incrEvaluatedSolutionsForNewLayer;
    239367
    240       incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = "EvaluatedSolutions";
     368      incrEvaluatedSolutionsForNewLayer.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
    241369      incrEvaluatedSolutionsForNewLayer.AccumulateParameter.Value = new BoolValue(true);
    242370
     
    252380    }
    253381
    254     private static CombinedOperator CreateReseeder() {
     382    private CombinedOperator CreateReseeder() {
    255383      var reseeder = new CombinedOperator() { Name = "Reseed Layer Zero if needed" };
    256384      var reseedingController = new ReseedingController() { Name = "Reseeding needed (Generation % AgeGap == 0)?" };
     
    267395      removeIndividuals.Successor = createIndividuals;
    268396
    269       createIndividuals.NumberOfSolutionsParameter.ActualName = "PopulationSize";
     397      createIndividuals.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
    270398      createIndividuals.Successor = initializeAgeProsessor;
    271399
     
    273401      initializeAgeProsessor.Successor = incrEvaluatedSolutionsAfterReseeding;
    274402
    275       initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>("Age", new DoubleValue(0)));
    276 
    277       incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = "EvaluatedSolutions";
     403      initializeAge.CollectedValues.Add(new ValueParameter<DoubleValue>(AgeParameter.Name, new DoubleValue(0)));
     404
     405      incrEvaluatedSolutionsAfterReseeding.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
    278406      incrEvaluatedSolutionsAfterReseeding.AccumulateParameter.Value = new BoolValue(true);
    279407
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainOperator.cs

    r13113 r13124  
    2020#endregion
    2121
    22 using System.Linq;
    23 using HeuristicLab.Algorithms.GeneticAlgorithm;
     22using HeuristicLab.Common;
     23using HeuristicLab.Core;
    2424using HeuristicLab.Data;
    2525using HeuristicLab.Operators;
    26 using HeuristicLab.Optimization;
    2726using HeuristicLab.Optimization.Operators;
    2827using HeuristicLab.Parameters;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2929using HeuristicLab.Selection;
    3030
    3131namespace HeuristicLab.Algorithms.ALPS {
    32   public static class AlpsGeneticAlgorithmMainOperator {
    33     public static GeneticAlgorithmMainLoop Create() {
    34       var mainLoop = new GeneticAlgorithmMainLoop();
    35 
    36       var selector = mainLoop.OperatorGraph.Iterate().OfType<Placeholder>().First(o => o.OperatorParameter.ActualName == "Selector");
    37       var crossover = mainLoop.OperatorGraph.Iterate().OfType<Placeholder>().First(o => o.OperatorParameter.ActualName == "Crossover");
    38       var subScopesCounter = mainLoop.OperatorGraph.Iterate().OfType<SubScopesCounter>().First();
    39       var elitesMerger = mainLoop.OperatorGraph.Iterate().OfType<MergingReducer>().First();
    40 
    41       // Operator starts with calculating number of selected scopes base on plus/comma-selection replacement scheme
    42       var numberOfSelectedSubScopesCalculator = new ExpressionCalculator() { Name = "NumberOfSelectedSubScopes = 2 * (PopulationSize - (PlusSelection ? 0 : Elites))" };
     32  [Item("AlpsGeneticAlgorithmMainOperator", "An operator that represents the core of an ALPS genetic algorithm.")]
     33  [StorableClass]
     34  public sealed class AlpsGeneticAlgorithmMainOperator : AlgorithmOperator {
     35    #region Parameter properties
     36    public IValueLookupParameter<IRandom> RandomParameter {
     37      get { return (IValueLookupParameter<IRandom>)Parameters["Random"]; }
     38    }
     39
     40    public IValueLookupParameter<IOperator> EvaluatorParameter {
     41      get { return (IValueLookupParameter<IOperator>)Parameters["Evaluator"]; }
     42    }
     43    public IValueLookupParameter<IntValue> EvaluatedSolutionsParameter {
     44      get { return (IValueLookupParameter<IntValue>)Parameters["EvaluatedSolutions"]; }
     45    }
     46    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
     47      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
     48    }
     49    public IValueLookupParameter<BoolValue> MaximizationParameter {
     50      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     51    }
     52
     53    public IValueLookupParameter<IntValue> PopulationSizeParameter {
     54      get { return (IValueLookupParameter<IntValue>)Parameters["PopulationSize"]; }
     55    }
     56    public IValueLookupParameter<IOperator> SelectorParameter {
     57      get { return (IValueLookupParameter<IOperator>)Parameters["Selector"]; }
     58    }
     59    public IValueLookupParameter<IOperator> CrossoverParameter {
     60      get { return (IValueLookupParameter<IOperator>)Parameters["Crossover"]; }
     61    }
     62    public IValueLookupParameter<IOperator> MutatorParameter {
     63      get { return (IValueLookupParameter<IOperator>)Parameters["Mutator"]; }
     64    }
     65    public IValueLookupParameter<PercentValue> MutationProbabilityParameter {
     66      get { return (IValueLookupParameter<PercentValue>)Parameters["MutationProbability"]; }
     67    }
     68    public IValueLookupParameter<IntValue> ElitesParameter {
     69      get { return (IValueLookupParameter<IntValue>)Parameters["Elites"]; }
     70    }
     71    public IValueLookupParameter<BoolValue> ReevaluateElitesParameter {
     72      get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; }
     73    }
     74    public IValueLookupParameter<BoolValue> PlusSelectionParameter {
     75      get { return (IValueLookupParameter<BoolValue>)Parameters["PlusSelection"]; }
     76    }
     77
     78    public IScopeTreeLookupParameter<DoubleValue> AgeParameter {
     79      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Age"]; }
     80    }
     81    public IValueLookupParameter<DoubleValue> AgeInheritanceParameter {
     82      get { return (IValueLookupParameter<DoubleValue>)Parameters["AgeInheritance"]; }
     83    }
     84    public IValueLookupParameter<DoubleValue> AgeIncrementParameter {
     85      get { return (IValueLookupParameter<DoubleValue>)Parameters["AgeIncrement"]; }
     86    }
     87    #endregion
     88
     89    [StorableConstructor]
     90    private AlpsGeneticAlgorithmMainOperator(bool deserializing) : base(deserializing) { }
     91    private AlpsGeneticAlgorithmMainOperator(AlpsGeneticAlgorithmMainOperator original, Cloner cloner)
     92      : base(original, cloner) {
     93    }
     94    public override IDeepCloneable Clone(Cloner cloner) {
     95      return new AlpsGeneticAlgorithmMainOperator(this, cloner);
     96    }
     97    public AlpsGeneticAlgorithmMainOperator()
     98      : base() {
     99      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
     100
     101      Parameters.Add(new ValueLookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions. This operator is executed in parallel, if an engine is used which supports parallelization."));
     102      Parameters.Add(new ValueLookupParameter<IntValue>("EvaluatedSolutions", "The number of times solutions have been evaluated."));
     103      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
     104      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
     105
     106      Parameters.Add(new ValueLookupParameter<IntValue>("PopulationSize", "The size of the population."));
     107      Parameters.Add(new ValueLookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
     108      Parameters.Add(new ValueLookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
     109      Parameters.Add(new ValueLookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
     110      Parameters.Add(new ValueLookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
     111      Parameters.Add(new ValueLookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
     112      Parameters.Add(new ValueLookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
     113      Parameters.Add(new ValueLookupParameter<BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation."));
     114
     115      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Age", "The age of individuals."));
     116      Parameters.Add(new ValueLookupParameter<DoubleValue>("AgeInheritance", "A weight that determines the age of a child after crossover based on the older (1.0) and younger (0.0) parent."));
     117      Parameters.Add(new ValueLookupParameter<DoubleValue>("AgeIncrement", "The value the age the individuals is incremented if they survives a generation."));
     118
     119
     120      var numberOfSelectedParentsCalculator = new ExpressionCalculator() { Name = "NumberOfSelectedParents = 2 * (PopulationSize - (PlusSelection ? 0 : Elites))" };
     121      var selector = new Placeholder() { Name = "Selector (Placeholder)" };
     122      var subScopesProcessor1 = new SubScopesProcessor();
     123      var childrenCreator = new ChildrenCreator();
     124      var uniformSubScopesProcessor1 = new UniformSubScopesProcessor();
     125      var crossover = new Placeholder() { Name = "Crossover (Placeholder)" };
     126      var stochasticBranch = new StochasticBranch() { Name = "MutationProbability" };
     127      var mutator = new Placeholder() { Name = "Mutator (Placeholder)" };
     128      var ageCalculator = new WeightingReducer() { Name = "Calculate Age" };
     129      var subScopesRemover = new SubScopesRemover();
     130      var uniformSubScopesProcessor2 = new UniformSubScopesProcessor();
     131      var evaluator = new Placeholder() { Name = "Evaluator (Placeholder)" };
     132      var subScopesCounter = new SubScopesCounter() { Name = "Increment EvaluatedSolutions" };
    43133      var replacementBranch = new ConditionalBranch() { Name = "PlusSelection?" };
    44 
    45       // Set new initial operator
    46       mainLoop.OperatorGraph.InitialOperator = numberOfSelectedSubScopesCalculator;
    47 
    48       numberOfSelectedSubScopesCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize"));
    49       numberOfSelectedSubScopesCalculator.CollectedValues.Add(new LookupParameter<IntValue>("Elites"));
    50       numberOfSelectedSubScopesCalculator.CollectedValues.Add(new LookupParameter<BoolValue>("PlusSelection"));
    51       numberOfSelectedSubScopesCalculator.ExpressionResultParameter.ActualName = "NumberOfSelectedSubScopes";
    52       numberOfSelectedSubScopesCalculator.ExpressionParameter.Value = new StringValue("PopulationSize 0 Elites PlusSelection if - 2 * toint");
    53       numberOfSelectedSubScopesCalculator.Successor = selector;
    54 
    55       // Use Elitism or Plus-Selection as replacement strategy
    56       var selectedProcessor = (SubScopesProcessor)selector.Successor;
    57       var elitismReplacement = selectedProcessor.Successor;
    58       selectedProcessor.Successor = replacementBranch;
    59       replacementBranch.ConditionParameter.ActualName = "PlusSelection";
    60       replacementBranch.FalseBranch = elitismReplacement;
    61 
    62       // Plus selection replacement
    63134      var replacementMergingReducer = new MergingReducer();
    64135      var replacementBestSelector = new BestSelector();
    65136      var replacementRightReducer = new RightReducer();
     137      var subScopesProcessor2 = new SubScopesProcessor();
     138      var bestSelector = new BestSelector();
     139      var rightReducer = new RightReducer();
     140      var mergingReducer = new MergingReducer();
     141      var reevaluateElitesBranch = new ConditionalBranch() { Name = "Reevaluate elites ?" };
     142      var incrementAgeProcessor = new UniformSubScopesProcessor();
     143      var ageIncrementor = new DoubleCounter() { Name = "Increment Age" };
     144
     145      OperatorGraph.InitialOperator = numberOfSelectedParentsCalculator;
     146
     147      numberOfSelectedParentsCalculator.CollectedValues.Add(new LookupParameter<IntValue>(PopulationSizeParameter.Name));
     148      numberOfSelectedParentsCalculator.CollectedValues.Add(new LookupParameter<IntValue>(ElitesParameter.Name));
     149      numberOfSelectedParentsCalculator.CollectedValues.Add(new LookupParameter<BoolValue>(PlusSelectionParameter.Name));
     150      numberOfSelectedParentsCalculator.ExpressionResultParameter.ActualName = "NumberOfSelectedSubScopes";
     151      numberOfSelectedParentsCalculator.ExpressionParameter.Value = new StringValue("PopulationSize 0 Elites PlusSelection if - 2 * toint");
     152      numberOfSelectedParentsCalculator.Successor = selector;
     153
     154      selector.OperatorParameter.ActualName = SelectorParameter.Name;
     155      selector.Successor = subScopesProcessor1;
     156
     157      subScopesProcessor1.Operators.Add(new EmptyOperator());
     158      subScopesProcessor1.Operators.Add(childrenCreator);
     159      subScopesProcessor1.Successor = replacementBranch;
     160
     161      childrenCreator.ParentsPerChild = new IntValue(2);
     162      childrenCreator.Successor = uniformSubScopesProcessor1;
     163
     164      uniformSubScopesProcessor1.Operator = crossover;
     165      uniformSubScopesProcessor1.Successor = uniformSubScopesProcessor2;
     166
     167      crossover.OperatorParameter.ActualName = CrossoverParameter.Name;
     168      crossover.Successor = stochasticBranch;
     169
     170      stochasticBranch.ProbabilityParameter.ActualName = MutationProbabilityParameter.Name;
     171      stochasticBranch.RandomParameter.ActualName = RandomParameter.Name;
     172      stochasticBranch.FirstBranch = mutator;
     173      stochasticBranch.SecondBranch = null;
     174      stochasticBranch.Successor = ageCalculator;
     175
     176      mutator.OperatorParameter.ActualName = MutatorParameter.Name;
     177      mutator.Successor = null;
     178
     179      ageCalculator.ParameterToReduce.ActualName = AgeParameter.Name;
     180      ageCalculator.TargetParameter.ActualName = AgeParameter.Name;
     181      ageCalculator.WeightParameter.ActualName = AgeInheritanceParameter.Name;
     182      ageCalculator.Successor = subScopesRemover;
     183
     184      subScopesRemover.RemoveAllSubScopes = true;
     185      subScopesRemover.Successor = null;
     186
     187      uniformSubScopesProcessor2.Parallel.Value = true;
     188      uniformSubScopesProcessor2.Operator = evaluator;
     189      uniformSubScopesProcessor2.Successor = subScopesCounter;
     190
     191      evaluator.OperatorParameter.ActualName = EvaluatorParameter.Name;
     192      evaluator.Successor = null;
     193
     194      subScopesCounter.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
     195      subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
     196      subScopesCounter.Successor = null;
     197
     198      replacementBranch.ConditionParameter.ActualName = PlusSelectionParameter.Name;
    66199      replacementBranch.TrueBranch = replacementMergingReducer;
     200      replacementBranch.FalseBranch = subScopesProcessor2;
     201      replacementBranch.Successor = incrementAgeProcessor;
    67202
    68203      replacementMergingReducer.Successor = replacementBestSelector;
    69204
    70       replacementBestSelector.NumberOfSelectedSubScopesParameter.ActualName = "PopulationSize";
     205      replacementBestSelector.NumberOfSelectedSubScopesParameter.ActualName = PopulationSizeParameter.Name;
    71206      replacementBestSelector.CopySelected = new BoolValue(false);
    72207      replacementBestSelector.Successor = replacementRightReducer;
    73208
    74       replacementRightReducer.Successor = null;
    75 
    76       // Increment ages of all individuals after replacement
    77       var incrementAgeProcessor = new UniformSubScopesProcessor();
    78       var ageIncrementor = new DoubleCounter() { Name = "Increment Age" };
    79       replacementBranch.Successor = incrementAgeProcessor;
     209      replacementRightReducer.Successor = reevaluateElitesBranch;
     210
     211      subScopesProcessor2.Operators.Add(bestSelector);
     212      subScopesProcessor2.Operators.Add(new EmptyOperator());
     213      subScopesProcessor2.Successor = mergingReducer;
     214
     215      bestSelector.CopySelected = new BoolValue(false);
     216      bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
     217      bestSelector.NumberOfSelectedSubScopesParameter.ActualName = ElitesParameter.Name;
     218      bestSelector.QualityParameter.ActualName = QualityParameter.Name;
     219      bestSelector.Successor = rightReducer;
     220
     221      rightReducer.Successor = reevaluateElitesBranch;
     222
     223      mergingReducer.Successor = null;
     224
     225      reevaluateElitesBranch.ConditionParameter.ActualName = ReevaluateElitesParameter.Name;
     226      reevaluateElitesBranch.TrueBranch = uniformSubScopesProcessor2;
     227      reevaluateElitesBranch.FalseBranch = null;
     228      reevaluateElitesBranch.Successor = null;
     229
     230
    80231      incrementAgeProcessor.Operator = ageIncrementor;
    81232      incrementAgeProcessor.Successor = null;
    82       ageIncrementor.ValueParameter.ActualName = "Age";
    83       ageIncrementor.Increment = new DoubleValue(1.0);
    84 
    85       // Insert AgeCalculator between crossover and its successor
    86       var crossoverSuccessor = crossover.Successor;
    87       var ageCalculator = new WeightingReducer() { Name = "Calculate Age" };
    88       crossover.Successor = ageCalculator;
    89 
    90       ageCalculator.ParameterToReduce.ActualName = "Age";
    91       ageCalculator.TargetParameter.ActualName = "Age";
    92       ageCalculator.WeightParameter.ActualName = "AgeInheritance";
    93       ageCalculator.Successor = crossoverSuccessor;
    94 
    95       // When counting the evaluated solutions, write in LayerEvaluatedSolutions
    96       subScopesCounter.ValueParameter.ActualName = "LayerEvaluatedSolutions";
    97       subScopesCounter.AccumulateParameter.Value = new BoolValue(false);
    98 
    99       // Instead of generational loop after merging of elites, stop
    100       elitesMerger.Successor = null;
    101 
    102       // Parameterize
    103       foreach (var stochasticOperator in mainLoop.OperatorGraph.Iterate().OfType<IStochasticOperator>())
    104         stochasticOperator.RandomParameter.ActualName = "LocalRandom";
    105       foreach (var stochasticBranch in mainLoop.OperatorGraph.Iterate().OfType<StochasticBranch>())
    106         stochasticBranch.RandomParameter.ActualName = "LocalRandom";
    107 
    108       // Remove unused operators
    109       var usedOperators = mainLoop.OperatorGraph.Iterate();
    110       var unusedOperators = mainLoop.OperatorGraph.Operators.Except(usedOperators);
    111       foreach (var op in unusedOperators.ToList())
    112         mainLoop.OperatorGraph.Operators.Remove(op);
    113 
    114       return mainLoop;
     233
     234      ageIncrementor.ValueParameter.ActualName = AgeParameter.Name;
     235      ageIncrementor.IncrementParameter.Value = null;
     236      ageIncrementor.IncrementParameter.ActualName = AgeIncrementParameter.Name;
     237      ageIncrementor.Successor = null;
    115238    }
    116239  }
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/HeuristicLab.Algorithms.ALPS-3.3.csproj

    r13111 r13124  
    8080  </PropertyGroup>
    8181  <ItemGroup>
    82     <Reference Include="HeuristicLab.Algorithms.GeneticAlgorithm-3.3">
    83       <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Algorithms.GeneticAlgorithm-3.3.dll</HintPath>
    84     </Reference>
    8582    <Reference Include="HeuristicLab.Analysis-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    8683      <SpecificVersion>False</SpecificVersion>
     
    134131    <Compile Include="AlpsGeneticAlgorithmMainOperator.cs" />
    135132    <Compile Include="ReseedingController.cs" />
     133    <Compile Include="ResultsHistoryWiper.cs" />
    136134    <Compile Include="WeightingReducer.cs" />
    137135    <Compile Include="Analyzers\OldestAverageYoungestAgeAnalyzer.cs" />
     
    142140    <Compile Include="Analyzers\OldestAverageYoungestAgeCalculator.cs" />
    143141    <Compile Include="EldersSelector.cs" />
    144     <Compile Include="LayerCreator.cs" />
     142    <Compile Include="LastScopeCloner.cs" />
    145143    <Compile Include="MatingPoolCreator.cs" />
    146144    <Compile Include="Plugin.cs" />
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/LastScopeCloner.cs

    r13123 r13124  
    2222using System;
    2323using System.Linq;
    24 using HeuristicLab.Analysis;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
    27 using HeuristicLab.Data;
    2826using HeuristicLab.Operators;
    29 using HeuristicLab.Optimization;
    3027using HeuristicLab.Parameters;
    3128using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3229
    3330namespace HeuristicLab.Algorithms.ALPS {
    34   [Item("LayerCreator", "An operator which creates a new layer by cloning the current oldest one.")]
     31  [Item("LastScopeCloner", "An operator that creates a new scope by cloning the current last one.")]
    3532  [StorableClass]
    36   public sealed class LayerCreator : SingleSuccessorOperator {
    37     private ILookupParameter<IntValue> OpenLayersParameter {
    38       get { return (ILookupParameter<IntValue>)Parameters["OpenLayers"]; }
    39     }
    40     public OperatorParameter NewLayerOperatorParameter {
    41       get { return (OperatorParameter)Parameters["NewLayerOperator"]; }
     33  public sealed class LastScopeCloner : SingleSuccessorOperator {
     34    public OperatorParameter NewScopeOperatorParameter {
     35      get { return (OperatorParameter)Parameters["NewScopeOperator"]; }
    4236    }
    4337
    44     public IOperator NewLayerOperator {
    45       get { return NewLayerOperatorParameter.Value; }
    46       set { NewLayerOperatorParameter.Value = value; }
     38    public IOperator NewScopeOperator {
     39      get { return NewScopeOperatorParameter.Value; }
     40      set { NewScopeOperatorParameter.Value = value; }
    4741    }
    4842
    4943    [StorableConstructor]
    50     private LayerCreator(bool deserializing) : base(deserializing) { }
     44    private LastScopeCloner(bool deserializing) : base(deserializing) { }
    5145
    52     private LayerCreator(LayerCreator original, Cloner cloner)
     46    private LastScopeCloner(LastScopeCloner original, Cloner cloner)
    5347      : base(original, cloner) {
    5448    }
    55     public LayerCreator()
    56       : base() {
    57       Parameters.Add(new LookupParameter<IntValue>("OpenLayers"));
    58       Parameters.Add(new OperatorParameter("NewLayerOperator"));
     49    public override IDeepCloneable Clone(Cloner cloner) {
     50      return new LastScopeCloner(this, cloner);
    5951    }
    6052
    61     public override IDeepCloneable Clone(Cloner cloner) {
    62       return new LayerCreator(this, cloner);
     53    public LastScopeCloner()
     54      : base() {
     55      Parameters.Add(new OperatorParameter("NewScopeOperator", "An Operator that is performed on the new scope."));
    6356    }
    6457
    6558    public override IOperation Apply() {
    66       var layersScope = ExecutionContext.Scope.SubScopes;
    67       if (layersScope.Count < 1)
     59      var scopes = ExecutionContext.Scope.SubScopes;
     60      if (scopes.Count < 1)
    6861        throw new ArgumentException("At least one layer must exist.");
    6962
    70       var newLayer = (IScope)layersScope.Last().Clone();
     63      var newScope = (IScope)scopes.Last().Clone();
    7164
    72       int number;
    73       if (int.TryParse(newLayer.Name, out number))
    74         newLayer.Name = (number + 1).ToString();
     65      int scopeNumber;
     66      if (int.TryParse(newScope.Name, out scopeNumber))
     67        newScope.Name = (scopeNumber + 1).ToString();
    7568
    76       layersScope.Add(newLayer);
     69      scopes.Add(newScope);
    7770
    78       // Set new layer number
    79       newLayer.Variables["Layer"].Value = new IntValue(OpenLayersParameter.ActualValue.Value);
    80 
    81       // Decrement ages, because MainOperator is goint to increment it
    82       foreach (var solution in newLayer.SubScopes)
    83         ((DoubleValue)solution.Variables["Age"].Value).Value -= 1;
    84 
    85       // Reset existing values in the results to NaN to symbolize that no layer existed during that duration
    86       var results = (ResultCollection)newLayer.Variables["LayerResults"].Value;
    87       ResetResults(results);
    8871
    8972      var next = new OperationCollection(base.Apply());
    90       next.Insert(0, ExecutionContext.CreateChildOperation(NewLayerOperator, newLayer));
     73      next.Insert(0, ExecutionContext.CreateChildOperation(NewScopeOperator, newScope));
    9174      return next;
    92     }
    93 
    94     private void ResetResults(ResultCollection results) {
    95       var values = results.Select(r => r.Value);
    96 
    97       // Reset all values within results in results
    98       foreach (var resultsCollection in values.OfType<ResultCollection>())
    99         ResetResults(resultsCollection);
    100 
    101       // Reset values
    102       foreach (var dataTable in values.OfType<DataTable>()) {
    103         foreach (var row in dataTable.Rows)
    104           for (int i = 0; i < row.Values.Count; i++)
    105             row.Values[i] = double.NaN;
    106       }
    10775    }
    10876  }
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/MatingPoolCreator.cs

    r13031 r13124  
    3232  public sealed class MatingPoolCreator : SingleSuccessorOperator {
    3333
    34     public ILookupParameter<IntValue> MatingPoolRangeParameter {
    35       get { return (ILookupParameter<IntValue>)Parameters["MatingPoolRange"]; }
     34    public IValueLookupParameter<IntValue> MatingPoolRangeParameter {
     35      get { return (IValueLookupParameter<IntValue>)Parameters["MatingPoolRange"]; }
    3636    }
    3737
     
    4646    public MatingPoolCreator()
    4747      : base() {
    48       Parameters.Add(new LookupParameter<IntValue>("MatingPoolRange"));
     48      Parameters.Add(new ValueLookupParameter<IntValue>("MatingPoolRange", "The range of sub-populations used for creating a mating pool. (1 = current + previous sub-population", new IntValue(1)));
    4949    }
    5050
     51    /// <summary>
     52    /// Copies the subscopes of the n previous scope into the current scope. (default n = 1)
     53    /// <pre>
     54    ///          __ scope __              __ scope __
     55    ///         /     |     \            /     |     \
     56    ///       Pop1   Pop2   Pop3  =>   Pop1   Pop2   Pop3
     57    ///       /|\    /|\    /|\         /|\    /|\   /|\
     58    ///       ABC    DEF    GHI         ABC    DEF   GHI
     59    ///                                        ABC   DEF
     60    /// </pre>
     61    /// </summary>
     62    /// <returns>The next operation.</returns>
    5163    public override IOperation Apply() {
    52       var layers = ExecutionContext.Scope.SubScopes;
     64      var subScopes = ExecutionContext.Scope.SubScopes;
    5365      int range = MatingPoolRangeParameter.ActualValue.Value;
    5466
    55       for (int layer = layers.Count - 1; layer > 0; layer--) {
    56         var layerScope = layers[layer];
    57         for (int n = 1; (n <= range) && (layer - n >= 0); n++) {
    58           var prevLayerScope = layers[layer - n];
    59           var individuals = prevLayerScope.SubScopes;
     67      for (int targetIndex = subScopes.Count - 1; targetIndex > 0; targetIndex--) {
     68        var targetScope = subScopes[targetIndex];
     69        for (int n = 1; (n <= range) && (targetIndex - n >= 0); n++) {
     70          var prevScope = subScopes[targetIndex - n];
     71          var individuals = prevScope.SubScopes;
    6072          foreach (var individual in individuals) {
    61             layerScope.SubScopes.Add((IScope)individual.Clone(new Cloner()));
     73            targetScope.SubScopes.Add((IScope)individual.Clone(new Cloner()));
    6274          }
    6375        }
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/Plugin.cs.frame

    r12994 r13124  
    4040  [PluginDependency("HeuristicLab.Random", "3.3")]
    4141  [PluginDependency("HeuristicLab.Selection", "3.3")]
    42   [PluginDependency("HeuristicLab.Algorithms.GeneticAlgorithm", "3.3")]
    4342  public class HeuristicLabAlgorithmsALPSPlugin : PluginBase {
    4443  }
Note: See TracChangeset for help on using the changeset viewer.