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/Problems
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/HeuristicOptimizationProblem.cs

    r17513 r17695  
    2929  [Item("Heuristic Optimization Problem", "Represents the base class for a heuristic optimization problem.")]
    3030  [StorableType("DE0478BA-3797-4AC3-9A89-3734D2643823")]
    31   public abstract class HeuristicOptimizationProblem<T, U> : EncodedProblem, IHeuristicOptimizationProblem
    32     where T : class, IEvaluator
    33     where U : class, ISolutionCreator {
     31  public abstract class HeuristicOptimizationProblem<T> : EncodedProblem, IHeuristicOptimizationProblem
     32    where T : class, IEvaluator {
    3433    private const string EvaluatorParameterName = "Evaluator";
    35     private const string SolutionCreateParameterName = "SolutionCreator";
    3634
    3735    [StorableConstructor]
    3836    protected HeuristicOptimizationProblem(StorableConstructorFlag _) : base(_) { }
    39     protected HeuristicOptimizationProblem(HeuristicOptimizationProblem<T, U> original, Cloner cloner)
     37    protected HeuristicOptimizationProblem(HeuristicOptimizationProblem<T> original, Cloner cloner)
    4038      : base(original, cloner) {
    4139      RegisterEventHandlers();
     
    4543      : base() {
    4644      Parameters.Add(new ValueParameter<T>(EvaluatorParameterName, "The operator used to evaluate a solution."));
    47       Parameters.Add(new ValueParameter<U>(SolutionCreateParameterName, "The operator to create a solution."));
    4845      RegisterEventHandlers();
    4946    }
    5047
    51     protected HeuristicOptimizationProblem(T evaluator, U solutionCreator)
     48    protected HeuristicOptimizationProblem(T evaluator)
    5249      : base() {
    5350      Parameters.Add(new ValueParameter<T>(EvaluatorParameterName, "The operator used to evaluate a solution.", evaluator));
    54       Parameters.Add(new ValueParameter<U>(SolutionCreateParameterName, "The operator to create a solution.", solutionCreator));
    5551      RegisterEventHandlers();
    5652    }
     
    6359    private void RegisterEventHandlers() {
    6460      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
    65       SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
    6661    }
    6762
     
    7671    IEvaluator IHeuristicOptimizationProblem.Evaluator { get { return Evaluator; } }
    7772    IParameter IHeuristicOptimizationProblem.EvaluatorParameter { get { return EvaluatorParameter; } }
    78 
    79     public U SolutionCreator {
    80       get { return (U)SolutionCreatorParameter.Value; }
    81       protected set { SolutionCreatorParameter.Value = value; }
    82     }
    83     public IValueParameter SolutionCreatorParameter {
    84       get { return (IValueParameter)Parameters[SolutionCreateParameterName]; }
    85     }
    86     ISolutionCreator IHeuristicOptimizationProblem.SolutionCreator { get { return SolutionCreator; } }
    87     IParameter IHeuristicOptimizationProblem.SolutionCreatorParameter { get { return SolutionCreatorParameter; } }
    8873    #endregion
    8974
     
    9883        handler(this, EventArgs.Empty);
    9984    }
    100 
    101     private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
    102       OnSolutionCreatorChanged();
    103     }
    104     public event EventHandler SolutionCreatorChanged;
    105     protected virtual void OnSolutionCreatorChanged() {
    106       EventHandler handler = SolutionCreatorChanged;
    107       if (handler != null)
    108         handler(this, EventArgs.Empty);
    109     }
    11085    #endregion
    11186  }
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/MultiObjectiveHeuristicOptimizationProblem.cs

    r17317 r17695  
    3030  [Item("Multi-Objective Heuristic Optimization Problem", "A base class for multi-objective heuristic optimization problems.")]
    3131  [StorableType("C46643E3-7144-4884-A30A-5329BD80DC4E")]
    32   public abstract class MultiObjectiveHeuristicOptimizationProblem<T, U> : HeuristicOptimizationProblem<T, U>, IMultiObjectiveHeuristicOptimizationProblem
    33     where T : class, IMultiObjectiveEvaluator
    34     where U : class, ISolutionCreator {
     32  public abstract class MultiObjectiveHeuristicOptimizationProblem<T> : HeuristicOptimizationProblem<T>, IMultiObjectiveHeuristicOptimizationProblem
     33    where T : class, IMultiObjectiveEvaluator {
    3534    private const string MaximizationParameterName = "Maximization";
    3635
    3736    [StorableConstructor]
    3837    protected MultiObjectiveHeuristicOptimizationProblem(StorableConstructorFlag _) : base(_) { }
    39     protected MultiObjectiveHeuristicOptimizationProblem(MultiObjectiveHeuristicOptimizationProblem<T, U> original, Cloner cloner)
     38    protected MultiObjectiveHeuristicOptimizationProblem(MultiObjectiveHeuristicOptimizationProblem<T> original, Cloner cloner)
    4039      : base(original, cloner) {
    4140      RegisterEventHandlers();
     
    4847    }
    4948
    50     protected MultiObjectiveHeuristicOptimizationProblem(T evaluator, U solutionCreator)
    51       : base(evaluator, solutionCreator) {
     49    protected MultiObjectiveHeuristicOptimizationProblem(T evaluator)
     50      : base(evaluator) {
    5251      Parameters.Add(new ValueParameter<BoolArray>(MaximizationParameterName, "Determines for each objective whether it should be maximized or minimized."));
    5352
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/SingleObjectiveHeuristicOptimizationProblem.cs

    r17317 r17695  
    3030  [Item("Single-Objective Heuristic OptimizationProblem", "A base class for single-objective heuristic optimization problems.")]
    3131  [StorableType("DFD5588E-6AB2-4712-9083-A405EF21226F")]
    32   public abstract class SingleObjectiveHeuristicOptimizationProblem<T, U> : HeuristicOptimizationProblem<T, U>, ISingleObjectiveHeuristicOptimizationProblem
    33     where T : class, ISingleObjectiveEvaluator
    34     where U : class, ISolutionCreator {
     32  public abstract class SingleObjectiveHeuristicOptimizationProblem<T> : HeuristicOptimizationProblem<T>, ISingleObjectiveHeuristicOptimizationProblem
     33    where T : class, ISingleObjectiveEvaluator {
    3534    private const string MaximizationParameterName = "Maximization";
    3635    private const string BestKnownQualityParameterName = "BestKnownQuality";
     
    3837    [StorableConstructor]
    3938    protected SingleObjectiveHeuristicOptimizationProblem(StorableConstructorFlag _) : base(_) { }
    40     protected SingleObjectiveHeuristicOptimizationProblem(SingleObjectiveHeuristicOptimizationProblem<T, U> original, Cloner cloner)
     39    protected SingleObjectiveHeuristicOptimizationProblem(SingleObjectiveHeuristicOptimizationProblem<T> original, Cloner cloner)
    4140      : base(original, cloner) {
    4241      RegisterEventHandlers();
     
    5049    }
    5150
    52     protected SingleObjectiveHeuristicOptimizationProblem(T evaluator, U solutionCreator)
    53       : base(evaluator, solutionCreator) {
     51    protected SingleObjectiveHeuristicOptimizationProblem(T evaluator)
     52      : base(evaluator) {
    5453      Parameters.Add(new ValueParameter<BoolValue>(MaximizationParameterName, "Set to false if the problem should be minimized.", new BoolValue()));
    5554      Parameters.Add(new OptionalValueParameter<DoubleValue>(BestKnownQualityParameterName, "The quality of the best known solution of this problem."));
  • branches/2521_ProblemRefactoring/HeuristicLab.Optimization/3.3/Problems/UserDefinedProblem.cs

    r17612 r17695  
    6262      get { return MaximizationParameter; }
    6363    }
    64     public ValueParameter<ISolutionCreator> SolutionCreatorParameter {
    65       get { return (ValueParameter<ISolutionCreator>)Parameters["SolutionCreator"]; }
    66     }
    67     IParameter IHeuristicOptimizationProblem.SolutionCreatorParameter {
    68       get { return SolutionCreatorParameter; }
    69     }
    7064    IParameter IHeuristicOptimizationProblem.EvaluatorParameter {
    7165      get { return EvaluatorParameter; }
     
    8983      get { return MaximizationParameter.Value; }
    9084      set { MaximizationParameter.Value = value; }
    91     }
    92     public ISolutionCreator SolutionCreator {
    93       get { return SolutionCreatorParameter.Value; }
    94       set { SolutionCreatorParameter.Value = value; }
    95     }
    96     ISolutionCreator IHeuristicOptimizationProblem.SolutionCreator {
    97       get { return SolutionCreatorParameter.Value; }
    9885    }
    9986    public ISingleObjectiveEvaluator Evaluator {
     
    138125      : base() {
    139126      Parameters.Add(new ValueParameter<ISingleObjectiveEvaluator>("Evaluator", "The evaluator that collects the values to exchange.", new EmptyUserDefinedProblemEvaluator()));
    140       Parameters.Add(new ValueParameter<ISolutionCreator>("SolutionCreator", "An operator to create the solution components."));
    141127      Parameters.Add(new ValueParameter<BoolValue>("Maximization", "Set to false as most test functions are minimization problems.", new BoolValue(false)));
    142128      Parameters.Add(new OptionalValueParameter<DoubleValue>("BestKnownQuality", "The quality of the best known solution of this problem."));
     
    156142
    157143    #region Events
    158     public event EventHandler SolutionCreatorChanged;
    159     private void OnSolutionCreatorChanged() {
    160       EventHandler handler = SolutionCreatorChanged;
    161       if (handler != null) handler(this, EventArgs.Empty);
    162     }
    163144    public event EventHandler EvaluatorChanged;
    164145    private void OnEvaluatorChanged() {
     
    174155
    175156    #region Event handlers
    176     private void SolutionCreatorParameter_ValueChanged(object sender, EventArgs e) {
    177       OnSolutionCreatorChanged();
    178     }
    179157    private void EvaluatorParameter_ValueChanged(object sender, EventArgs e) {
    180158      if (Evaluator != null)
     
    202180    #region Helpers
    203181    private void RegisterEventHandlers() {
    204       SolutionCreatorParameter.ValueChanged += new EventHandler(SolutionCreatorParameter_ValueChanged);
    205182      EvaluatorParameter.ValueChanged += new EventHandler(EvaluatorParameter_ValueChanged);
    206183      if (Evaluator != null)
Note: See TracChangeset for help on using the changeset viewer.