Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/23/20 16:21:55 (4 years ago)
Author:
abeham
Message:

#2521:

  • Moving solution creator parameter from problems to algorithms (breaking wiring in some HeuristicOptimizationProblems)
  • Disallowing evaluator or encoding changes in encoding-specific base problems (to avoid confusion in derived problems whether this needs to be handled or not)
  • Added private set to ReferenceParameter property (serialization)
Location:
branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Algorithms
Files:
1 deleted
1 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Algorithms/HeuristicOptimizationEngineAlgorithm.cs

    r17226 r17695  
    2121
    2222using System;
     23using HEAL.Attic;
    2324using HeuristicLab.Common;
    2425using HeuristicLab.Core;
    25 using HEAL.Attic;
     26using HeuristicLab.Parameters;
    2627
    2728namespace HeuristicLab.Optimization {
     
    3738    }
    3839
    39     protected HeuristicOptimizationEngineAlgorithm() : base() { }
    40     protected HeuristicOptimizationEngineAlgorithm(string name) : base(name) { }
    41     protected HeuristicOptimizationEngineAlgorithm(string name, ParameterCollection parameters) : base(name, parameters) { }
    42     protected HeuristicOptimizationEngineAlgorithm(string name, string description) : base(name, description) { }
    43     protected HeuristicOptimizationEngineAlgorithm(string name, string description, ParameterCollection parameters) : base(name, description, parameters) { }
     40    [Storable] public IConstrainedValueParameter<ISolutionCreator> SolutionCreatorParameter { get; private set; }
     41    public ISolutionCreator SolutionCreator {
     42      get => SolutionCreatorParameter.Value;
     43      set {
     44        if (!SolutionCreatorParameter.ValidValues.Contains(value))
     45          SolutionCreatorParameter.ValidValues.Add(value);
     46        SolutionCreatorParameter.Value = value;
     47      }
     48    }
     49
     50    protected HeuristicOptimizationEngineAlgorithm() : base() {
     51      Parameters.Add(SolutionCreatorParameter = new ConstrainedValueParameter<ISolutionCreator>("SolutionCreator", "An operator that creates a solution for a given problem."));
     52
     53      RegisterEventHandlers();
     54    }
     55    protected HeuristicOptimizationEngineAlgorithm(string name) : base(name) {
     56      Parameters.Add(SolutionCreatorParameter = new ConstrainedValueParameter<ISolutionCreator>("SolutionCreator", "An operator that creates a solution for a given problem."));
     57
     58      RegisterEventHandlers();
     59    }
     60    protected HeuristicOptimizationEngineAlgorithm(string name, ParameterCollection parameters) : base(name, parameters) {
     61      Parameters.Add(SolutionCreatorParameter = new ConstrainedValueParameter<ISolutionCreator>("SolutionCreator", "An operator that creates a solution for a given problem."));
     62
     63      RegisterEventHandlers();
     64    }
     65    protected HeuristicOptimizationEngineAlgorithm(string name, string description) : base(name, description) {
     66      Parameters.Add(SolutionCreatorParameter = new ConstrainedValueParameter<ISolutionCreator>("SolutionCreator", "An operator that creates a solution for a given problem."));
     67
     68      RegisterEventHandlers();
     69    }
     70    protected HeuristicOptimizationEngineAlgorithm(string name, string description, ParameterCollection parameters) : base(name, description, parameters) {
     71      Parameters.Add(SolutionCreatorParameter = new ConstrainedValueParameter<ISolutionCreator>("SolutionCreator", "An operator that creates a solution for a given problem."));
     72
     73      RegisterEventHandlers();
     74    }
    4475
    4576    [StorableConstructor]
    4677    protected HeuristicOptimizationEngineAlgorithm(StorableConstructorFlag _) : base(_) { }
    47     protected HeuristicOptimizationEngineAlgorithm(HeuristicOptimizationEngineAlgorithm original, Cloner cloner) : base(original, cloner) { }
     78    protected HeuristicOptimizationEngineAlgorithm(HeuristicOptimizationEngineAlgorithm original, Cloner cloner) : base(original, cloner) {
     79      SolutionCreatorParameter = cloner.Clone(original.SolutionCreatorParameter);
     80
     81      RegisterEventHandlers();
     82    }
     83
     84    [StorableHook(HookType.AfterDeserialization)]
     85    private void AfterDeserialization() {
     86      RegisterEventHandlers();
     87    }
    4888
    4989    #region Events
     90    private void RegisterEventHandlers() {
     91      ParameterChangeHandler<ISolutionCreator>.Create(SolutionCreatorParameter, SolutionCreatorOnChanged);
     92    }
    5093    protected override void DeregisterProblemEvents() {
    51       Problem.SolutionCreatorChanged -= new EventHandler(Problem_SolutionCreatorChanged);
    52       Problem.EvaluatorChanged -= new EventHandler(Problem_EvaluatorChanged);
     94      Problem.EvaluatorChanged -= Problem_EvaluatorChanged;
    5395      base.DeregisterProblemEvents();
    5496    }
    5597    protected override void RegisterProblemEvents() {
    5698      base.RegisterProblemEvents();
    57       Problem.SolutionCreatorChanged += new EventHandler(Problem_SolutionCreatorChanged);
    58       Problem.EvaluatorChanged += new EventHandler(Problem_EvaluatorChanged);
     99      Problem.EvaluatorChanged += Problem_EvaluatorChanged;
     100    }
     101    protected override void OnProblemChanged() {
     102      base.OnProblemChanged();
     103      SolutionCreatorParameter.Repopulate(Problem.Operators);
    59104    }
    60105
    61     protected virtual void Problem_SolutionCreatorChanged(object sender, EventArgs e) { }
     106    protected virtual void SolutionCreatorOnChanged() { }
    62107    protected virtual void Problem_EvaluatorChanged(object sender, EventArgs e) { }
     108
     109    protected override void Problem_OperatorsChanged(object sender, EventArgs e) {
     110      base.Problem_OperatorsChanged(sender, e);
     111      SolutionCreatorParameter.Repopulate(Problem.Operators);
     112    }
    63113    #endregion
    64114  }
Note: See TracChangeset for help on using the changeset viewer.