Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1614_GeneralizedQAP/HeuristicLab.Analysis.FitnessLandscape/3.3/ProblemCharacteristicAnalysis/QAP/QAPCharacteristicCalculator.cs @ 15702

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

#2457: worked on problem instance detection

File size: 4.2 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 HeuristicLab.Common;
23using HeuristicLab.Core;
24using HeuristicLab.Data;
25using HeuristicLab.Optimization;
26using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
27using HeuristicLab.Problems.QuadraticAssignment;
28using System;
29using System.Collections.Generic;
30using System.Linq;
31
32namespace HeuristicLab.Analysis.FitnessLandscape {
33  [Item("QAP Characteristic Calculator", "")]
34  [StorableClass]
35  public sealed class QAPCharacteristicCalculator : CharacteristicCalculator {
36
37    [StorableConstructor]
38    private QAPCharacteristicCalculator(bool deserializing) : base(deserializing) { }
39    private QAPCharacteristicCalculator(QAPCharacteristicCalculator original, Cloner cloner) : base(original, cloner) { }
40    public QAPCharacteristicCalculator() {
41      characteristics.AddRange(new[] { "Dimension",
42        "FlowDominance", "DistanceDominance",
43        "FlowAsymmetry", "DistanceAsymmetry",
44        "FlowSparsity", "DistanceSparsity",
45        "FlowSkewness", "DistanceSkewness",
46        "FlowDisparity", "DistanceDisparity" }.Select(x => new StringValue(x)).ToList());
47    }
48
49    public override IDeepCloneable Clone(Cloner cloner) {
50      return new QAPCharacteristicCalculator(this, cloner);
51    }
52
53    public override bool CanCalculate() {
54      return Problem is QuadraticAssignmentProblem;
55    }
56
57    public override IEnumerable<IResult> Calculate() {
58      var qap = Problem as QuadraticAssignmentProblem;
59      if (qap == null) throw new ArgumentException("Instance is not of type QuadraticAssignmentProblem");
60      foreach (var chara in characteristics.CheckedItems.Select(x => x.Value.Value)) {
61        if (chara == "Dimension")
62          yield return new Result(chara, new IntValue(qap.Weights.Rows));
63        if (chara == "FlowDominance")
64          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.CoeffVariation(qap.Weights)));
65        if (chara == "DistanceDominance")
66          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.CoeffVariation(qap.Distances)));
67        if (chara == "FlowAsymmetry")
68          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.Asymmetry(qap.Weights)));
69        if (chara == "DistanceAsymmetry")
70          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.Asymmetry(qap.Distances)));
71        if (chara == "FlowSparsity")
72          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.Sparsity(qap.Weights)));
73        if (chara == "DistanceSparsity")
74          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.Sparsity(qap.Distances)));
75        if (chara == "FlowSkewness")
76          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.Skewness(qap.Weights)));
77        if (chara == "DistanceSkewness")
78          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.Skewness(qap.Distances)));
79        if (chara == "FlowDisparity")
80          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.Disparity(qap.Weights)));
81        if (chara == "DistanceDisparity")
82          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.Disparity(qap.Distances)));
83      }
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.