Changeset 12993


Ignore:
Timestamp:
10/09/15 14:37:18 (3 years ago)
Author:
pfleck
Message:

#2269 Removed Alps base class and integrated the code in AlpsGeneticAlgorithm.

Location:
branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3
Files:
1 deleted
2 edited

Legend:

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

    r12992 r12993  
    2323using System.Collections.Generic;
    2424using System.Linq;
     25using HeuristicLab.Analysis;
     26using HeuristicLab.Collections;
    2527using HeuristicLab.Common;
    2628using HeuristicLab.Core;
     
    3941  [Creatable("Algorithms")]
    4042  [StorableClass]
    41   public sealed class AlpsGeneticAlgorithm : Alps {
     43  public sealed class AlpsGeneticAlgorithm : HeuristicOptimizationEngineAlgorithm, IStorableContent {
     44    public string Filename { get; set; }
     45
     46    #region Problem Properties
     47    public override Type ProblemType {
     48      get { return typeof(ISingleObjectiveHeuristicOptimizationProblem); }
     49    }
     50    public new ISingleObjectiveHeuristicOptimizationProblem Problem {
     51      get { return (ISingleObjectiveHeuristicOptimizationProblem)base.Problem; }
     52      set { base.Problem = value; }
     53    }
     54    #endregion
     55
    4256    #region Parameter Properties
     57    private IValueParameter<IntValue> SeedParameter {
     58      get { return (IValueParameter<IntValue>)Parameters["Seed"]; }
     59    }
     60    private IValueParameter<BoolValue> SetSeedRandomlyParameter {
     61      get { return (IValueParameter<BoolValue>)Parameters["SetSeedRandomly"]; }
     62    }
     63
     64    private IFixedValueParameter<MultiAnalyzer> AnalyzerParameter {
     65      get { return (IFixedValueParameter<MultiAnalyzer>)Parameters["Analyzer"]; }
     66    }
     67    private IFixedValueParameter<MultiAnalyzer> LayerAnalyzerParameter {
     68      get { return (IFixedValueParameter<MultiAnalyzer>)Parameters["LayerAnalyzer"]; }
     69    }
     70
     71    private IValueParameter<IntValue> NumberOfLayersParameter {
     72      get { return (IValueParameter<IntValue>)Parameters["NumberOfLayers"]; }
     73    }
    4374    private IValueParameter<IntValue> PopulationSizeParameter {
    4475      get { return (IValueParameter<IntValue>)Parameters["PopulationSize"]; }
    4576    }
     77
    4678    public IConstrainedValueParameter<ISelector> SelectorParameter {
    4779      get { return (IConstrainedValueParameter<ISelector>)Parameters["Selector"]; }
     
    5082      get { return (IConstrainedValueParameter<ICrossover>)Parameters["Crossover"]; }
    5183    }
     84    public IConstrainedValueParameter<IManipulator> MutatorParameter {
     85      get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
     86    }
    5287    private IValueParameter<PercentValue> MutationProbabilityParameter {
    5388      get { return (IValueParameter<PercentValue>)Parameters["MutationProbability"]; }
    5489    }
    55     public IConstrainedValueParameter<IManipulator> MutatorParameter {
    56       get { return (IConstrainedValueParameter<IManipulator>)Parameters["Mutator"]; }
    57     }
    5890    private IValueParameter<IntValue> ElitesParameter {
    5991      get { return (IValueParameter<IntValue>)Parameters["Elites"]; }
     
    6597      get { return (IValueParameter<BoolValue>)Parameters["PlusSelection"]; }
    6698    }
     99
     100    private IValueParameter<EnumValue<AgingScheme>> AgingSchemeParameter {
     101      get { return (IValueParameter<EnumValue<AgingScheme>>)Parameters["AgingScheme"]; }
     102    }
     103    private IValueParameter<IntValue> AgeGapParameter {
     104      get { return (IValueParameter<IntValue>)Parameters["AgeGap"]; }
     105    }
     106    private IValueParameter<EnumValue<AgeInheritance>> AgeInheritanceParameter {
     107      get { return (IValueParameter<EnumValue<AgeInheritance>>)Parameters["AgeInheritance"]; }
     108    }
     109    private IValueParameter<ReductionOperation> AgeInheritanceReductionParameter {
     110      get { return (IValueParameter<ReductionOperation>)Parameters["AgeInheritanceReduction"]; }
     111    }
     112    private IValueParameter<IntArray> AgeLimitsParameter {
     113      get { return (IValueParameter<IntArray>)Parameters["AgeLimits"]; }
     114    }
     115
     116    private IValueParameter<IntValue> MatingPoolRangeParameter {
     117      get { return (IValueParameter<IntValue>)Parameters["MatingPoolRange"]; }
     118    }
     119    private IValueParameter<PercentValue> MatingPoolSelectionPercentageParameter {
     120      get { return (IValueLookupParameter<PercentValue>)Parameters["MatingPoolSelectionPercentage"]; }
     121    }
     122
     123    private IValueParameter<MultiTerminator> TerminatorParameter {
     124      get { return (IValueParameter<MultiTerminator>)Parameters["Terminator"]; }
     125    }
    67126    #endregion
    68127
    69128    #region Properties
     129    public IntValue Seed {
     130      get { return SeedParameter.Value; }
     131      set { SeedParameter.Value = value; }
     132    }
     133    public BoolValue SetSeedRandomly {
     134      get { return SetSeedRandomlyParameter.Value; }
     135      set { SetSeedRandomlyParameter.Value = value; }
     136    }
     137
     138    public MultiAnalyzer Analyzer {
     139      get { return AnalyzerParameter.Value; }
     140    }
     141    public MultiAnalyzer LayerAnalyzer {
     142      get { return LayerAnalyzerParameter.Value; }
     143    }
     144
     145    public IntValue NumberOfLayers {
     146      get { return NumberOfLayersParameter.Value; }
     147      set { NumberOfLayersParameter.Value = value; }
     148    }
    70149    public IntValue PopulationSize {
    71150      get { return PopulationSizeParameter.Value; }
    72151      set { PopulationSizeParameter.Value = value; }
    73152    }
     153
     154    public ISelector Selector {
     155      get { return SelectorParameter.Value; }
     156      set { SelectorParameter.Value = value; }
     157    }
     158    public ICrossover Crossover {
     159      get { return CrossoverParameter.Value; }
     160      set { CrossoverParameter.Value = value; }
     161    }
     162    public IManipulator Mutator {
     163      get { return MutatorParameter.Value; }
     164      set { MutatorParameter.Value = value; }
     165    }
     166    public PercentValue MutationProbability {
     167      get { return MutationProbabilityParameter.Value; }
     168      set { MutationProbabilityParameter.Value = value; }
     169    }
     170    public IntValue Elites {
     171      get { return ElitesParameter.Value; }
     172      set { ElitesParameter.Value = value; }
     173    }
     174    public bool ReevaluteElites {
     175      get { return ReevaluateElitesParameter.Value.Value; }
     176      set { ReevaluateElitesParameter.Value.Value = value; }
     177    }
     178    public bool PlusSelection {
     179      get { return PlusSelectionParameter.Value.Value; }
     180      set { PlusSelectionParameter.Value.Value = value; }
     181    }
     182
     183    public EnumValue<AgingScheme> AgingScheme {
     184      get { return AgingSchemeParameter.Value; }
     185      set { AgingSchemeParameter.Value = value; }
     186    }
     187    public IntValue AgeGap {
     188      get { return AgeGapParameter.Value; }
     189      set { AgeGapParameter.Value = value; }
     190    }
     191    public EnumValue<AgeInheritance> AgeInheritance {
     192      get { return AgeInheritanceParameter.Value; }
     193      set { AgeInheritanceParameter.Value = value; }
     194    }
     195    private ReductionOperation AgeInheritanceReduction {
     196      get { return AgeInheritanceReductionParameter.Value; }
     197      set { AgeInheritanceReductionParameter.Value = value; }
     198    }
     199    public IntArray AgeLimits {
     200      get { return AgeLimitsParameter.Value; }
     201      set { AgeLimitsParameter.Value = value; }
     202    }
     203
     204    public IntValue MatingPoolRange {
     205      get { return MatingPoolRangeParameter.Value; }
     206      set { MatingPoolRangeParameter.Value = value; }
     207    }
     208    public PercentValue MatingPoolSelectionPercentage {
     209      get { return MatingPoolSelectionPercentageParameter.Value; }
     210      set { MatingPoolSelectionPercentageParameter.Value = value; }
     211    }
     212
     213    public MultiTerminator Terminators {
     214      get { return TerminatorParameter.Value; }
     215    }
     216
    74217    public int MaximumGenerations {
    75218      get { return generationsTerminator.Threshold.Value; }
    76219      set { generationsTerminator.Threshold.Value = value; }
    77220    }
    78     public ISelector Selector {
    79       get { return SelectorParameter.Value; }
    80       set { SelectorParameter.Value = value; }
    81     }
    82     public ICrossover Crossover {
    83       get { return CrossoverParameter.Value; }
    84       set { CrossoverParameter.Value = value; }
    85     }
    86     public PercentValue MutationProbability {
    87       get { return MutationProbabilityParameter.Value; }
    88       set { MutationProbabilityParameter.Value = value; }
    89     }
    90     public IManipulator Mutator {
    91       get { return MutatorParameter.Value; }
    92       set { MutatorParameter.Value = value; }
    93     }
    94     public IntValue Elites {
    95       get { return ElitesParameter.Value; }
    96       set { ElitesParameter.Value = value; }
    97     }
    98     public bool ReevaluteElites {
    99       get { return ReevaluateElitesParameter.Value.Value; }
    100       set { ReevaluateElitesParameter.Value.Value = value; }
    101     }
    102     public bool PlusSelection {
    103       get { return PlusSelectionParameter.Value.Value; }
    104       set { PlusSelectionParameter.Value.Value = value; }
    105     }
    106 
     221    #endregion
     222
     223    #region Helper Properties
     224    private RandomCreator GlobalRandomCreator {
     225      get { return (RandomCreator)OperatorGraph.InitialOperator; }
     226    }
     227    private SolutionsCreator SolutionsCreator {
     228      get { return OperatorGraph.Iterate().OfType<SolutionsCreator>().First(); }
     229    }
    107230    private AlpsGeneticAlgorithmMainLoop MainLoop {
    108231      get { return OperatorGraph.Iterate().OfType<AlpsGeneticAlgorithmMainLoop>().First(); }
     
    110233    #endregion
    111234
     235    #region Preconfigured Analyzers
     236    [Storable]
     237    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
     238    [Storable]
     239    private BestAverageWorstQualityAnalyzer layerQualityAnalyzer;
     240    #endregion
     241
     242    #region Preconfigured Terminators
    112243    [Storable]
    113244    private ComparisonTerminator<IntValue> generationsTerminator;
     245    [Storable]
     246    private ComparisonTerminator<IntValue> evaluationsTerminator;
     247    [Storable]
     248    private SingleObjectiveQualityTerminator qualityTerminator;
     249    [Storable]
     250    private ExecutionTimeTerminator executionTimeTerminator;
     251    #endregion
    114252
    115253    [StorableConstructor]
     
    122260    private AlpsGeneticAlgorithm(AlpsGeneticAlgorithm original, Cloner cloner)
    123261      : base(original, cloner) {
     262      qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
     263      layerQualityAnalyzer = cloner.Clone(original.layerQualityAnalyzer);
    124264      generationsTerminator = cloner.Clone(original.generationsTerminator);
     265      evaluationsTerminator = cloner.Clone(original.evaluationsTerminator);
     266      qualityTerminator = cloner.Clone(original.qualityTerminator);
     267      executionTimeTerminator = cloner.Clone(original.executionTimeTerminator);
    125268      Initialize();
    126269    }
     
    130273    public AlpsGeneticAlgorithm()
    131274      : base() {
     275      #region Add parameters
     276      Parameters.Add(new ValueParameter<IntValue>("Seed", "The random seed used to initialize the new pseudo random number generator.", new IntValue(0)));
     277      Parameters.Add(new ValueParameter<BoolValue>("SetSeedRandomly", "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true)));
     278
     279      Parameters.Add(new FixedValueParameter<MultiAnalyzer>("Analyzer", "The operator used to analyze the islands.", new MultiAnalyzer()));
     280      Parameters.Add(new FixedValueParameter<MultiAnalyzer>("LayerAnalyzer", "The operator used to analyze each layer.", new MultiAnalyzer()));
     281
     282      Parameters.Add(new ValueParameter<IntValue>("NumberOfLayers", "The number of layers.", new IntValue(10)));
    132283      Parameters.Add(new ValueParameter<IntValue>("PopulationSize", "The size of the population of solutions each layer.", new IntValue(100)));
     284
    133285      Parameters.Add(new ConstrainedValueParameter<ISelector>("Selector", "The operator used to select solutions for reproduction."));
    134286      Parameters.Add(new ConstrainedValueParameter<ICrossover>("Crossover", "The operator used to cross solutions."));
     287      Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
    135288      Parameters.Add(new ValueParameter<PercentValue>("MutationProbability", "The probability that the mutation operator is applied on a solution.", new PercentValue(0.05)));
    136       Parameters.Add(new OptionalConstrainedValueParameter<IManipulator>("Mutator", "The operator used to mutate solutions."));
    137289      Parameters.Add(new ValueParameter<IntValue>("Elites", "The numer of elite solutions which are kept in each generation.", new IntValue(1)));
    138290      Parameters.Add(new FixedValueParameter<BoolValue>("ReevaluateElites", "Flag to determine if elite individuals should be reevaluated (i.e., if stochastic fitness functions are used.)", new BoolValue(false)) { Hidden = true });
    139291      Parameters.Add(new ValueParameter<BoolValue>("PlusSelection", "Include the parents in the selection of the invividuals for the next generation.", new BoolValue(false)) { Hidden = true });
    140292
     293      Parameters.Add(new ValueParameter<EnumValue<AgingScheme>>("AgingScheme", "The aging scheme for setting the age-limits for the layers.", new EnumValue<AgingScheme>(ALPS.AgingScheme.Polynomial)));
     294      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)));
     295      Parameters.Add(new ValueParameter<EnumValue<AgeInheritance>>("AgeInheritance", "The operator for determining the age of an offspring based the parents' age.", new EnumValue<AgeInheritance>(ALPS.AgeInheritance.Older)));
     296      Parameters.Add(new ValueParameter<ReductionOperation>("AgeInheritanceReduction") { Hidden = true });
     297      Parameters.Add(new ValueParameter<IntArray>("AgeLimits", new IntArray(new int[0])) { Hidden = true });
     298
     299      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 });
     300      Parameters.Add(new ValueParameter<PercentValue>("MatingPoolSelectionPercentage", "Percentage of the previous layers used for creating a mating pool.", new PercentValue(1.0, restrictToUnitInterval: true)) { Hidden = true });
     301
     302      Parameters.Add(new ValueParameter<MultiTerminator>("Terminator", "The termination criteria which sould be checked.", new MultiTerminator()));
     303      #endregion
     304
     305      #region Create operators
    141306      var globalRandomCreator = new RandomCreator();
    142307      var layer0Creator = new SubScopesCreator() { Name = "Create Layer Zero" };
     
    152317      var resultsCollector = new ResultsCollector();
    153318      var mainLoop = new AlpsGeneticAlgorithmMainLoop();
    154 
     319      #endregion
     320
     321      #region Create and parameterize operator graph
    155322      OperatorGraph.InitialOperator = globalRandomCreator;
    156323
     
    195362      resultsCollector.CollectedValues.Add(new LookupParameter<IntValue>("Evaluated Solutions", null, "EvaluatedSolutions"));
    196363      resultsCollector.Successor = mainLoop;
    197 
     364      #endregion
     365
     366      #region Set selectors
    198367      foreach (var selector in ApplicationManager.Manager.GetInstances<ISelector>().Where(s => !(s is IMultiObjectiveSelector)).OrderBy(s => Name))
    199368        SelectorParameter.ValidValues.Add(selector);
    200       var tournamentSelector = SelectorParameter.ValidValues.OfType<TournamentSelector>().FirstOrDefault();
    201       if (tournamentSelector != null) {
    202         tournamentSelector.GroupSizeParameter.Value = new IntValue(4);
    203         SelectorParameter.Value = tournamentSelector;
    204       }
    205 
     369      var defaultSelector = SelectorParameter.ValidValues.OfType<GeneralizedRankSelector>().FirstOrDefault();
     370      if (defaultSelector != null) {
     371        defaultSelector.PressureParameter.Value = new DoubleValue(4);
     372        SelectorParameter.Value = defaultSelector;
     373      }
     374      #endregion
     375
     376      #region Create analyzers
     377      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
     378      layerQualityAnalyzer = new BestAverageWorstQualityAnalyzer();
     379      #endregion
     380
     381      #region Create terminators
    206382      generationsTerminator = new ComparisonTerminator<IntValue>("Generations", ComparisonType.Less, new IntValue(1000)) { Name = "Generations" };
     383      evaluationsTerminator = new ComparisonTerminator<IntValue>("EvaluatedSolutions", ComparisonType.Less, new IntValue(int.MaxValue)) { Name = "Evaluations" };
     384      qualityTerminator = new SingleObjectiveQualityTerminator() { Name = "Quality" };
     385      executionTimeTerminator = new ExecutionTimeTerminator(this, new TimeSpanValue(TimeSpan.FromMinutes(5)));
     386      #endregion
     387
     388      #region Parameterize
     389      ParameterizeAnalyzers();
     390      UpdateAnalyzers();
    207391
    208392      ParameterizeSelectors();
     
    210394      UpdateTerminators();
    211395
     396      ParameterizeAgeLimits();
     397      ParameterizeAgeInheritanceReduction();
     398      #endregion
     399
    212400      Initialize();
    213401    }
    214402
    215403    #region Events
     404    public override void Prepare() {
     405      if (Problem != null)
     406        base.Prepare();
     407    }
    216408    protected override void OnProblemChanged() {
    217409      base.OnProblemChanged();
     410      ParameterizeStochasticOperator(Problem.SolutionCreator);
     411      ParameterizeStochasticOperatorForLayer(Problem.Evaluator);
     412      foreach (var @operator in Problem.Operators.OfType<IOperator>())
     413        ParameterizeStochasticOperator(@operator);
     414
     415      ParameterizeIterationBasedOperators();
     416
    218417      ParameterizeSolutionsCreator();
    219418      ParameterizeMainLoop();
     419      ParameterizeAnalyzers();
    220420      ParameterizeSelectors();
    221       ParameterizeIterationBasedOperators();
     421      ParameterizeTerminators();
     422
     423      Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
     424
     425      UpdateAnalyzers();
    222426      UpdateCrossovers();
    223427      UpdateMutators();
    224428      UpdateTerminators();
    225429    }
     430
     431    protected override void RegisterProblemEvents() {
     432      base.RegisterProblemEvents();
     433      var maximizationParameter = (IValueParameter<BoolValue>)Problem.MaximizationParameter;
     434      if (maximizationParameter != null) maximizationParameter.ValueChanged += new EventHandler(MaximizationParameter_ValueChanged);
     435    }
     436    protected override void DeregisterProblemEvents() {
     437      var maximizationParameter = (IValueParameter<BoolValue>)Problem.MaximizationParameter;
     438      if (maximizationParameter != null) maximizationParameter.ValueChanged -= new EventHandler(MaximizationParameter_ValueChanged);
     439      base.DeregisterProblemEvents();
     440    }
     441
    226442    protected override void Problem_SolutionCreatorChanged(object sender, EventArgs e) {
    227443      base.Problem_SolutionCreatorChanged(sender, e);
     444      ParameterizeStochasticOperator(Problem.SolutionCreator);
     445      ParameterizeStochasticOperatorForLayer(Problem.Evaluator);
     446
     447      Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
     448
    228449      ParameterizeSolutionsCreator();
     450      ParameterizeAnalyzers();
    229451    }
    230452    protected override void Problem_EvaluatorChanged(object sender, EventArgs e) {
    231453      base.Problem_EvaluatorChanged(sender, e);
     454      foreach (var @operator in Problem.Operators.OfType<IOperator>())
     455        ParameterizeStochasticOperator(@operator);
     456
     457      UpdateAnalyzers();
     458
    232459      ParameterizeSolutionsCreator();
    233460      ParameterizeMainLoop();
     
    241468      UpdateTerminators();
    242469    }
    243     protected override void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
    244       base.Evaluator_QualityParameter_ActualNameChanged(sender, e);
     470    private void Evaluator_QualityParameter_ActualNameChanged(object sender, EventArgs e) {
    245471      ParameterizeMainLoop();
     472      ParameterizeAnalyzers();
    246473      ParameterizeSelectors();
     474    }
     475    private void MaximizationParameter_ValueChanged(object sender, EventArgs e) {
     476      ParameterizeTerminators();
     477    }
     478    private void QualityAnalyzer_CurrentBestQualityParameter_NameChanged(object sender, EventArgs e) {
     479      ParameterizeTerminators();
     480    }
     481
     482    private void AgeGapParameter_ValueChanged(object sender, EventArgs e) {
     483      AgeGap.ValueChanged += AgeGap_ValueChanged;
     484      ParameterizeAgeLimits();
     485    }
     486    private void AgeGap_ValueChanged(object sender, EventArgs e) {
     487      ParameterizeAgeLimits();
     488    }
     489    private void AgingSchemeParameter_ValueChanged(object sender, EventArgs e) {
     490      AgingScheme.ValueChanged += AgingScheme_ValueChanged;
     491      ParameterizeAgeLimits();
     492    }
     493    private void AgingScheme_ValueChanged(object sender, EventArgs e) {
     494      ParameterizeAgeLimits();
     495    }
     496    private void NumberOfLayersParameter_ValueChanged(object sender, EventArgs e) {
     497      NumberOfLayers.ValueChanged += NumberOfLayers_ValueChanged;
     498      ParameterizeAgeLimits();
     499    }
     500    private void NumberOfLayers_ValueChanged(object sender, EventArgs e) {
     501      ParameterizeAgeLimits();
     502    }
     503    private void AgeInheritanceParameter_ValueChanged(object sender, EventArgs e) {
     504      AgeInheritance.ValueChanged += AgeInheritance_ValueChanged;
     505      ParameterizeAgeInheritanceReduction();
     506    }
     507    private void AgeInheritance_ValueChanged(object sender, EventArgs e) {
     508      ParameterizeAgeInheritanceReduction();
     509    }
     510
     511    private void AnalyzerOperators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IAnalyzer>> e) {
     512      foreach (var analyzer in e.Items) {
     513        foreach (var parameter in analyzer.Value.Parameters.OfType<IScopeTreeLookupParameter>()) {
     514          parameter.Depth = 2;
     515        }
     516      }
     517    }
     518    private void LayerAnalyzerOperators_ItemsAdded(object sender, CollectionItemsChangedEventArgs<IndexedItem<IAnalyzer>> e) {
     519      foreach (var analyzer in e.Items) {
     520        IParameter resultParameter;
     521        if (analyzer.Value.Parameters.TryGetValue("Results", out resultParameter)) {
     522          var lookupParameter = resultParameter as ILookupParameter;
     523          if (lookupParameter != null)
     524            lookupParameter.ActualName = "LayerResults";
     525        }
     526        foreach (var parameter in analyzer.Value.Parameters.OfType<IScopeTreeLookupParameter>()) {
     527          parameter.Depth = 1;
     528        }
     529      }
    247530    }
    248531    #endregion
     
    250533    #region Parameterization
    251534    private void Initialize() {
     535      if (Problem != null)
     536        Problem.Evaluator.QualityParameter.ActualNameChanged += Evaluator_QualityParameter_ActualNameChanged;
     537
     538      NumberOfLayersParameter.ValueChanged += NumberOfLayersParameter_ValueChanged;
     539      NumberOfLayers.ValueChanged += NumberOfLayers_ValueChanged;
     540
     541      Analyzer.Operators.ItemsAdded += AnalyzerOperators_ItemsAdded;
     542      LayerAnalyzer.Operators.ItemsAdded += LayerAnalyzerOperators_ItemsAdded;
     543
     544      AgeGapParameter.ValueChanged += AgeGapParameter_ValueChanged;
     545      AgeGap.ValueChanged += AgeGap_ValueChanged;
     546      AgingSchemeParameter.ValueChanged += AgingSchemeParameter_ValueChanged;
     547      AgingScheme.ValueChanged += AgingScheme_ValueChanged;
     548      AgeInheritanceParameter.ValueChanged += AgeInheritanceParameter_ValueChanged;
     549      AgeInheritance.ValueChanged += AgeInheritance_ValueChanged;
     550
     551      qualityAnalyzer.CurrentBestQualityParameter.NameChanged += new EventHandler(QualityAnalyzer_CurrentBestQualityParameter_NameChanged);
    252552    }
    253553    private void ParameterizeSolutionsCreator() {
     554      SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
     555      SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
    254556      MainLoop.LayerUpdator.SolutionsCreator.EvaluatorParameter.ActualName = Problem.EvaluatorParameter.Name;
    255557      MainLoop.LayerUpdator.SolutionsCreator.SolutionCreatorParameter.ActualName = Problem.SolutionCreatorParameter.Name;
     
    263565      MainLoop.LayerUpdator.SolutionsCreator.NumberOfSolutionsParameter.ActualName = PopulationSizeParameter.Name;
    264566    }
     567    private void ParameterizeAnalyzers() {
     568      qualityAnalyzer.ResultsParameter.ActualName = "Results";
     569      qualityAnalyzer.ResultsParameter.Hidden = true;
     570      qualityAnalyzer.QualityParameter.Depth = 2;
     571      layerQualityAnalyzer.ResultsParameter.ActualName = "Results";
     572      layerQualityAnalyzer.ResultsParameter.Hidden = true;
     573      layerQualityAnalyzer.QualityParameter.Depth = 1;
     574      if (Problem != null) {
     575        qualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
     576        qualityAnalyzer.MaximizationParameter.Hidden = true;
     577        qualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     578        qualityAnalyzer.QualityParameter.Hidden = true;
     579        qualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
     580        qualityAnalyzer.BestKnownQualityParameter.Hidden = true;
     581        layerQualityAnalyzer.MaximizationParameter.ActualName = Problem.MaximizationParameter.Name;
     582        layerQualityAnalyzer.MaximizationParameter.Hidden = true;
     583        layerQualityAnalyzer.QualityParameter.ActualName = Problem.Evaluator.QualityParameter.ActualName;
     584        layerQualityAnalyzer.QualityParameter.Hidden = true;
     585        layerQualityAnalyzer.BestKnownQualityParameter.ActualName = Problem.BestKnownQualityParameter.Name;
     586        layerQualityAnalyzer.BestKnownQualityParameter.Hidden = true;
     587      }
     588    }
    265589    private void ParameterizeSelectors() {
    266590      foreach (var selector in SelectorParameter.ValidValues) {
     
    279603        }
    280604      }
     605    }
     606    private void ParameterizeTerminators() {
     607      qualityTerminator.Parameterize(qualityAnalyzer.CurrentBestQualityParameter, Problem);
    281608    }
    282609    private void ParameterizeIterationBasedOperators() {
     
    290617      }
    291618    }
    292 
    293     protected override ReductionOperations GetAgeInheritanceReduction(AgeInheritance ageInheritance) {
     619    private void ParameterizeAgeInheritanceReduction() {
     620      AgeInheritanceReduction.Value = GetAgeInheritanceReduction(AgeInheritance.Value);
     621    }
     622    private void ParameterizeAgeLimits() {
     623      var scheme = AgingScheme.Value;
     624      int ageGap = AgeGap.Value;
     625      int numberOfLayers = NumberOfLayers.Value;
     626      AgeLimits = scheme.CalculateAgeLimits(ageGap, numberOfLayers);
     627    }
     628
     629    private void ParameterizeStochasticOperator(IOperator @operator) {
     630      var stochasticOperator = @operator as IStochasticOperator;
     631      if (stochasticOperator != null) {
     632        stochasticOperator.RandomParameter.ActualName = "GlobalRandom";
     633        stochasticOperator.RandomParameter.Hidden = true;
     634      }
     635    }
     636
     637    private void ParameterizeStochasticOperatorForLayer(IOperator @operator) {
     638      var stochasticOperator = @operator as IStochasticOperator;
     639      if (stochasticOperator != null) {
     640        stochasticOperator.RandomParameter.ActualName = "LocalRandom";
     641        stochasticOperator.RandomParameter.Hidden = true;
     642      }
     643    }
     644
     645    private ReductionOperations GetAgeInheritanceReduction(AgeInheritance ageInheritance) {
    294646      switch (ageInheritance) {
    295647        case ALPS.AgeInheritance.Older: return ReductionOperations.Max;
     
    302654
    303655    #region Updates
     656    private void UpdateAnalyzers() {
     657      Analyzer.Operators.Clear();
     658      LayerAnalyzer.Operators.Clear();
     659
     660      Analyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
     661      LayerAnalyzer.Operators.Add(layerQualityAnalyzer, layerQualityAnalyzer.EnabledByDefault);
     662
     663      if (Problem != null) {
     664        foreach (var analyzer in Problem.Operators.OfType<IAnalyzer>()) {
     665          Analyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
     666        }
     667      }
     668    }
     669    private void UpdateCrossovers() {
     670      var oldCrossover = CrossoverParameter.Value;
     671      var defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
     672      CrossoverParameter.ValidValues.Clear();
     673      foreach (var crossover in Problem.Operators.OfType<ICrossover>().OrderBy(c => c.Name)) {
     674        ParameterizeStochasticOperatorForLayer(crossover);
     675        CrossoverParameter.ValidValues.Add(crossover);
     676      }
     677      if (oldCrossover != null) {
     678        var crossover = CrossoverParameter.ValidValues.FirstOrDefault(c => c.GetType() == oldCrossover.GetType());
     679        if (crossover != null)
     680          CrossoverParameter.Value = crossover;
     681        else
     682          oldCrossover = null;
     683      }
     684      if (oldCrossover == null && defaultCrossover != null)
     685        CrossoverParameter.Value = defaultCrossover;
     686    }
     687    private void UpdateMutators() {
     688      var oldMutator = MutatorParameter.Value;
     689      MutatorParameter.ValidValues.Clear();
     690      foreach (var mutator in Problem.Operators.OfType<IManipulator>().OrderBy(m => m.Name)) {
     691        ParameterizeStochasticOperatorForLayer(mutator);
     692        MutatorParameter.ValidValues.Add(mutator);
     693      }
     694      if (oldMutator != null) {
     695        var mutator = MutatorParameter.ValidValues.FirstOrDefault(m => m.GetType() == oldMutator.GetType());
     696        if (mutator != null)
     697          MutatorParameter.Value = mutator;
     698      }
     699    }
    304700    private void UpdateTerminators() {
    305701      var newTerminators = new Dictionary<ITerminator, bool> {
     
    319715        Terminators.Operators.Add(newTerminator.Key, newTerminator.Value);
    320716    }
    321     private void UpdateCrossovers() {
    322       var oldCrossover = CrossoverParameter.Value;
    323       var defaultCrossover = Problem.Operators.OfType<ICrossover>().FirstOrDefault();
    324       CrossoverParameter.ValidValues.Clear();
    325       foreach (var crossover in Problem.Operators.OfType<ICrossover>().OrderBy(c => c.Name)) {
    326         ParameterizeStochasticOperatorForLayer(crossover);
    327         CrossoverParameter.ValidValues.Add(crossover);
    328       }
    329       if (oldCrossover != null) {
    330         var crossover = CrossoverParameter.ValidValues.FirstOrDefault(c => c.GetType() == oldCrossover.GetType());
    331         if (crossover != null)
    332           CrossoverParameter.Value = crossover;
    333         else
    334           oldCrossover = null;
    335       }
    336       if (oldCrossover == null && defaultCrossover != null)
    337         CrossoverParameter.Value = defaultCrossover;
    338     }
    339     private void UpdateMutators() {
    340       var oldMutator = MutatorParameter.Value;
    341       MutatorParameter.ValidValues.Clear();
    342       foreach (var mutator in Problem.Operators.OfType<IManipulator>().OrderBy(m => m.Name)) {
    343         ParameterizeStochasticOperatorForLayer(mutator);
    344         MutatorParameter.ValidValues.Add(mutator);
    345       }
    346       if (oldMutator != null) {
    347         var mutator = MutatorParameter.ValidValues.FirstOrDefault(m => m.GetType() == oldMutator.GetType());
    348         if (mutator != null)
    349           MutatorParameter.Value = mutator;
    350       }
    351     }
    352717    #endregion
    353718  }
  • branches/ALPS/HeuristicLab.Algorithms.ALPS/3.3/HeuristicLab.Algorithms.ALPS-3.3.csproj

    r12992 r12993  
    133133  <ItemGroup>
    134134    <Compile Include="AgeInheritance.cs" />
    135     <Compile Include="Alps.cs" />
    136135    <Compile Include="Analyzers\EvaluatedSolutionsHistoryAnalyzer.cs" />
    137136    <Compile Include="Analyzers\OldestAverageYoungestAgeAnalyzer.cs" />
Note: See TracChangeset for help on using the changeset viewer.