Free cookie consent management tool by TermsFeed Policy Generator

source: branches/ProgrammableProblem/HeuristicLab.Problems.Programmable/3.3/New/SingleObjectiveProgrammableProblem.cs @ 11739

Last change on this file since 11739 was 11739, checked in by mkommend, 9 years ago

#2174: Worked on operators and programmable problem base classes and scripts.

File size: 2.7 KB
RevLine 
[10753]1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2014 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System.Linq;
23using HeuristicLab.Analysis;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Optimization;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Problems.Programmable {
30  [StorableClass]
[11739]31  public abstract class SingleObjectiveProgrammableProblem<TEncoding> : ProgrammableProblem<TEncoding, SingleObjectiveEvaluator>, ISingleObjectiveProblemDefinition
32  where TEncoding : class, IEncoding {
[10753]33    [StorableConstructor]
[10850]34    protected SingleObjectiveProgrammableProblem(bool deserializing) : base(deserializing) { }
[10753]35
[11739]36    protected SingleObjectiveProgrammableProblem(SingleObjectiveProgrammableProblem<TEncoding> original, Cloner cloner)
[10753]37      : base(original, cloner) {
[11739]38      ParameterizeOperators();
[10753]39    }
40
[11739]41    protected SingleObjectiveProgrammableProblem()
42      : base() {
[10753]43
44      Operators.Add(new BestScopeSolutionAnalyzer());
[11739]45      Operators.Add(new SingleObjectiveEvaluator());
[11396]46      Operators.Add(new SingleObjectiveAnalyzer());
[10753]47
[11739]48      ParameterizeOperators();
[10753]49    }
50
51    [StorableHook(HookType.AfterDeserialization)]
52    private void AfterDeserialization() {
[11739]53      ParameterizeOperators();
[10753]54    }
55
[11739]56    public abstract bool Maximization { get; }
57    public abstract double Evaluate(Individual individual, IRandom random);
58    public virtual void Analyze(Individual[] individuals, double[] qualities, ResultCollection results) { }
[10753]59
60
[11396]61    protected override void OnEvaluatorChanged() {
62      base.OnEvaluatorChanged();
[11739]63      ParameterizeOperators();
[11396]64    }
65
[11739]66    protected override void ParameterizeOperators() {
67      base.ParameterizeOperators();
68      foreach (var op in Operators.OfType<ISingleObjectiveEvaluationOperator>())
69        op.EvaluateFunc = Evaluate;
70      foreach (var op in Operators.OfType<ISingleObjectiveAnalysisOperator>())
71        op.AnalyzeAction = Analyze;
[11393]72    }
73
[10753]74  }
75}
Note: See TracBrowser for help on using the repository browser.