1 | #region License Information
|
---|
2 | /* HeuristicLab
|
---|
3 | * Copyright (C) 2002-2018 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 |
|
---|
22 | using System.Collections.Generic;
|
---|
23 | using HEAL.Attic;
|
---|
24 | using HeuristicLab.Common;
|
---|
25 | using HeuristicLab.Core;
|
---|
26 | using HeuristicLab.Optimization;
|
---|
27 | using HeuristicLab.Parameters;
|
---|
28 |
|
---|
29 | namespace HeuristicLab.Analysis.FitnessLandscape {
|
---|
30 | [StorableType("19468006-B8AE-485A-BECC-2E4DD0A0B059")]
|
---|
31 | public abstract class AlgorithmCharacteristicCalculator<TAlgorithm> : CharacteristicCalculator
|
---|
32 | where TAlgorithm : class, IAlgorithm {
|
---|
33 |
|
---|
34 | public override IProblem Problem {
|
---|
35 | get { return base.Problem; }
|
---|
36 | set {
|
---|
37 | base.Problem = value;
|
---|
38 | Algorithm.Problem = value;
|
---|
39 | }
|
---|
40 | }
|
---|
41 |
|
---|
42 | [Storable]
|
---|
43 | private ValueParameter<TAlgorithm> algorithmParameter;
|
---|
44 | public IValueParameter<TAlgorithm> AlgorithmParameter { get { return algorithmParameter; } }
|
---|
45 | public TAlgorithm Algorithm {
|
---|
46 | get { return algorithmParameter.Value; }
|
---|
47 | set { algorithmParameter.Value = value; }
|
---|
48 | }
|
---|
49 |
|
---|
50 | [StorableConstructor]
|
---|
51 | protected AlgorithmCharacteristicCalculator(StorableConstructorFlag _) : base(_) { }
|
---|
52 | protected AlgorithmCharacteristicCalculator(AlgorithmCharacteristicCalculator<TAlgorithm> original, Cloner cloner)
|
---|
53 | : base(original, cloner) {
|
---|
54 | algorithmParameter = cloner.Clone(original.algorithmParameter);
|
---|
55 | }
|
---|
56 | protected AlgorithmCharacteristicCalculator() {
|
---|
57 | Parameters.Add(algorithmParameter = new ValueParameter<TAlgorithm>("Algorithm", "The algorithm that calculates characteristics."));
|
---|
58 | }
|
---|
59 | protected AlgorithmCharacteristicCalculator(TAlgorithm algorithm) {
|
---|
60 | Parameters.Add(algorithmParameter = new ValueParameter<TAlgorithm>("Algorithm", "The algorithm that calculates characteristics.", algorithm));
|
---|
61 | }
|
---|
62 |
|
---|
63 | public override bool CanCalculate() {
|
---|
64 | return Algorithm != null
|
---|
65 | && Problem != null
|
---|
66 | && Algorithm.ProblemType.IsAssignableFrom(Problem.GetType());
|
---|
67 | }
|
---|
68 |
|
---|
69 | public override IEnumerable<IResult> Calculate() {
|
---|
70 | Algorithm.Prepare(true);
|
---|
71 | Algorithm.Start();
|
---|
72 |
|
---|
73 | foreach (var p in characteristics.CheckedItems) {
|
---|
74 | yield return new Result(p.Value.Value, Algorithm.Results[p.Value.Value].Value);
|
---|
75 | }
|
---|
76 | Algorithm.Prepare(true);
|
---|
77 | }
|
---|
78 | }
|
---|
79 | }
|
---|