Changeset 11586


Ignore:
Timestamp:
11/26/14 11:06:38 (4 years ago)
Author:
pfleck
Message:

#2269 Implemented LayerUpdator.

  • Added First/LastSubScopeProcessor.
  • Added two Calculators because ExpressionCalculator does not support required features yet.
  • Added some wiring.
  • Small bugfixes and refactorings.
Location:
branches/ALPS
Files:
5 added
9 edited

Legend:

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

    r11585 r11586  
    217217      Parameters.Add(new ValueParameter<AgingScheme>("AgingScheme", "The aging scheme for setting the age-limits for the layers.", new AgingScheme(AgingSchemes.Polynomial)));
    218218      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(5)));
    219       Parameters.Add(new ValueParameter<IntArray>("AgeLimits", new IntArray(new[] { 1, 20, 45, 80, 125 })) { Hidden = true });
     219      Parameters.Add(new ValueParameter<IntArray>("AgeLimits", new IntArray(new[] { 5, 20, 45, 80, 125 })) { Hidden = true });
    220220      Parameters.Add(new ValueParameter<ReductionOperation>("AgeInheritance", "The operator for determining the age of an offspring based the parents' age.", new ReductionOperation(ReductionOperations.Max)) { Hidden = true });
    221221      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
     
    373373      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
    374374      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
     375      MainLoop.EldersEmigrator.SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
     376      MainLoop.EldersEmigrator.SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
     377
    375378    }
    376379    private void ParameterizeMainLoop() {
     
    382385      MainLoop.MainOperator.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    383386      MainLoop.MainOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     387      MainLoop.EldersEmigrator.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
     388      MainLoop.EldersEmigrator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    384389    }
    385390    private void ParameterizeSelectors() {
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs

    r11585 r11586  
    3838  public sealed class AlpsGeneticAlgorithmMainLoop : AlgorithmOperator {
    3939    #region Parameter Properties
    40     public ILookupParameter<IRandom> RandomParameter {
    41       get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    42     }
    43     /*public ILookupParameter<BoolValue> MaximizationParameter {
    44       get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
    45     }
    46     public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
    47       get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
    48     }
    49     public ILookupParameter<DoubleValue> BestKnownQualityParameter {
    50       get { return (ILookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
    51     }
    52     public ILookupParameter<IOperator> EvaluatorParameter {
    53       get { return (ILookupParameter<IOperator>)Parameters["Evaluator"]; }
    54     }*/
    55     public ILookupParameter<IntValue> PopulationSizeParameter {
    56       get { return (ILookupParameter<IntValue>)Parameters["PopulationSize"]; }
    57     }
    5840    public ILookupParameter<IntValue> MaximumGenerationsParameter {
    5941      get { return (ILookupParameter<IntValue>)Parameters["MaximumGenerations"]; }
    60     }
    61     public ILookupParameter<IOperator> SelectorParameter {
    62       get { return (ILookupParameter<IOperator>)Parameters["Selector"]; }
    63     }
    64     public ILookupParameter<IOperator> CrossoverParameter {
    65       get { return (ILookupParameter<IOperator>)Parameters["Crossover"]; }
    66     }
    67     public ILookupParameter<PercentValue> MutationProbabilityParameter {
    68       get { return (ILookupParameter<PercentValue>)Parameters["MutationProbability"]; }
    69     }
    70     public ILookupParameter<IOperator> MutatorParameter {
    71       get { return (ILookupParameter<IOperator>)Parameters["Mutator"]; }
    72     }
    73     public ILookupParameter<IntValue> ElitesParameter {
    74       get { return (ILookupParameter<IntValue>)Parameters["Elites"]; }
    75     }
    76     public IValueLookupParameter<BoolValue> ReevaluateElitesParameter {
    77       get { return (IValueLookupParameter<BoolValue>)Parameters["ReevaluateElites"]; }
    78     }
    79     public ILookupParameter<ResultCollection> ResultsParameter {
    80       get { return (ILookupParameter<ResultCollection>)Parameters["Results"]; }
    8142    }
    8243    public ILookupParameter<IOperator> AnalyzerParameter {
     
    9152      get { return OperatorGraph.Iterate().OfType<GeneticAlgorithmMainLoop>().First(); }
    9253    }
     54    public EldersEmigrator EldersEmigrator {
     55      get { return OperatorGraph.Iterate().OfType<EldersEmigrator>().First(); }
     56    }
    9357
    9458    [StorableConstructor]
     
    10266    public AlpsGeneticAlgorithmMainLoop()
    10367      : base() {
    104       Parameters.Add(new LookupParameter<IRandom>("Random", "A pseudo random number generator."));
    105       /*Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
    106       Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
    107       Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
    108       Parameters.Add(new LookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions."));*/
    109       Parameters.Add(new LookupParameter<IntValue>("PopulationSize", "The size of the population of solutions."));
    11068      Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations that the algorithm should process."));
    111       Parameters.Add(new LookupParameter<IOperator>("Selector", "The operator used to select solutions for reproduction."));
    112       Parameters.Add(new LookupParameter<IOperator>("Crossover", "The operator used to cross solutions."));
    113       Parameters.Add(new LookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
    114       Parameters.Add(new LookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
    115       Parameters.Add(new LookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
    116       Parameters.Add(new LookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
    117       Parameters.Add(new LookupParameter<ResultCollection>("Results", "The results collection to store the results."));
    11869      Parameters.Add(new LookupParameter<IOperator>("Analyzer", "The operator used to the analyze all individuals."));
    11970      Parameters.Add(new LookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each layer."));
     
    12677      var matingPoolCreator = new MatingPoolCreator() { Name = "Create Mating Pools" };
    12778      var matingPoolProcessor = new UniformSubScopesProcessor();
    128       var mainOperator = PrepareGeneticAlgorithmMainLoop();
     79      var mainOperator = CreatePreparedGeneticAlgorithmMainLoop();
    12980      var layerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
    13081      var generationsIcrementor = new IntCounter() { Name = "Increment Generations" };
    13182      var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" };
    13283      var eldersEmigrator = new EldersEmigrator() { Name = "Emigrate Elders" };
    133       var layerUpdator = new CombinedOperator() { Name = "Update Layers" };
     84      var layerUpdator = new LayerUpdator(mainOperator) { Name = "Update Layers" };
    13485      var analyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" };
    13586      var generationsComparator = new Comparator() { Name = "Generations >= MaximumGenerations" };
     
    14091      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("Generations", new IntValue(0)));
    14192      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("GenerationsSinceLastRefresh", new IntValue(0)));
     93      variableCreator.CollectedValues.Add(new ValueParameter<IntValue>("OpenLayers", new IntValue(1)));
    14294      variableCreator.Successor = resultsCollector;
    14395
     
    193145    }
    194146
    195     private GeneticAlgorithmMainLoop PrepareGeneticAlgorithmMainLoop() {
     147    private GeneticAlgorithmMainLoop CreatePreparedGeneticAlgorithmMainLoop() {
    196148      var mainLoop = new GeneticAlgorithmMainLoop();
    197149      var selector = mainLoop.OperatorGraph.Iterate().OfType<Placeholder>().First(o => o.OperatorParameter.ActualName == "Selector");
     
    228180        stochasticBranch.RandomParameter.ActualName = "LocalRandom";
    229181
    230       // Remove unnessesary subtrees
    231       //foreach (var @operator in mainLoop.OperatorGraph.Operators.OfType<SingleSuccessorOperator>().Where(o => o.Successor == selector))
    232       //  @operator.Successor = null;
    233 
    234182      return mainLoop;
    235183    }
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/EldersEmigrator.cs

    r11585 r11586  
    2020#endregion
    2121
     22using System.Linq;
    2223using HeuristicLab.Common;
    2324using HeuristicLab.Core;
     
    3233  [Item("EldersEmigrator", "Moves Individuals which are too old for its current layer up to the next layer.")]
    3334  [StorableClass]
    34   public class EldersEmigrator : AlgorithmOperator {
     35  public sealed class EldersEmigrator : AlgorithmOperator {
     36
     37    public IValueLookupParameter<BoolValue> MaximizationParameter {
     38      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     39    }
     40    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
     41      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
     42    }
     43
     44    public SolutionsCreator SolutionsCreator {
     45      get { return OperatorGraph.Iterate().OfType<SolutionsCreator>().First(); }
     46    }
    3547
    3648    [StorableConstructor]
     
    4456    public EldersEmigrator()
    4557      : base() {
     58      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
     59      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
     60
    4661      var selectorProsessor = new UniformSubScopesProcessor();
    4762      var eldersSelector = new EldersSelector();
     
    5065      var mergingReducer = new MergingReducer();
    5166      var subScopesCounter = new SubScopesCounter();
    52       var countCalculator = new ExpressionCalculator() { Name = "Count = Min(NumSubScopes, PopulationSize)" };
     67      // TODO: if expression calculator supports int, use expression calculator
     68      var countCalculator = new MergingReducerCalculator() { Name = "NumSubScopes = Min(NumSubScopes, PopulationSize)" };
     69      //var countCalculator = new ExpressionCalculator() { Name = "NumSubScopes = Min(NumSubScopes, PopulationSize)" };
    5370      var bestSelector = new BestSelector();
    5471      var rightReducer = new RightReducer();
     
    7390      subScopesCounter.Successor = countCalculator;
    7491
    75       countCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize"));
    76       countCalculator.CollectedValues.Add(new LookupParameter<IntValue>("NumSubScopes"));
    77       countCalculator.ExpressionParameter.Value = new StringValue("NumSubScopes PopulationSize NumSubScopes < PopulationSize if");
    78       countCalculator.ExpressionResultParameter.ActualName = "Count";
     92      //countCalculator.CollectedValues.Add(new LookupParameter<IntValue>("PopulationSize"));
     93      //countCalculator.CollectedValues.Add(new LookupParameter<IntValue>("NumSubScopes"));
     94      //countCalculator.ExpressionParameter.Value = new StringValue("NumSubScopes PopulationSize NumSubScopes PopulationSize < if");
     95      //countCalculator.ExpressionResultParameter.ActualName = "NumSubScopes";
    7996      countCalculator.Successor = bestSelector;
    8097
    81       bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "Count";
     98      bestSelector.NumberOfSelectedSubScopesParameter.ActualName = "NumSubScopes";
     99      bestSelector.QualityParameter.ActualName = QualityParameter.Name;
     100      bestSelector.MaximizationParameter.ActualName = MaximizationParameter.Name;
    82101      bestSelector.Successor = rightReducer;
    83102
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/EldersSelector.cs

    r11585 r11586  
    3333  [Item("EldersSelector", "Select all individuals which are to old for their current layer.")]
    3434  [StorableClass]
    35   public class EldersSelector : SingleObjectiveSelector {
     35  public sealed class EldersSelector : SingleObjectiveSelector {
    3636
    3737    private ILookupParameter<IntArray> AgeLimitsParameter {
     
    4040    private ILookupParameter<IntValue> NumberOfLayersParameter {
    4141      get { return (ILookupParameter<IntValue>)Parameters["NumberOfLayers"]; }
     42    }
     43    private ILookupParameter<IntValue> LayerParameter {
     44      get { return (ILookupParameter<IntValue>)Parameters["Layer"]; }
    4245    }
    4346
     
    5356      : base() {
    5457      Parameters.Add(new LookupParameter<IntArray>("AgeLimits"));
     58      Parameters.Add(new LookupParameter<IntValue>("NumberOfLayers"));
     59      Parameters.Add(new LookupParameter<IntValue>("Layer"));
    5560    }
    5661
     
    5863      var ageLimits = AgeLimitsParameter.ActualValue;
    5964      int numberOfLayers = NumberOfLayersParameter.ActualValue.Value;
     65      int layer = LayerParameter.ActualValue.Value;
    6066
    61       int layer = ((IntValue)CurrentScope.Variables["Layer"]).Value;
    62 
    63       if (layer >= numberOfLayers)
     67      if (layer >= numberOfLayers) // is max layer?
    6468        return new IScope[0];
    6569
     
    6771      var elders =
    6872        from scope in scopes
    69         let age = ((IntValue)scope.Variables["Age"]).Value
     73        let age = ((IntValue)scope.Variables["Age"].Value).Value
    7074        where age > limit
    7175        select scope;
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/HeuristicLab.Algorithms.ALPS-3.3.csproj

    r11585 r11586  
    8383    <Compile Include="EldersEmigrator.cs" />
    8484    <Compile Include="EldersSelector.cs" />
     85    <Compile Include="LayerUpdator.cs" />
    8586    <Compile Include="MatingPoolCreator.cs" />
     87    <Compile Include="OpenNewLayerCalculator.cs" />
     88    <Compile Include="MergingReducerCalculator.cs" />
    8689    <Compile Include="Plugin.cs" />
    8790    <Compile Include="Properties\AssemblyInfo.cs" />
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/MatingPoolCreator.cs

    r11583 r11586  
    2020#endregion
    2121
    22 using System.Linq;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
     
    4645      var subPopulations = ExecutionContext.Scope.SubScopes;
    4746
    48       for (int i = subPopulations.Count - 1; i >= 0; i++) {
     47      for (int i = subPopulations.Count - 1; i > 0; i++) {
    4948        var currentSubPopulation = subPopulations[i].SubScopes;
    50         var prevSubPopulation = i > 0 ? subPopulations[i - 1].SubScopes : Enumerable.Empty<IScope>();
     49        var prevSubPopulation = subPopulations[i - 1].SubScopes;
    5150
    52         foreach (var individual in prevSubPopulation) {
     51        foreach (var individual in prevSubPopulation)
    5352          currentSubPopulation.Add(individual);
    54         }
    5553      }
     54
    5655      return base.Apply();
    5756    }
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/ShiftToRightMigrator.cs

    r11585 r11586  
    2929
    3030namespace HeuristicLab.Algorithms.ALPS {
    31   [Item("ShiftToRightMigrator", "Migrates the selected sub scopes by shifting it to the next(right) subscope.")]
     31  [Item("ShiftToRightMigrator", "Migrates the selected sub scopes by shifting them to the next(right) subscope.")]
    3232  [StorableClass]
    33   public class ShiftToRightMigrator : SingleSuccessorOperator, IMigrator {
     33  public sealed class ShiftToRightMigrator : SingleSuccessorOperator, IMigrator {
    3434
    3535    [StorableConstructor]
     
    5959      emigrantsList.RemoveAt(emigrantsList.Count - 1);
    6060
    61       for (int i = 0; i < scope.SubScopes.Count; i++) {
     61      for (int i = 0; i < scope.SubScopes.Count; i++)
    6262        scope.SubScopes[i].SubScopes.Add(emigrantsList[i]);
    63       }
    6463
    6564      return base.Apply();
  • branches/ALPS/HeuristicLab.Operators/3.3/HeuristicLab.Operators-3.3.csproj

    r11558 r11586  
    113113    <Compile Include="CheckedMultiOperator.cs" />
    114114    <Compile Include="CombinedOperator.cs" />
     115    <Compile Include="LastSubScopeProcessor.cs" />
     116    <Compile Include="FirstSubScopeProcessor.cs" />
    115117    <Compile Include="Operator.InstrumentedOperatorWrapper.cs" />
    116118    <None Include="Plugin.cs.frame" />
  • branches/ALPS/HeuristicLab.Optimization.Operators/3.3/ExpressionCalculator.cs

    r11171 r11586  
    7878predicates:
    7979  ==, <, >, isnull, not
     80array index:
     81  []
    8082stack manipulation:
    8183  drop swap dup
Note: See TracChangeset for help on using the changeset viewer.