Free cookie consent management tool by TermsFeed Policy Generator

source: branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/Algorithms/FLACharacterizer.cs @ 15331

Last change on this file since 15331 was 15331, checked in by abeham, 7 years ago

#2457: added FLA Characterizer algorithm

File size: 2.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2016 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;
23using System.Threading;
24using HeuristicLab.Common;
25using HeuristicLab.Core;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
29
30namespace HeuristicLab.Analysis.FitnessLandscape {
31  [Item("FLA Characterizer", "An algorithm that executes a characteristic calculator.")]
32  [StorableClass]
33  [Creatable(CreatableAttribute.Categories.TestingAndAnalysis + CreatableAttribute.Categories.SplitToken + "1" + CreatableAttribute.Categories.OrderToken + "FLA", Priority = 300)]
34  public sealed class FLACharacterizer : BasicAlgorithm {
35    public override bool SupportsPause { get { return false; } }
36   
37    public IValueParameter<ICharacteristicCalculator> CalculatorParameter {
38      get { return (IValueParameter<ICharacteristicCalculator>)Parameters["Calculator"]; }
39    }
40
41    [StorableConstructor]
42    private FLACharacterizer(bool deserializing) : base(deserializing) { }
43    private FLACharacterizer(FLACharacterizer original, Cloner cloner) : base(original, cloner) { }
44    public FLACharacterizer() : base() {
45      Parameters.Add(new ValueParameter<ICharacteristicCalculator>("Calculator", "The FLA characteristic calculator.", new RandomWalkCalculator()));
46    }
47
48    public override IDeepCloneable Clone(Cloner cloner) {
49      return new FLACharacterizer(this, cloner);
50    }
51
52    protected override void Run(CancellationToken cancellationToken) {
53      var calculator = CalculatorParameter.Value;
54      calculator.Problem = Problem;
55      if (calculator.CanCalculate()) {
56        foreach (var result in calculator.Calculate()) {
57          Results.Add(result);
58        }
59      } else throw new InvalidOperationException("Calculator cannot be applied.");
60    }
61  }
62}
Note: See TracBrowser for help on using the repository browser.