Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1614_GeneralizedQAP/HeuristicLab.Analysis.FitnessLandscape/3.3/Algorithms/FLACharacterizer.cs @ 17607

Last change on this file since 17607 was 16728, checked in by abeham, 6 years ago

#1614: updated to new persistence and .NET 4.6.1

File size: 3.2 KB
RevLine 
[13583]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
[15331]22using System;
23using System.Threading;
[16728]24using HEAL.Attic;
[13583]25using HeuristicLab.Common;
26using HeuristicLab.Core;
[15331]27using HeuristicLab.Optimization;
28using HeuristicLab.Parameters;
[13583]29
30namespace HeuristicLab.Analysis.FitnessLandscape {
[15331]31  [Item("FLA Characterizer", "An algorithm that executes a characteristic calculator.")]
[16728]32  [StorableType("B8D4C686-FDFE-4110-96F8-588E294A06A3")]
[15331]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    }
[13583]40
[15332]41    public ICharacteristicCalculator Calculator {
42      get { return CalculatorParameter.Value; }
43    }
44
[13583]45    [StorableConstructor]
[16728]46    private FLACharacterizer(StorableConstructorFlag _) : base(_) { }
[15332]47    private FLACharacterizer(FLACharacterizer original, Cloner cloner)
48      : base(original, cloner) {
49      RegisterEventHandlers();
50    }
[15331]51    public FLACharacterizer() : base() {
52      Parameters.Add(new ValueParameter<ICharacteristicCalculator>("Calculator", "The FLA characteristic calculator.", new RandomWalkCalculator()));
[15332]53      RegisterEventHandlers();
[13583]54    }
55
56    public override IDeepCloneable Clone(Cloner cloner) {
[15331]57      return new FLACharacterizer(this, cloner);
[13583]58    }
[15332]59   
60    [StorableHook(HookType.AfterDeserialization)]
61    private void AfterDeserialization() {
62      RegisterEventHandlers();
63    }
[15331]64
[15332]65    private void RegisterEventHandlers() {
66      CalculatorParameter.ValueChanged += CalculatorParameterOnValueChanged;
67    }
68
69    private void CalculatorParameterOnValueChanged(object sender, EventArgs e) {
70      Calculator.Problem = Problem;
71    }
72
73    protected override void OnProblemChanged() {
74      base.OnProblemChanged();
75      Calculator.Problem = Problem;
76    }
77
[15331]78    protected override void Run(CancellationToken cancellationToken) {
[15332]79      var calculator = Calculator;
[15331]80      if (calculator.CanCalculate()) {
81        foreach (var result in calculator.Calculate()) {
82          Results.Add(result);
83        }
84      } else throw new InvalidOperationException("Calculator cannot be applied.");
85    }
[13583]86  }
87}
Note: See TracBrowser for help on using the repository browser.