Free cookie consent management tool by TermsFeed Policy Generator

source: branches/2457_ExpertSystem/HeuristicLab.Analysis.FitnessLandscape/3.3/CharacteristicCalculator/QAP/QAPCharacteristicCalculator.cs

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

#2457: adapted to trunk

File size: 4.1 KB
RevLine 
[16137]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.Collections.Generic;
24using System.Linq;
[16958]25using HEAL.Attic;
[16137]26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29using HeuristicLab.Optimization;
30using HeuristicLab.Problems.QuadraticAssignment;
31
32namespace HeuristicLab.Analysis.FitnessLandscape {
33  [Item("QAP Characteristic Calculator", "")]
[16958]34  [StorableType("84B82178-F412-412B-B388-4288AA15B11D")]
[16137]35  public sealed class QAPCharacteristicCalculator : CharacteristicCalculator {
36
37    [StorableConstructor]
[16958]38    private QAPCharacteristicCalculator(StorableConstructorFlag _) : base(_) { }
[16137]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        else if (chara == "FlowDominance")
64          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.CoeffVariation(qap.Weights)));
65        else if (chara == "DistanceDominance")
66          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.CoeffVariation(qap.Distances)));
67        else if (chara == "FlowAsymmetry")
68          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.Asymmetry(qap.Weights)));
69        else if (chara == "DistanceAsymmetry")
70          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.Asymmetry(qap.Distances)));
71        else if (chara == "FlowSparsity")
72          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.Sparsity(qap.Weights)));
73        else if (chara == "DistanceSparsity")
74          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.Sparsity(qap.Distances)));
75        else if (chara == "FlowSkewness")
76          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.Skewness(qap.Weights)));
77        else if (chara == "DistanceSkewness")
78          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.Skewness(qap.Distances)));
79        else if (chara == "FlowDisparity")
80          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.Disparity(qap.Weights)));
81        else if (chara == "DistanceDisparity")
82          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.Disparity(qap.Distances)));
83      }
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.