Changeset 15713 for branches/1614_GeneralizedQAP/HeuristicLab.Analysis.FitnessLandscape/3.3/ProblemCharacteristicAnalysis/GQAP/GQAPCharacteristicCalculator.cs
 Timestamp:
 02/02/18 16:31:42 (4 years ago)
 Location:
 branches/1614_GeneralizedQAP/HeuristicLab.Analysis.FitnessLandscape/3.3/ProblemCharacteristicAnalysis/GQAP
 Files:

 1 added
 1 copied
Legend:
 Unmodified
 Added
 Removed

branches/1614_GeneralizedQAP/HeuristicLab.Analysis.FitnessLandscape/3.3/ProblemCharacteristicAnalysis/GQAP/GQAPCharacteristicCalculator.cs
r15702 r15713 20 20 #endregion 21 21 22 using System; 23 using System.Collections.Generic; 24 using System.Linq; 22 25 using HeuristicLab.Common; 23 26 using HeuristicLab.Core; … … 25 28 using HeuristicLab.Optimization; 26 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using HeuristicLab.Problems.QuadraticAssignment; 28 using System; 29 using System.Collections.Generic; 30 using System.Linq; 30 using HeuristicLab.Problems.GeneralizedQuadraticAssignment; 31 31 32 32 namespace HeuristicLab.Analysis.FitnessLandscape { 33 [Item(" QAP Characteristic Calculator", "")]33 [Item("GQAP Characteristic Calculator", "")] 34 34 [StorableClass] 35 public sealed class QAPCharacteristicCalculator : CharacteristicCalculator {35 public sealed class GQAPCharacteristicCalculator : CharacteristicCalculator { 36 36 37 37 [StorableConstructor] 38 private QAPCharacteristicCalculator(bool deserializing) : base(deserializing) { } 39 private QAPCharacteristicCalculator(QAPCharacteristicCalculator original, Cloner cloner) : base(original, cloner) { } 40 public QAPCharacteristicCalculator() { 41 characteristics.AddRange(new[] { "Dimension", 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", 42 43 "FlowDominance", "DistanceDominance", 43 "FlowAsymmetry", "DistanceAsymmetry",44 44 "FlowSparsity", "DistanceSparsity", 45 "FlowSkewness", "DistanceSkewness", 46 "FlowDisparity", "DistanceDisparity" }.Select(x => new StringValue(x)).ToList()); 45 "DemandDominance", "CapacityDominance", 46 "Utilization", "BasicFeasibility", 47 }.Select(x => new StringValue(x)).ToList()); 47 48 } 48 49 49 50 public override IDeepCloneable Clone(Cloner cloner) { 50 return new QAPCharacteristicCalculator(this, cloner);51 return new GQAPCharacteristicCalculator(this, cloner); 51 52 } 52 53 53 54 public override bool CanCalculate() { 54 return Problem is QuadraticAssignmentProblem;55 return Problem is GQAP; 55 56 } 56 57 57 58 public override IEnumerable<IResult> Calculate() { 58 var qap = Problem as QuadraticAssignmentProblem; 59 if (qap == null) throw new ArgumentException("Instance is not of type QuadraticAssignmentProblem"); 59 var gqap = Problem as GQAP; 60 if (gqap == null) throw new ArgumentException("Instance is not of type GQAP"); 61 var inst = gqap.ProblemInstance; 60 62 foreach (var chara in characteristics.CheckedItems.Select(x => x.Value.Value)) { 61 63 if (chara == "Dimension") 62 yield return new Result(chara, new IntValue(qap.Weights.Rows)); 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)); 63 67 if (chara == "FlowDominance") 64 yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.CoeffVariation( qap.Weights)));68 yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.CoeffVariation(inst.Weights))); 65 69 if (chara == "DistanceDominance") 66 yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.CoeffVariation(qap.Distances))); 67 if (chara == "FlowAsymmetry") 68 yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.Asymmetry(qap.Weights))); 69 if (chara == "DistanceAsymmetry") 70 yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.Asymmetry(qap.Distances))); 70 yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.CoeffVariation(inst.Distances))); 71 71 if (chara == "FlowSparsity") 72 yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.Sparsity( qap.Weights)));72 yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.Sparsity(inst.Weights))); 73 73 if (chara == "DistanceSparsity") 74 yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.Sparsity( qap.Distances)));75 if (chara == " FlowSkewness")76 yield return new Result(chara, new DoubleValue( DoubleMatrixCharacteristicCalculator.Skewness(qap.Weights)));77 if (chara == " DistanceSkewness")78 yield return new Result(chara, new DoubleValue( DoubleMatrixCharacteristicCalculator.Skewness(qap.Distances)));79 if (chara == " FlowDisparity")80 yield return new Result(chara, new DoubleValue( DoubleMatrixCharacteristicCalculator.Disparity(qap.Weights)));81 if (chara == " DistanceDisparity")82 yield return new Result(chara, new DoubleValue( DoubleMatrixCharacteristicCalculator.Disparity(qap.Distances)));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 83 } 84 84 }
Note: See TracChangeset
for help on using the changeset viewer.