#region License Information /* HeuristicLab * Copyright (C) 2002-2016 Heuristic and Evolutionary Algorithms Laboratory (HEAL) * * This file is part of HeuristicLab. * * HeuristicLab is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * HeuristicLab is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with HeuristicLab. If not, see . */ #endregion using System; using System.Collections.Generic; using System.Linq; using HEAL.Attic; using HeuristicLab.Common; using HeuristicLab.Core; using HeuristicLab.Data; using HeuristicLab.Optimization; using HeuristicLab.Problems.QuadraticAssignment; namespace HeuristicLab.Analysis.FitnessLandscape { [Item("QAP Characteristic Calculator", "")] [StorableType("84B82178-F412-412B-B388-4288AA15B11D")] public sealed class QAPCharacteristicCalculator : CharacteristicCalculator { [StorableConstructor] private QAPCharacteristicCalculator(StorableConstructorFlag _) : base(_) { } private QAPCharacteristicCalculator(QAPCharacteristicCalculator original, Cloner cloner) : base(original, cloner) { } public QAPCharacteristicCalculator() { characteristics.AddRange(new[] { "Dimension", "FlowDominance", "DistanceDominance", "FlowAsymmetry", "DistanceAsymmetry", "FlowSparsity", "DistanceSparsity", "FlowSkewness", "DistanceSkewness", "FlowDisparity", "DistanceDisparity" }.Select(x => new StringValue(x)).ToList()); } public override IDeepCloneable Clone(Cloner cloner) { return new QAPCharacteristicCalculator(this, cloner); } public override bool CanCalculate() { return Problem is QuadraticAssignmentProblem; } public override IEnumerable Calculate() { var qap = Problem as QuadraticAssignmentProblem; if (qap == null) throw new ArgumentException("Instance is not of type QuadraticAssignmentProblem"); foreach (var chara in characteristics.CheckedItems.Select(x => x.Value.Value)) { if (chara == "Dimension") yield return new Result(chara, new IntValue(qap.Weights.Rows)); else if (chara == "FlowDominance") yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.CoeffVariation(qap.Weights))); else if (chara == "DistanceDominance") yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.CoeffVariation(qap.Distances))); else if (chara == "FlowAsymmetry") yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.Asymmetry(qap.Weights))); else if (chara == "DistanceAsymmetry") yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.Asymmetry(qap.Distances))); else if (chara == "FlowSparsity") yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.Sparsity(qap.Weights))); else if (chara == "DistanceSparsity") yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.Sparsity(qap.Distances))); else if (chara == "FlowSkewness") yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.Skewness(qap.Weights))); else if (chara == "DistanceSkewness") yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.Skewness(qap.Distances))); else if (chara == "FlowDisparity") yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.Disparity(qap.Weights))); else if (chara == "DistanceDisparity") yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristics.Disparity(qap.Distances))); } } } }