[13551] | 1 | #region License Information
|
---|
| 2 | /* HeuristicLab
|
---|
[13667] | 3 | * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
|
---|
[13551] | 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 |
|
---|
[15713] | 22 | using System;
|
---|
| 23 | using System.Collections.Generic;
|
---|
| 24 | using System.Linq;
|
---|
[13551] | 25 | using HeuristicLab.Common;
|
---|
| 26 | using HeuristicLab.Core;
|
---|
[13594] | 27 | using HeuristicLab.Data;
|
---|
[13551] | 28 | using HeuristicLab.Optimization;
|
---|
| 29 | using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
|
---|
[15713] | 30 | using HeuristicLab.Problems.GeneralizedQuadraticAssignment;
|
---|
[13551] | 31 |
|
---|
[14678] | 32 | namespace HeuristicLab.Analysis.FitnessLandscape {
|
---|
[15713] | 33 | [Item("GQAP Characteristic Calculator", "")]
|
---|
[13551] | 34 | [StorableClass]
|
---|
[15713] | 35 | public sealed class GQAPCharacteristicCalculator : CharacteristicCalculator {
|
---|
[13551] | 36 |
|
---|
[13594] | 37 | [StorableConstructor]
|
---|
[15713] | 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",
|
---|
[13551] | 43 | "FlowDominance", "DistanceDominance",
|
---|
| 44 | "FlowSparsity", "DistanceSparsity",
|
---|
[15713] | 45 | "DemandDominance", "CapacityDominance",
|
---|
| 46 | "Utilization", "BasicFeasibility",
|
---|
| 47 | }.Select(x => new StringValue(x)).ToList());
|
---|
[13551] | 48 | }
|
---|
| 49 |
|
---|
| 50 | public override IDeepCloneable Clone(Cloner cloner) {
|
---|
[15713] | 51 | return new GQAPCharacteristicCalculator(this, cloner);
|
---|
[13551] | 52 | }
|
---|
| 53 |
|
---|
[13594] | 54 | public override bool CanCalculate() {
|
---|
[15713] | 55 | return Problem is GQAP;
|
---|
[13551] | 56 | }
|
---|
| 57 |
|
---|
[13594] | 58 | public override IEnumerable<IResult> Calculate() {
|
---|
[15713] | 59 | var gqap = Problem as GQAP;
|
---|
| 60 | if (gqap == null) throw new ArgumentException("Instance is not of type GQAP");
|
---|
| 61 | var inst = gqap.ProblemInstance;
|
---|
[13594] | 62 | foreach (var chara in characteristics.CheckedItems.Select(x => x.Value.Value)) {
|
---|
| 63 | if (chara == "Dimension")
|
---|
[15713] | 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));
|
---|
[13594] | 67 | if (chara == "FlowDominance")
|
---|
[15713] | 68 | yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.CoeffVariation(inst.Weights)));
|
---|
[13594] | 69 | if (chara == "DistanceDominance")
|
---|
[15713] | 70 | yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.CoeffVariation(inst.Distances)));
|
---|
[13594] | 71 | if (chara == "FlowSparsity")
|
---|
[15713] | 72 | yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.Sparsity(inst.Weights)));
|
---|
[13594] | 73 | if (chara == "DistanceSparsity")
|
---|
[15713] | 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));
|
---|
[13594] | 83 | }
|
---|
[13551] | 84 | }
|
---|
| 85 | }
|
---|
| 86 | }
|
---|