Free cookie consent management tool by TermsFeed Policy Generator

Changeset 11583


Ignore:
Timestamp:
11/25/14 13:46:50 (10 years ago)
Author:
pfleck
Message:

#2269

  • Implemented MatingPoolCreator.
  • Added a modified GeneticAlgorithMainLoop as main operator in ALPS-GA-MainLoop.
Location:
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3
Files:
1 added
4 edited

Legend:

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

    r11580 r11583  
    3939  [Creatable("Algorithms")]
    4040  [StorableClass]
    41   public class AlpsGeneticAlgorithm : HeuristicOptimizationEngineAlgorithm, IStorableContent {
     41  public sealed class AlpsGeneticAlgorithm : HeuristicOptimizationEngineAlgorithm, IStorableContent {
    4242    public string Filename { get; set; }
    4343
     
    371371    }
    372372    private void ParameterizeMainLoop() {
    373       MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
    374       MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
    375       MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
    376       MainLoop.BestKnownQualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     373      //MainLoop.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
     374      //MainLoop.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
     375      //MainLoop.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
     376      //MainLoop.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     377      MainLoop.MainOperator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
     378      MainLoop.MainOperator.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
     379      MainLoop.MainOperator.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    377380    }
    378381    private void ParameterizeSelectors() {
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsGeneticAlgorithmMainLoop.cs

    r11580 r11583  
    2020#endregion
    2121
     22using System.Linq;
     23using HeuristicLab.Algorithms.GeneticAlgorithm;
    2224using HeuristicLab.Common;
    2325using HeuristicLab.Core;
     
    2830using HeuristicLab.Parameters;
    2931using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     32using HeuristicLab.Selection;
    3033
    3134namespace HeuristicLab.Algorithms.ALPS {
    3235
    3336  [Item("AlpsGeneticAlgorithmMainLoop", "An ALPS genetic algorithm main loop operator.")]
    34   public class AlpsGeneticAlgorithmMainLoop : AlgorithmOperator {
     37  public sealed class AlpsGeneticAlgorithmMainLoop : AlgorithmOperator {
    3538    #region Parameter Properties
    3639    public ILookupParameter<IRandom> RandomParameter {
    3740      get { return (ILookupParameter<IRandom>)Parameters["Random"]; }
    3841    }
    39     public ILookupParameter<BoolValue> MaximizationParameter {
     42    /*public ILookupParameter<BoolValue> MaximizationParameter {
    4043      get { return (ILookupParameter<BoolValue>)Parameters["Maximization"]; }
    4144    }
     
    4649      get { return (ILookupParameter<DoubleValue>)Parameters["BestKnownQuality"]; }
    4750    }
     51    public ILookupParameter<IOperator> EvaluatorParameter {
     52      get { return (ILookupParameter<IOperator>)Parameters["Evaluator"]; }
     53    }*/
    4854    public ILookupParameter<IntValue> PopulationSizeParameter {
    4955      get { return (ILookupParameter<IntValue>)Parameters["PopulationSize"]; }
     
    6470      get { return (ILookupParameter<IOperator>)Parameters["Mutator"]; }
    6571    }
    66     public ILookupParameter<IOperator> EvaluatorParameter {
    67       get { return (ILookupParameter<IOperator>)Parameters["Evaluator"]; }
    68     }
    6972    public ILookupParameter<IntValue> ElitesParameter {
    7073      get { return (ILookupParameter<IntValue>)Parameters["Elites"]; }
     
    8386    }
    8487    #endregion
     88
     89    public GeneticAlgorithmMainLoop MainOperator {
     90      get { return OperatorGraph.Iterate().OfType<GeneticAlgorithmMainLoop>().First(); }
     91    }
    8592
    8693    [StorableConstructor]
     
    95102      : base() {
    96103      Parameters.Add(new LookupParameter<IRandom>("Random", "A pseudo random number generator."));
    97       Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
     104      /*Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem is a maximization problem, otherwise false."));
    98105      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The value which represents the quality of a solution."));
    99106      Parameters.Add(new LookupParameter<DoubleValue>("BestKnownQuality", "The best known quality value found so far."));
     107      Parameters.Add(new LookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions."));*/
    100108      Parameters.Add(new LookupParameter<IntValue>("PopulationSize", "The size of the population of solutions."));
    101109      Parameters.Add(new LookupParameter<IntValue>("MaximumGenerations", "The maximum number of generations that the algorithm should process."));
     
    104112      Parameters.Add(new LookupParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution."));
    105113      Parameters.Add(new LookupParameter<IOperator>("Mutator", "The operator used to mutate solutions."));
    106       Parameters.Add(new LookupParameter<IOperator>("Evaluator", "The operator used to evaluate solutions."));
    107114      Parameters.Add(new LookupParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation."));
    108115      Parameters.Add(new LookupParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)"));
     
    111118      Parameters.Add(new LookupParameter<IOperator>("LayerAnalyzer", "The operator used to analyze each layer."));
    112119
    113 
    114120      var variableCreator = new VariableCreator() { Name = "Initialize" };
    115121      var resultsCollector = new ResultsCollector();
     
    117123      var initLayerAnalyzerProcessor = new SubScopesProcessor();
    118124      var initLayerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
    119       var matingPoolCreator = new CombinedOperator() { Name = "Create Mating Pools" };
     125      var matingPoolCreator = new MatingPoolCreator() { Name = "Create Mating Pools" };
    120126      var matingPoolProcessor = new UniformSubScopesProcessor();
    121       var mainOperator = new CombinedOperator() { Name = "Perform Generation" };
     127      var mainOperator = PrepareGeneticAlgorithmMainLoop();
    122128      var layerAnalyzerPlaceholder = new Placeholder() { Name = "LayerAnalyzer (Placeholder)" };
     129      var generationsIcrementor = new IntCounter() { Name = "Increment Generations" };
     130      var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" };
    123131      var eldersEmigrator = new CombinedOperator() { Name = "Emigrate Elders" };
    124132      var layerUpdator = new CombinedOperator() { Name = "Update Layers" };
     
    150158      matingPoolProcessor.Parallel.Value = true;
    151159      matingPoolProcessor.Operator = mainOperator;
    152       matingPoolProcessor.Successor = eldersEmigrator;
     160      matingPoolProcessor.Successor = generationsIcrementor;
     161
     162      generationsIcrementor.ValueParameter.ActualName = "Generations";
     163      generationsIcrementor.Increment = new IntValue(1);
     164      generationsIcrementor.Successor = evaluatedSolutionsReducer;
     165
     166      evaluatedSolutionsReducer.ParameterToReduce.ActualName = "EvaluatedSolutions";
     167      evaluatedSolutionsReducer.TargetParameter.ActualName = "EvaluatedSolutions";
     168      evaluatedSolutionsReducer.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Sum);
     169      evaluatedSolutionsReducer.TargetOperation.Value = new ReductionOperation(ReductionOperations.Sum);
     170      evaluatedSolutionsReducer.Successor = eldersEmigrator;
    153171
    154172      mainOperator.Successor = layerAnalyzerPlaceholder;
     
    170188      generationsComparator.Successor = terminateBranch;
    171189
    172       terminateBranch.ConditionParameter.ActualName = "Terminategenerations";
     190      terminateBranch.ConditionParameter.ActualName = "TerminateGenerations";
    173191      terminateBranch.FalseBranch = matingPoolCreator;
    174 
    175     }
    176 
     192    }
     193
     194    private GeneticAlgorithmMainLoop PrepareGeneticAlgorithmMainLoop() {
     195      var mainLoop = new GeneticAlgorithmMainLoop();
     196      var selector = mainLoop.OperatorGraph.Iterate().OfType<Placeholder>().First(o => o.OperatorParameter.ActualName == "Selector");
     197      var crossover = mainLoop.OperatorGraph.Iterate().OfType<Placeholder>().First(o => o.OperatorParameter.ActualName == "Crossover");
     198      var elitesMerger = mainLoop.OperatorGraph.Iterate().OfType<MergingReducer>().First();
     199
     200      // Operator starts with selector
     201      mainLoop.OperatorGraph.InitialOperator = selector;
     202
     203      // Insert AgeCalculator between crossover and its successor
     204      var crossoverSuccessor = crossover.Successor;
     205      var ageCalculator = new DataReducer() { Name = "Calculate Age" };
     206      ageCalculator.ParameterToReduce.ActualName = "Age";
     207      ageCalculator.TargetParameter.ActualName = "Age";
     208      ageCalculator.ReductionOperation.Value = new ReductionOperation(ReductionOperations.Max);
     209      ageCalculator.TargetOperation.Value = new ReductionOperation(ReductionOperations.Assign);
     210      crossover.Successor = ageCalculator;
     211      ageCalculator.Successor = crossoverSuccessor;
     212
     213      // Instead of generational loop after merging of elites, increment ages of all individuals
     214      var processor = new UniformSubScopesProcessor();
     215      var incrementor = new IntCounter() { Name = "Increment Age" };
     216      processor.Operator = incrementor;
     217      processor.Successor = null;
     218      incrementor.ValueParameter.ActualName = "Age";
     219      incrementor.Increment = new IntValue(1);
     220      incrementor.Successor = null;
     221      elitesMerger.Successor = processor;
     222
     223      // Parameterize
     224      foreach (var stochasticOperator in mainLoop.OperatorGraph.Iterate().OfType<IStochasticOperator>())
     225        stochasticOperator.RandomParameter.ActualName = "LocalRandom";
     226      foreach (var stochasticBranch in mainLoop.OperatorGraph.Iterate().OfType<StochasticBranch>())
     227        stochasticBranch.RandomParameter.ActualName = "LocalRandom";
     228
     229      // Remove unnessesary subtrees
     230      //foreach (var @operator in mainLoop.OperatorGraph.Iterate().OfType<SingleSuccessorOperator>().Where(o => o.Successor == selector))
     231      //  @operator.Successor = null;
     232
     233      return mainLoop;
     234    }
    177235  }
    178236}
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/HeuristicLab.Algorithms.ALPS-3.3.csproj

    r11580 r11583  
    8181    <Compile Include="AlpsGeneticAlgorithm.cs" />
    8282    <Compile Include="AlpsGeneticAlgorithmMainLoop.cs" />
     83    <Compile Include="MatingPoolCreator.cs" />
    8384    <Compile Include="Plugin.cs" />
    8485    <Compile Include="Properties\AssemblyInfo.cs" />
     
    9091  </ItemGroup>
    9192  <ItemGroup>
     93    <ProjectReference Include="..\..\HeuristicLab.Algorithms.GeneticAlgorithm\3.3\HeuristicLab.Algorithms.GeneticAlgorithm-3.3.csproj">
     94      <Project>{a51da44f-cb35-4f6f-99f5-2a2e904ab93b}</Project>
     95      <Name>HeuristicLab.Algorithms.GeneticAlgorithm-3.3</Name>
     96    </ProjectReference>
    9297    <ProjectReference Include="..\..\HeuristicLab.Analysis\3.3\HeuristicLab.Analysis-3.3.csproj">
    9398      <Project>{887425b4-4348-49ed-a457-b7d2c26ddbf9}</Project>
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/Plugin.cs.frame

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