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 |
|
---|
22 | using System;
|
---|
23 | using System.Collections.Generic;
|
---|
24 | using System.Linq;
|
---|
25 | using HeuristicLab.Common;
|
---|
26 | using HeuristicLab.Core;
|
---|
27 | using HeuristicLab.Data;
|
---|
28 | using HeuristicLab.Optimization;
|
---|
29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
30 | using HeuristicLab.Problems.GeneralizedQuadraticAssignment;
|
---|
31 |
|
---|
32 | namespace 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.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 | }
|
---|