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

Last change on this file since 15713 was 15713, checked in by abeham, 4 years ago

#1614:

  • added additional constraint to benchmark data generator and updated one instance that was affected by this
  • added fitness landscape characteristics for the GQAP
  • fixed RLD analysis view to compensate for empty convergence graphs
  • fixed CPLEX solvers not using the obj value when the solver terminates (callback is not called if proven optimal solution is found)
  • added code for local solver to also check on final quality
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 HeuristicLab.Common;
26using HeuristicLab.Core;
27using HeuristicLab.Data;
28using HeuristicLab.Optimization;
29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
30using HeuristicLab.Problems.GeneralizedQuadraticAssignment;
31
32namespace HeuristicLab.Analysis.FitnessLandscape {
33  [Item("GQAP Characteristic Calculator", "")]
34  [StorableClass]
35  public sealed class GQAPCharacteristicCalculator : CharacteristicCalculator {
36
37    [StorableConstructor]
38    private GQAPCharacteristicCalculator(bool deserializing) : base(deserializing) { }
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.CoeffVariation(inst.Weights)));
69        if (chara == "DistanceDominance")
70          yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.CoeffVariation(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.