Free cookie consent management tool by TermsFeed Policy Generator

source: branches/1614_GeneralizedQAP/HeuristicLab.Analysis.FitnessLandscape/3.3/ProblemCharacteristicAnalysis/GQAP/GQAPCharacteristicCalculator.cs @ 17573

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

#1614: updated to new persistence and .NET 4.6.1

File size: 4.0 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 System;
23using System.Collections.Generic;
24using System.Linq;
25using HEAL.Attic;
26using HeuristicLab.Common;
27using HeuristicLab.Core;
28using HeuristicLab.Data;
29using HeuristicLab.Optimization;
30using HeuristicLab.Problems.GeneralizedQuadraticAssignment;
31
32namespace HeuristicLab.Analysis.FitnessLandscape {
33  [Item("GQAP Characteristic Calculator", "")]
34  [StorableType("B587BC90-028E-4E8F-A4A6-5CD6677D5369")]
35  public sealed class GQAPCharacteristicCalculator : CharacteristicCalculator {
36
37    [StorableConstructor]
38    private GQAPCharacteristicCalculator(StorableConstructorFlag _) : base(_) { }
39    private GQAPCharacteristicCalculator(GQAPCharacteristicCalculator original, Cloner cloner) : base(original, cloner) { }
40    public GQAPCharacteristicCalculator() {
41      characteristics.AddRange(new[] {
42        "Dimension", "MNRatio",
43        "FlowDominance", "DistanceDominance",
44        "FlowSparsity", "DistanceSparsity",
45        "DemandDominance", "CapacityDominance",
46        "Utilization", "BasicFeasibility",
47      }.Select(x => new StringValue(x)).ToList());
48    }
49
50    public override IDeepCloneable Clone(Cloner cloner) {
51      return new GQAPCharacteristicCalculator(this, cloner);
52    }
53
54    public override bool CanCalculate() {
55      return Problem is GQAP;
56    }
57
58    public override IEnumerable<IResult> Calculate() {
59      var gqap = Problem as GQAP;
60      if (gqap == null) throw new ArgumentException("Instance is not of type GQAP");
61      var inst = gqap.ProblemInstance;
62      foreach (var chara in characteristics.CheckedItems.Select(x => x.Value.Value)) {
63        if (chara == "Dimension")
64          yield return new Result(chara, new IntValue(inst.Demands.Length));
65        if (chara == "MNRatio")
66          yield return new Result(chara, new DoubleValue(inst.Capacities.Length / (double)inst.Demands.Length));
67        if (chara == "FlowDominance")
68          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.CoeffVariationNonZeroes(inst.Weights)));
69        if (chara == "DistanceDominance")
70          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.CoeffVariationNonZeroes(inst.Distances)));
71        if (chara == "FlowSparsity")
72          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.Sparsity(inst.Weights)));
73        if (chara == "DistanceSparsity")
74          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.Sparsity(inst.Distances)));
75        if (chara == "DemandDominance")
76          yield return new Result(chara, new DoubleValue(inst.Demands.StandardDeviation() / inst.Demands.Average()));
77        if (chara == "CapacityDominance")
78          yield return new Result(chara, new DoubleValue(inst.Capacities.StandardDeviation() / inst.Capacities.Average()));
79        if (chara == "Utilization")
80          yield return new Result(chara, new DoubleValue(inst.Demands.Sum() / inst.Capacities.Sum()));
81        if (chara == "BasicFeasibility")
82          yield return new Result(chara, new DoubleValue(inst.Demands.Select(d => inst.Capacities.Count(c => d <= c)).Average() / inst.Capacities.Length));
83      }
84    }
85  }
86}
Note: See TracBrowser for help on using the repository browser.