Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior/3.3/Creators/BestIndividualWildcardCreator.cs @ 8267

Last change on this file since 8267 was 8267, checked in by ascheibe, 12 years ago

#1886 added wild card analyzer for the best individual

File size: 3.2 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2012 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Operators;
25using HeuristicLab.Optimization;
26using HeuristicLab.Parameters;
27using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
28
29namespace HeuristicLab.Analysis.AlgorithmBehavior {
30  using HeuristicLab.Data;
31  using HeuristicLab.Problems.TravelingSalesman;
32
33  /// <summary>
34  /// An operator that analyzes schemata.
35  /// </summary>
36  [Item("BestIndividualWildcardCreator", "An operator that analyzes schemata.")]
37  [StorableClass]
38  public sealed class BestIndividualWildcardCreator : SingleSuccessorOperator, IAnalyzer {
39    private const string ResultsParameterName = "Results";
40    private const string SchemataParameterName = "BestIndividualWildcards";
41    private const string BestSolutionParameterName = "Best TSP Solution";
42
43    #region IAnalyzer Members
44    public bool EnabledByDefault {
45      get { return true; }
46    }
47    #endregion
48
49    #region Parameter properties
50    public ILookupParameter<ResultCollection> ResultsParameter {
51      get { return (ILookupParameter<ResultCollection>)Parameters[ResultsParameterName]; }
52    }
53    #endregion
54
55    #region Properties
56    public ResultCollection Results {
57      get { return ResultsParameter.ActualValue; }
58    }
59    public PathTSPTour BestSolution {
60      get { return ((PathTSPTour)ResultsParameter.ActualValue[BestSolutionParameterName].Value); }
61    }
62    #endregion
63
64    [StorableConstructor]
65    private BestIndividualWildcardCreator(bool deserializing) : base(deserializing) { }
66    private BestIndividualWildcardCreator(BestIndividualWildcardCreator original, Cloner cloner) : base(original, cloner) { }
67    public BestIndividualWildcardCreator()
68      : base() {
69      Parameters.Add(new LookupParameter<ResultCollection>(ResultsParameterName, "The results collection where the analysis values should be stored."));
70    }
71
72    public override IDeepCloneable Clone(Cloner cloner) {
73      return new BestIndividualWildcardCreator(this, cloner);
74    }
75
76    public override IOperation Apply() {
77      var subtours = AlgorithmBehaviorHelpers.GenerateWildcardSchemata(BestSolution.Permutation);
78      subtours.Add(BestSolution.Permutation);
79      Results.Add(new Result(SchemataParameterName, new ItemArray<IntArray>(subtours)));
80      return base.Apply();
81    }
82  }
83}
Note: See TracBrowser for help on using the repository browser.