Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
10/29/14 15:06:25 (10 years ago)
Author:
ascheibe
Message:

#2267 made offspring selector configurable

Location:
branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm
Files:
2 added
5 edited

Legend:

Unmodified
Added
Removed
  • branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm-3.3.csproj

    r11492 r11510  
    161161  </ItemGroup>
    162162  <ItemGroup>
     163    <Compile Include="OffspringSelectors\IOffspringSelector.cs" />
     164    <Compile Include="OffspringSelectors\StandardOffspringSelector.cs" />
    163165    <Compile Include="ProbabilitiesGenerator.cs" />
    164166    <Compile Include="Plugin.cs" />
  • branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/Plugin.cs.frame

    r11492 r11510  
    4040  [PluginDependency("HeuristicLab.Random", "3.3")]
    4141  [PluginDependency("HeuristicLab.Selection", "3.3")]
    42   public class HeuristicLabAlgorithmsOffspringSelectionGeneticAlgorithmPlugin : PluginBase {
     42  public class HeuristicLabAlgorithmsVOffspringSelectionGeneticAlgorithmPlugin : PluginBase {
    4343  }
    4444}
  • branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/VOffspringSelectionGeneticAlgorithm.cs

    r11492 r11510  
    3838  /// An offspring selection genetic algorithm.
    3939  /// </summary>
    40   [Item("Offspring Selection Genetic Algorithm", "An offspring selection genetic algorithm (Affenzeller, M. et al. 2009. Genetic Algorithms and Genetic Programming - Modern Concepts and Practical Applications. CRC Press).")]
     40  [Item("VOSGA", "An OSGA with selectable OS criteria and automtic crossover/mutation selection.")]
    4141  [Creatable("Algorithms")]
    4242  [StorableClass]
    43   public sealed class OffspringSelectionGeneticAlgorithm : HeuristicOptimizationEngineAlgorithm, IStorableContent {
     43  public sealed class VOffspringSelectionGeneticAlgorithm : HeuristicOptimizationEngineAlgorithm, IStorableContent {
    4444    public string Filename { get; set; }
    4545
     
    114114    private IFixedValueParameter<BoolValue> FillPopulationWithParentsParameter {
    115115      get { return (IFixedValueParameter<BoolValue>)Parameters["FillPopulationWithParents"]; }
     116    }
     117    public IConstrainedValueParameter<IOffspringSelector> OffspringSelectorParameter {
     118      get { return (IConstrainedValueParameter<IOffspringSelector>)Parameters["OffspringSelector"]; }
    116119    }
    117120    #endregion
     
    134137      set { SelectorParameter.Value = value; }
    135138    }
     139    public IOffspringSelector OffspringSelector {
     140      get { return OffspringSelectorParameter.Value; }
     141      set { OffspringSelectorParameter.Value = value; }
     142    }
    136143    public ICrossover Crossover {
    137144      get { return CrossoverParameter.Value; }
     
    204211      get { return (SolutionsCreator)RandomCreator.Successor; }
    205212    }
    206     private OffspringSelectionGeneticAlgorithmMainLoop MainLoop {
     213    private VOffspringSelectionGeneticAlgorithmMainLoop MainLoop {
    207214      get { return FindMainLoop(SolutionsCreator.Successor); }
    208215    }
     
    216223
    217224    [StorableConstructor]
    218     private OffspringSelectionGeneticAlgorithm(bool deserializing) : base(deserializing) { }
     225    private VOffspringSelectionGeneticAlgorithm(bool deserializing) : base(deserializing) { }
    219226    [StorableHook(HookType.AfterDeserialization)]
    220227    private void AfterDeserialization() {
     
    232239      Initialize();
    233240    }
    234     private OffspringSelectionGeneticAlgorithm(OffspringSelectionGeneticAlgorithm original, Cloner cloner)
     241    private VOffspringSelectionGeneticAlgorithm(VOffspringSelectionGeneticAlgorithm original, Cloner cloner)
    235242      : base(original, cloner) {
    236243      qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
     
    240247    }
    241248    public override IDeepCloneable Clone(Cloner cloner) {
    242       return new OffspringSelectionGeneticAlgorithm(this, cloner);
    243     }
    244     public OffspringSelectionGeneticAlgorithm()
     249      return new VOffspringSelectionGeneticAlgorithm(this, cloner);
     250    }
     251    public VOffspringSelectionGeneticAlgorithm()
    245252      : base() {
    246253      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
     
    264271      Parameters.Add(new ValueParameter<IntValue>("MaximumEvaluatedSolutions", "The maximum number of evaluated solutions (approximately).", new IntValue(int.MaxValue)));
    265272      Parameters.Add(new FixedValueParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individual or false if worse children should be used when the maximum selection pressure is exceeded.", new BoolValue(false)) { Hidden = true });
     273      Parameters.Add(new ConstrainedValueParameter<IOffspringSelector>("OffspringSelector", "The operator used as selection criterea for deciding which individuals are successful and which should be disgarded."));
     274
    266275
    267276      RandomCreator randomCreator = new RandomCreator();
     
    269278      SubScopesCounter subScopesCounter = new SubScopesCounter();
    270279      ResultsCollector resultsCollector = new ResultsCollector();
    271       OffspringSelectionGeneticAlgorithmMainLoop mainLoop = new OffspringSelectionGeneticAlgorithmMainLoop();
     280      VOffspringSelectionGeneticAlgorithmMainLoop mainLoop = new VOffspringSelectionGeneticAlgorithmMainLoop();
    272281      OperatorGraph.InitialOperator = randomCreator;
    273282
     
    321330      ParameterizeComparisonFactorModifiers();
    322331
     332      foreach (IOffspringSelector selector in ApplicationManager.Manager.GetInstances<IOffspringSelector>().OrderBy(x => x.Name))
     333        OffspringSelectorParameter.ValidValues.Add(selector);
     334      IOffspringSelector standardOffspringSelector = OffspringSelectorParameter.ValidValues.FirstOrDefault(x => x.GetType().Name.Equals("StandardOffspringSelector"));
     335      if (standardOffspringSelector != null) OffspringSelectorParameter.Value = standardOffspringSelector;
     336      ParameterizeOffspringSelectors();
     337
    323338      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
    324339      selectionPressureAnalyzer = new ValueAnalyzer();
     
    329344      Initialize();
    330345    }
    331 
    332 
    333346
    334347    public override void Prepare() {
     
    431444          selector.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
    432445        }
     446      }
     447    }
     448    private void ParameterizeOffspringSelectors() {
     449      foreach (IOffspringSelector selector in OffspringSelectorParameter.ValidValues) {
     450        //TODO: do we need to set these parameters? if yes, where?
     451        // selector.CurrentSuccessRatioParameter.ActualName = CurrentSuccessRatioParameter.Name;
     452        //selector.SelectionPressureParameter.ActualName = SelectionPressureParameter.Name;
     453        selector.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
     454        selector.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
     455        selector.OffspringPopulationParameter.ActualName = "OffspringPopulation";
     456        selector.OffspringPopulationWinnersParameter.ActualName = "OffspringPopulationWinners";
     457        selector.SuccessfulOffspringParameter.ActualName = "SuccessfulOffspring";
     458        selector.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name;
    433459      }
    434460    }
     
    507533      Analyzer.Operators.Add(successfulOffspringAnalyzer, successfulOffspringAnalyzer.EnabledByDefault);
    508534    }
    509     private OffspringSelectionGeneticAlgorithmMainLoop FindMainLoop(IOperator start) {
     535    private VOffspringSelectionGeneticAlgorithmMainLoop FindMainLoop(IOperator start) {
    510536      IOperator mainLoop = start;
    511       while (mainLoop != null && !(mainLoop is OffspringSelectionGeneticAlgorithmMainLoop))
     537      while (mainLoop != null && !(mainLoop is VOffspringSelectionGeneticAlgorithmMainLoop))
    512538        mainLoop = ((SingleSuccessorOperator)mainLoop).Successor;
    513539      if (mainLoop == null) return null;
    514       else return (OffspringSelectionGeneticAlgorithmMainLoop)mainLoop;
     540      else return (VOffspringSelectionGeneticAlgorithmMainLoop)mainLoop;
    515541    }
    516542    #endregion
  • branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/VOffspringSelectionGeneticAlgorithmMainLoop.cs

    r11492 r11510  
    3232  /// An operator which represents the main loop of an offspring selection genetic algorithm.
    3333  /// </summary>
    34   [Item("OffspringSelectionGeneticAlgorithmMainLoop", "An operator which represents the main loop of an offspring selection genetic algorithm.")]
     34  [Item("VOffspringSelectionGeneticAlgorithmMainLoop", "An operator which represents the main loop of an offspring selection genetic algorithm.")]
    3535  [StorableClass]
    36   public sealed class OffspringSelectionGeneticAlgorithmMainLoop : AlgorithmOperator {
     36  public sealed class VOffspringSelectionGeneticAlgorithmMainLoop : AlgorithmOperator {
    3737    #region Parameter properties
    3838    public ValueLookupParameter<IRandom> RandomParameter {
     
    102102
    103103    [StorableConstructor]
    104     private OffspringSelectionGeneticAlgorithmMainLoop(bool deserializing) : base(deserializing) { }
    105     private OffspringSelectionGeneticAlgorithmMainLoop(OffspringSelectionGeneticAlgorithmMainLoop original, Cloner cloner)
     104    private VOffspringSelectionGeneticAlgorithmMainLoop(bool deserializing) : base(deserializing) { }
     105    private VOffspringSelectionGeneticAlgorithmMainLoop(VOffspringSelectionGeneticAlgorithmMainLoop original, Cloner cloner)
    106106      : base(original, cloner) {
    107107    }
    108108    public override IDeepCloneable Clone(Cloner cloner) {
    109       return new OffspringSelectionGeneticAlgorithmMainLoop(this, cloner);
    110     }
    111     public OffspringSelectionGeneticAlgorithmMainLoop()
     109      return new VOffspringSelectionGeneticAlgorithmMainLoop(this, cloner);
     110    }
     111    public VOffspringSelectionGeneticAlgorithmMainLoop()
    112112      : base() {
    113113      Initialize();
     
    157157      Placeholder analyzer1 = new Placeholder();
    158158      ResultsCollector resultsCollector1 = new ResultsCollector();
    159       OffspringSelectionGeneticAlgorithmMainOperator mainOperator = new OffspringSelectionGeneticAlgorithmMainOperator();
     159      VOffspringSelectionGeneticAlgorithmMainOperator mainOperator = new VOffspringSelectionGeneticAlgorithmMainOperator();
    160160      IntCounter generationsCounter = new IntCounter();
    161161      Comparator maxGenerationsComparator = new Comparator();
  • branches/VOSGA/HeuristicLab.Algorithms.VOffspringSelectionGeneticAlgorithm/VOffspringSelectionGeneticAlgorithmMainOperator.cs

    r11492 r11510  
    3333  /// An operator which represents the main loop of an offspring selection genetic algorithm.
    3434  /// </summary>
    35   [Item("OffspringSelectionGeneticAlgorithmMainOperator", "An operator that represents the core of an offspring selection genetic algorithm.")]
     35  [Item("VOffspringSelectionGeneticAlgorithmMainOperator", "An operator that represents the core of an offspring selection genetic algorithm.")]
    3636  [StorableClass]
    37   public sealed class OffspringSelectionGeneticAlgorithmMainOperator : AlgorithmOperator {
     37  public sealed class VOffspringSelectionGeneticAlgorithmMainOperator : AlgorithmOperator {
    3838    #region Parameter properties
    3939    public ValueLookupParameter<IRandom> RandomParameter {
     
    9191      get { return (IValueLookupParameter<BoolValue>)Parameters["FillPopulationWithParents"]; }
    9292    }
     93    public ValueLookupParameter<IOffspringSelector> OffspringSelectorParameter {
     94      get { return (ValueLookupParameter<IOffspringSelector>)Parameters["OffspringSelector"]; }
     95    }
    9396    #endregion
    9497
    9598    [StorableConstructor]
    96     private OffspringSelectionGeneticAlgorithmMainOperator(bool deserializing) : base(deserializing) { }
    97     private OffspringSelectionGeneticAlgorithmMainOperator(OffspringSelectionGeneticAlgorithmMainOperator original, Cloner cloner)
     99    private VOffspringSelectionGeneticAlgorithmMainOperator(bool deserializing) : base(deserializing) { }
     100    private VOffspringSelectionGeneticAlgorithmMainOperator(VOffspringSelectionGeneticAlgorithmMainOperator original, Cloner cloner)
    98101      : base(original, cloner) {
    99102    }
    100103    public override IDeepCloneable Clone(Cloner cloner) {
    101       return new OffspringSelectionGeneticAlgorithmMainOperator(this, cloner);
    102     }
    103     public OffspringSelectionGeneticAlgorithmMainOperator()
     104      return new VOffspringSelectionGeneticAlgorithmMainOperator(this, cloner);
     105    }
     106    public VOffspringSelectionGeneticAlgorithmMainOperator()
    104107      : base() {
    105108      Initialize();
     
    138141      Parameters.Add(new ValueLookupParameter<BoolValue>("OffspringSelectionBeforeMutation", "True if the offspring selection step should be applied before mutation, false if it should be applied after mutation."));
    139142      Parameters.Add(new ValueLookupParameter<BoolValue>("FillPopulationWithParents", "True if the population should be filled with parent individual or false if worse children should be used when the maximum selection pressure is exceeded."));
     143      Parameters.Add(new ValueLookupParameter<IOffspringSelector>("OffspringSelector", "The operator used as selection criterea for deciding which individuals are successful and which should be disgarded."));
    140144      #endregion
    141145
     
    172176      WeightedParentsQualityComparator qualityComparer2 = new WeightedParentsQualityComparator();
    173177      SubScopesRemover subScopesRemover2 = new SubScopesRemover();
    174       OffspringSelector offspringSelector = new OffspringSelector();
     178      Placeholder offspringSelector = new Placeholder();
    175179      SubScopesProcessor subScopesProcessor3 = new SubScopesProcessor();
    176180      BestSelector bestSelector = new BestSelector();
     
    183187      Placeholder evaluator4 = new Placeholder();
    184188      SubScopesCounter subScopesCounter4 = new SubScopesCounter();
     189      ConditionalBranch conditionalBranch = new ConditionalBranch();
    185190
    186191      selector.Name = "Selector (placeholder)";
     
    260265      subScopesRemover2.RemoveAllSubScopes = true;
    261266
    262       offspringSelector.CurrentSuccessRatioParameter.ActualName = CurrentSuccessRatioParameter.Name;
    263       offspringSelector.MaximumSelectionPressureParameter.ActualName = MaximumSelectionPressureParameter.Name;
    264       offspringSelector.SelectionPressureParameter.ActualName = SelectionPressureParameter.Name;
    265       offspringSelector.SuccessRatioParameter.ActualName = SuccessRatioParameter.Name;
    266       offspringSelector.OffspringPopulationParameter.ActualName = "OffspringPopulation";
    267       offspringSelector.OffspringPopulationWinnersParameter.ActualName = "OffspringPopulationWinners";
    268       offspringSelector.SuccessfulOffspringParameter.ActualName = "SuccessfulOffspring";
    269       offspringSelector.FillPopulationWithParentsParameter.ActualName = FillPopulationWithParentsParameter.Name;
     267      offspringSelector.Name = "OffspringSelector (placeholder)";
     268      offspringSelector.OperatorParameter.ActualName = OffspringSelectorParameter.Name;
    270269
    271270      bestSelector.CopySelected = new BoolValue(false);
     
    289288      subScopesCounter4.Name = "Increment EvaluatedSolutions";
    290289      subScopesCounter4.ValueParameter.ActualName = EvaluatedSolutionsParameter.Name;
     290
     291      conditionalBranch.Name = "Enough children produced?";
     292      conditionalBranch.ConditionParameter.ActualName = "EnoughChildrenGenerated";
     293      conditionalBranch.FalseBranch = selector;
     294      conditionalBranch.TrueBranch = subScopesProcessor3;
    291295      #endregion
    292296
     
    340344      subScopesRemover2.Successor = null;
    341345      subScopesCounter3.Successor = null;
    342       offspringSelector.OffspringCreator = selector;
    343       offspringSelector.Successor = subScopesProcessor3;
     346      offspringSelector.Successor = conditionalBranch;
    344347      subScopesProcessor3.Operators.Add(bestSelector);
    345348      subScopesProcessor3.Operators.Add(worstSelector);
Note: See TracChangeset for help on using the changeset viewer.