Free cookie consent management tool by TermsFeed Policy Generator

source: branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment/3.3/Analyzers/GQAPPopulationDiversityAnalyzer.cs @ 15490

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

#1614:

  • branched optimization
  • adapted references
  • renamed plugin
File size: 3.6 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.Analysis;
23using HeuristicLab.Common;
24using HeuristicLab.Core;
25using HeuristicLab.Data;
26using HeuristicLab.Encodings.IntegerVectorEncoding;
27using HeuristicLab.Parameters;
28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
29
30namespace HeuristicLab.Problems.GeneralizedQuadraticAssignment.Analyzers {
31  [Item("GQAPPopulationDiversityAnalyzer", "Analyzes the population diversity.")]
32  [StorableClass]
33  public class GQAPPopulationDiversityAnalyzer : PopulationDiversityAnalyzer<IntegerVector>, IAssignmentsAwareGQAPOperator, IQualitiesAwareGQAPOperator {
34
35    public IScopeTreeLookupParameter<IntegerVector> AssignmentParameter {
36      get { return SolutionParameter; }
37    }
38    public new ILookupParameter<BoolValue> MaximizationParameter {
39      get { return base.MaximizationParameter; }
40    }
41    public new IScopeTreeLookupParameter<DoubleValue> QualityParameter {
42      get { return base.QualityParameter; }
43    }
44    public IScopeTreeLookupParameter<DoubleValue> FlowDistanceQualityParameter {
45      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["FlowDistanceQuality"]; }
46    }
47    public IScopeTreeLookupParameter<DoubleValue> InstallationQualityParameter {
48      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["InstallationQuality"]; }
49    }
50    public IScopeTreeLookupParameter<DoubleValue> OverbookedCapacityParameter {
51      get { return (IScopeTreeLookupParameter<DoubleValue>)Parameters["OverbookedCapacity"]; }
52    }
53
54    [StorableConstructor]
55    protected GQAPPopulationDiversityAnalyzer(bool deserializing) : base(deserializing) { }
56    protected GQAPPopulationDiversityAnalyzer(GQAPPopulationDiversityAnalyzer original, Cloner cloner) : base(original, cloner) { }
57    public GQAPPopulationDiversityAnalyzer()
58      : base() {
59      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("FlowDistanceQuality", GQAPEvaluator.FlowDistanceQualityDescription));
60      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("InstallationQuality", GQAPEvaluator.InstallationQualityDescription));
61      Parameters.Add(new ScopeTreeLookupParameter<DoubleValue>("OverbookedCapacity", GQAPEvaluator.OverbookedCapacityDescription));
62    }
63
64    public override IDeepCloneable Clone(Cloner cloner) {
65      return new GQAPPopulationDiversityAnalyzer(this, cloner);
66    }
67
68    protected override double[,] CalculateSimilarities(IntegerVector[] solutions) {
69      double[,] result = new double[solutions.Length, solutions.Length];
70      for (int i = 0; i < solutions.Length - 1; i++)
71        for (int j = i + 1; j < solutions.Length; j++) {
72          result[i, j] = HammingSimilarityCalculator.CalculateSimilarity(solutions[i], solutions[j]);
73          result[j, i] = result[i, j];
74        }
75      return result;
76    }
77  }
78}
Note: See TracBrowser for help on using the repository browser.