Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/25/17 13:53:11 (7 years ago)
Author:
pfleck
Message:

#2849: AlpsOs2 with a ContinuousMatingPoolCreator

Location:
branches/Enhanced OSALPS/HeuristicLab.Algorithms.ALPS/3.3
Files:
3 added
2 edited
3 copied

Legend:

Unmodified
Added
Removed
  • branches/Enhanced OSALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsOs2MainLoop.cs

    r15429 r15432  
    3232namespace HeuristicLab.Algorithms.ALPS {
    3333
    34   [Item("AlpsOffspringSelectionGeneticAlgorithmMainLoop", "An ALPS offspring selection genetic algorithm main loop operator.")]
     34  [Item("AlpsOs2MainLoop", "An ALPS offspring selection genetic algorithm main loop operator.")]
    3535  [StorableClass]
    36   public sealed class AlpsOffspringSelectionGeneticAlgorithmMainLoop : AlgorithmOperator {
     36  public sealed class AlpsOs2MainLoop : AlgorithmOperator {
    3737    #region Parameter Properties
    3838    public IValueLookupParameter<IRandom> GlobalRandomParameter {
     
    121121    }
    122122
    123     public IValueLookupParameter<IntValue> MatingPoolRangeParameter {
    124       get { return (IValueLookupParameter<IntValue>)Parameters["MatingPoolRange"]; }
     123    public IValueLookupParameter<DoubleArray> MatingPoolRangesParameter {
     124      get { return (IValueLookupParameter<DoubleArray>)Parameters["MatingPoolRanges"]; }
    125125    }
    126126    public IValueLookupParameter<BoolValue> ReduceToPopulationSizeParameter {
     
    133133    #endregion
    134134
    135     [StorableConstructor]
    136     private AlpsOffspringSelectionGeneticAlgorithmMainLoop(bool deserializing)
    137       : base(deserializing) { }
    138     private AlpsOffspringSelectionGeneticAlgorithmMainLoop(AlpsOffspringSelectionGeneticAlgorithmMainLoop original, Cloner cloner)
    139       : base(original, cloner) { }
    140     public override IDeepCloneable Clone(Cloner cloner) {
    141       return new AlpsOffspringSelectionGeneticAlgorithmMainLoop(this, cloner);
    142     }
    143     public AlpsOffspringSelectionGeneticAlgorithmMainLoop()
     135    #region Constructor, Cloning & Persistence
     136    public AlpsOs2MainLoop()
    144137      : base() {
    145138      Parameters.Add(new ValueLookupParameter<IRandom>("GlobalRandom", "A pseudo random number generator."));
     
    176169      Parameters.Add(new ValueLookupParameter<IntArray>("AgeLimits", "The maximum age an individual is allowed to reach in a certain layer."));
    177170
    178       Parameters.Add(new ValueLookupParameter<IntValue>("MatingPoolRange", "The range of sub - populations used for creating a mating pool. (1 = current + previous sub-population)"));
     171      Parameters.Add(new ValueLookupParameter<DoubleArray>("MatingPoolRanges", "The range of sub-populations used for creating a mating pool. (1 = current + previous sub-population)"));
    179172      Parameters.Add(new ValueLookupParameter<BoolValue>("ReduceToPopulationSize", "Reduce the CurrentPopulationSize after elder migration to PopulationSize"));
    180173
     
    189182      var initAnalyzerPlaceholder = new Placeholder() { Name = "Analyzer (Placeholder)" };
    190183      var resultsCollector = new ResultsCollector();
    191       var matingPoolCreator = new MatingPoolCreator() { Name = "Create Mating Pools" };
     184      var matingPoolCreator = new ContinuousMatingPoolCreator() { Name = "Create Mating Pools" };
    192185      var matingPoolProcessor = new UniformSubScopesProcessor() { Name = "Process Mating Pools" };
    193186      var initializeLayer = new Assigner() { Name = "Reset LayerEvaluatedSolutions" };
    194       var mainOperator = new AlpsOffspringSelectionGeneticAlgorithmMainOperator();
     187      var mainOperator = new AlpsOs2MainOperator();
    195188      var generationsIcrementor = new IntCounter() { Name = "Increment Generations" };
    196189      var evaluatedSolutionsReducer = new DataReducer() { Name = "Increment EvaluatedSolutions" };
     
    235228      resultsCollector.Successor = matingPoolCreator;
    236229
    237       matingPoolCreator.MatingPoolRangeParameter.Value = null;
    238       matingPoolCreator.MatingPoolRangeParameter.ActualName = MatingPoolRangeParameter.Name;
     230      matingPoolCreator.RangesParameter.ActualName = MatingPoolRangesParameter.Name;
     231      matingPoolCreator.QualityParameter.ActualName = QualityParameter.Name;
     232      matingPoolCreator.MaximizationParameter.ActualName = MaximizationParameter.Name;
    239233      matingPoolCreator.Successor = matingPoolProcessor;
    240234
     
    466460      return reseeder;
    467461    }
     462
     463    public override IDeepCloneable Clone(Cloner cloner) {
     464      return new AlpsOs2MainLoop(this, cloner);
     465    }
     466    private AlpsOs2MainLoop(AlpsOs2MainLoop original, Cloner cloner)
     467      : base(original, cloner) { }
     468
     469    [StorableConstructor]
     470    private AlpsOs2MainLoop(bool deserializing)
     471      : base(deserializing) { }
     472    #endregion
    468473  }
    469474}
  • branches/Enhanced OSALPS/HeuristicLab.Algorithms.ALPS/3.3/AlpsOs2MainOperator.cs

    r15429 r15432  
    3333  /// An operator which represents the main loop of an offspring selection genetic algorithm.
    3434  /// </summary>
    35   [Item("AlpsOffspringSelectionGeneticAlgorithmMainOperator", "An operator that represents the core of an alps offspring selection genetic algorithm.")]
     35  [Item("AlpsOs2MainOperator", "An operator that represents the core of an alps offspring selection genetic algorithm.")]
    3636  [StorableClass]
    37   public sealed class AlpsOffspringSelectionGeneticAlgorithmMainOperator : AlgorithmOperator {
     37  public sealed class AlpsOs2MainOperator : AlgorithmOperator {
    3838    #region Parameter properties
    3939    public IValueLookupParameter<IRandom> RandomParameter {
     
    109109    #endregion
    110110
    111     [StorableConstructor]
    112     private AlpsOffspringSelectionGeneticAlgorithmMainOperator(bool deserializing) : base(deserializing) { }
    113     private AlpsOffspringSelectionGeneticAlgorithmMainOperator(AlpsOffspringSelectionGeneticAlgorithmMainOperator original, Cloner cloner)
    114       : base(original, cloner) {
    115     }
    116     public override IDeepCloneable Clone(Cloner cloner) {
    117       return new AlpsOffspringSelectionGeneticAlgorithmMainOperator(this, cloner);
    118     }
    119     public AlpsOffspringSelectionGeneticAlgorithmMainOperator()
    120       : base() {
    121       Initialize();
    122     }
    123 
    124     private void Initialize() {
     111    #region Constructor, Cloning & Persistence
     112    public AlpsOs2MainOperator()
     113     : base() {
    125114      Parameters.Add(new ValueLookupParameter<IRandom>("Random", "A pseudo random number generator."));
    126115
     
    401390    }
    402391
     392    private AlpsOs2MainOperator(AlpsOs2MainOperator original, Cloner cloner)
     393      : base(original, cloner) {
     394    }
     395    public override IDeepCloneable Clone(Cloner cloner) {
     396      return new AlpsOs2MainOperator(this, cloner);
     397    }
     398
     399    [StorableConstructor]
     400    private AlpsOs2MainOperator(bool deserializing)
     401      : base(deserializing) { }
     402    #endregion
     403
    403404    public override IOperation Apply() {
    404405      if (CrossoverParameter.ActualValue == null)
  • branches/Enhanced OSALPS/HeuristicLab.Algorithms.ALPS/3.3/ContinuousMatingPoolCreator.cs

    r15429 r15432  
    2020#endregion
    2121
     22using System;
     23using System.Collections.Generic;
     24using System.Linq;
    2225using HeuristicLab.Common;
    2326using HeuristicLab.Core;
     
    2831
    2932namespace HeuristicLab.Algorithms.ALPS {
    30   [Item("MatingPoolCreator", "An operator which creates mating pools based on a set of sub-populations. For each sub-population, the individuals from the previous sub-population are copied into the current sub-population.")]
     33  [Item("ContinuousMatingPoolCreator", "An operator which creates mating pools based on a set of sub-populations. For each sub-population, the individuals from the previous sub-population are copied into the current sub-population.")]
    3134  [StorableClass]
    32   public sealed class MatingPoolCreator : SingleSuccessorOperator {
    33     public IValueLookupParameter<IntValue> MatingPoolRangeParameter {
    34       get { return (IValueLookupParameter<IntValue>)Parameters["MatingPoolRange"]; }
     35  public sealed class ContinuousMatingPoolCreator : SingleSuccessorOperator, IMatingPoolCreator {
     36    public IValueLookupParameter<DoubleArray> RangesParameter {
     37      get { return (IValueLookupParameter<DoubleArray>)Parameters["Ranges"]; }
     38    }
     39
     40    public IScopeTreeLookupParameter<DoubleValue> QualityParameter {
     41      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["Quality"]; }
     42    }
     43    public IValueLookupParameter<BoolValue> MaximizationParameter {
     44      get { return (IValueLookupParameter<BoolValue>)Parameters["Maximization"]; }
     45    }
     46
     47
     48    #region Constructor, Cloning & Persistence
     49    public ContinuousMatingPoolCreator()
     50      : base() {
     51      Parameters.Add(new ValueLookupParameter<DoubleArray>("Ranges", "The range of sub-populations used for creating a mating pool. (1 = current + previous sub-population)"));
     52      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("Quality", "The quality value contained in each sub-scope which is used for selection."));
     53      Parameters.Add(new ValueLookupParameter<BoolValue>("Maximization", "True if the current problem is a maximization problem, otherwise false."));
     54    }
     55
     56    private ContinuousMatingPoolCreator(ContinuousMatingPoolCreator original, Cloner cloner)
     57      : base(original, cloner) { }
     58    public override IDeepCloneable Clone(Cloner cloner) {
     59      return new ContinuousMatingPoolCreator(this, cloner);
    3560    }
    3661
    3762    [StorableConstructor]
    38     private MatingPoolCreator(bool deserializing)
     63    private ContinuousMatingPoolCreator(bool deserializing)
    3964      : base(deserializing) { }
    40     private MatingPoolCreator(MatingPoolCreator original, Cloner cloner)
    41       : base(original, cloner) { }
    42     public override IDeepCloneable Clone(Cloner cloner) {
    43       return new MatingPoolCreator(this, cloner);
    44     }
    45     public MatingPoolCreator()
    46       : base() {
    47       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)));
    48     }
     65    #endregion
    4966
    5067    /// <summary>
     
    6279    public override IOperation Apply() {
    6380      var subScopes = ExecutionContext.Scope.SubScopes;
    64       int range = MatingPoolRangeParameter.ActualValue.Value;
     81      var ranges = RangesParameter.ActualValue;
     82      var qualityName = QualityParameter.TranslatedName;
     83      bool maximization = MaximizationParameter.ActualValue.Value;
    6584
    6685      for (int targetIndex = subScopes.Count - 1; targetIndex > 0; targetIndex--) {
    6786        var targetScope = subScopes[targetIndex];
    68         for (int n = 1; (n <= range) && (targetIndex - n >= 0); n++) {
     87        var range = ranges.Length == 1 ? ranges[0] : ranges[targetIndex];
     88        for (int n = 1; (n <= (range + 1)) && (targetIndex - n >= 0); n++) {
    6989          var prevScope = subScopes[targetIndex - n];
    70           var individuals = prevScope.SubScopes;
     90          IEnumerable<IScope> individuals = prevScope.SubScopes
     91            .OrderBy(i => ((DoubleValue)i.Variables[qualityName].Value).Value);
     92          if (maximization) individuals = individuals.Reverse();
     93          individuals = individuals.Take((int)(Math.Min(range + 1 - n, 1.0) * prevScope.SubScopes.Count));
    7194          foreach (var individual in individuals) {
    7295            targetScope.SubScopes.Add((IScope)individual.Clone());
  • branches/Enhanced OSALPS/HeuristicLab.Algorithms.ALPS/3.3/HeuristicLab.Algorithms.ALPS-3.3.csproj

    r15429 r15432  
    8383      <SpecificVersion>False</SpecificVersion>
    8484      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Analysis-3.3.dll</HintPath>
     85      <Private>False</Private>
    8586    </Reference>
    8687    <Reference Include="HeuristicLab.Collections-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    8788      <SpecificVersion>False</SpecificVersion>
    8889      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Collections-3.3.dll</HintPath>
    89     </Reference>
    90     <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec" />
     90      <Private>False</Private>
     91    </Reference>
     92    <Reference Include="HeuristicLab.Common-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec">
     93      <Private>False</Private>
     94    </Reference>
    9195    <Reference Include="HeuristicLab.Core-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    9296      <SpecificVersion>False</SpecificVersion>
    9397      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Core-3.3.dll</HintPath>
     98      <Private>False</Private>
    9499    </Reference>
    95100    <Reference Include="HeuristicLab.Data-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    96101      <SpecificVersion>False</SpecificVersion>
    97102      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Data-3.3.dll</HintPath>
     103      <Private>False</Private>
    98104    </Reference>
    99105    <Reference Include="HeuristicLab.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    100106      <SpecificVersion>False</SpecificVersion>
    101107      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Operators-3.3.dll</HintPath>
     108      <Private>False</Private>
    102109    </Reference>
    103110    <Reference Include="HeuristicLab.Optimization-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    104111      <SpecificVersion>False</SpecificVersion>
    105112      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Optimization-3.3.dll</HintPath>
     113      <Private>False</Private>
    106114    </Reference>
    107115    <Reference Include="HeuristicLab.Optimization.Operators-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    108116      <SpecificVersion>False</SpecificVersion>
    109117      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Optimization.Operators-3.3.dll</HintPath>
     118      <Private>False</Private>
    110119    </Reference>
    111120    <Reference Include="HeuristicLab.Parameters-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    112121      <SpecificVersion>False</SpecificVersion>
    113122      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Parameters-3.3.dll</HintPath>
     123      <Private>False</Private>
    114124    </Reference>
    115125    <Reference Include="HeuristicLab.Persistence-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    116126      <SpecificVersion>False</SpecificVersion>
    117127      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Persistence-3.3.dll</HintPath>
     128      <Private>False</Private>
    118129    </Reference>
    119130    <Reference Include="HeuristicLab.PluginInfrastructure-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    120131      <SpecificVersion>False</SpecificVersion>
    121132      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.PluginInfrastructure-3.3.dll</HintPath>
     133      <Private>False</Private>
    122134    </Reference>
    123135    <Reference Include="HeuristicLab.Random-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    124136      <SpecificVersion>False</SpecificVersion>
    125137      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Random-3.3.dll</HintPath>
     138      <Private>False</Private>
    126139    </Reference>
    127140    <Reference Include="HeuristicLab.Selection-3.3, Version=3.3.0.0, Culture=neutral, PublicKeyToken=ba48961d6f65dcec, processorArchitecture=MSIL">
    128141      <SpecificVersion>False</SpecificVersion>
    129142      <HintPath>..\..\..\..\trunk\sources\bin\HeuristicLab.Selection-3.3.dll</HintPath>
     143      <Private>False</Private>
    130144    </Reference>
    131145    <Reference Include="System" />
     
    134148  </ItemGroup>
    135149  <ItemGroup>
     150    <Compile Include="AlpsOs2MainOperator.cs" />
     151    <Compile Include="AlpsOs2MainLoop.cs" />
    136152    <Compile Include="AlpsOffspringSelectionGeneticAlgorithmMainLoop.cs" />
    137153    <Compile Include="AlpsOffspringSelectionGeneticAlgorithm.cs" />
     
    139155    <Compile Include="AlpsOffspringSelectionGeneticAlgorithmMainOperator.cs" />
    140156    <Compile Include="AlpsOffspringSelector.cs" />
     157    <Compile Include="AlpsOs2.cs" />
     158    <Compile Include="Interfaces\IMatingPoolCreator.cs" />
     159    <Compile Include="ContinuousMatingPoolCreator.cs" />
    141160    <Compile Include="ReseedingController.cs" />
    142161    <Compile Include="ResultsHistoryWiper.cs" />
  • branches/Enhanced OSALPS/HeuristicLab.Algorithms.ALPS/3.3/MatingPoolCreator.cs

    r14185 r15432  
    3030  [Item("MatingPoolCreator", "An operator which creates mating pools based on a set of sub-populations. For each sub-population, the individuals from the previous sub-population are copied into the current sub-population.")]
    3131  [StorableClass]
    32   public sealed class MatingPoolCreator : SingleSuccessorOperator {
     32  public sealed class MatingPoolCreator : SingleSuccessorOperator, IMatingPoolCreator {
    3333    public IValueLookupParameter<IntValue> MatingPoolRangeParameter {
    3434      get { return (IValueLookupParameter<IntValue>)Parameters["MatingPoolRange"]; }
Note: See TracChangeset for help on using the changeset viewer.