Changeset 13594 for branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/ProblemCharacteristicAnalysis
- Timestamp:
- 02/07/16 23:14:22 (9 years ago)
- Location:
- branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/ProblemCharacteristicAnalysis
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/ProblemCharacteristicAnalysis/CharacteristicCalculator.cs
r13551 r13594 20 20 #endregion 21 21 22 using System.Collections.Generic;23 22 using HeuristicLab.Common; 24 23 using HeuristicLab.Core; 24 using HeuristicLab.Data; 25 25 using HeuristicLab.Optimization; 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using System.Collections.Generic; 27 28 28 29 namespace HeuristicLab.Problems.CharacteristicAnalysis { 29 30 [Item("Characteristic Calculator", "")] 30 31 [StorableClass] 31 public abstract class CharacteristicCalculator : NamedItem, ICharacteristicCalculator {32 public abstract class CharacteristicCalculator : ParameterizedNamedItem, ICharacteristicCalculator { 32 33 33 public abstract IEnumerable<string> Characteristics { get; } 34 [Storable] 35 public IProblem Problem { get; set; } 36 37 [Storable] 38 protected CheckedItemList<StringValue> characteristics; 39 public ReadOnlyCheckedItemList<StringValue> Characteristics { get { return characteristics.AsReadOnly(); } } 34 40 35 41 [StorableConstructor] 36 42 protected CharacteristicCalculator(bool deserializing) : base(deserializing) { } 37 protected CharacteristicCalculator(CharacteristicCalculator original, Cloner cloner) : base(original, cloner) { } 43 protected CharacteristicCalculator(CharacteristicCalculator original, Cloner cloner) 44 : base(original, cloner) { 45 characteristics = cloner.Clone(original.characteristics); 46 Problem = cloner.Clone(original.Problem); 47 } 38 48 protected CharacteristicCalculator() 39 49 : base() { 40 50 name = ItemName; 41 51 description = ItemDescription; 52 characteristics = new CheckedItemList<StringValue>(); 42 53 } 43 54 44 public abstract bool CanCalculate( IProblem problem);55 public abstract bool CanCalculate(); 45 56 46 public abstract IEnumerable< KeyValuePair<string, IItem>> Calculate(IProblem problem, IEnumerable<string> characteristics = null);57 public abstract IEnumerable<IResult> Calculate(); 47 58 } 48 59 } -
branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/ProblemCharacteristicAnalysis/QAP/QAPCharacteristicCalculator.cs
r13551 r13594 20 20 #endregion 21 21 22 using System;23 using System.Collections.Generic;24 22 using HeuristicLab.Common; 25 23 using HeuristicLab.Core; 24 using HeuristicLab.Data; 26 25 using HeuristicLab.Optimization; 27 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 28 27 using HeuristicLab.Problems.QuadraticAssignment; 28 using System; 29 using System.Collections.Generic; 30 using System.Linq; 29 31 30 32 namespace HeuristicLab.Problems.CharacteristicAnalysis.QAP { … … 33 35 public sealed class QAPCharacteristicCalculator : CharacteristicCalculator { 34 36 35 public override IEnumerable<string> Characteristics { 36 get { 37 return new[] { "Dimension", 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 42 "FlowDominance", "DistanceDominance", 39 43 "FlowAsymmetry", "DistanceAsymmetry", 40 44 "FlowSparsity", "DistanceSparsity", 41 45 "FlowSkewness", "DistanceSkewness", 42 "FlowDisparity", "DistanceDisparity" }; 43 } 46 "FlowDisparity", "DistanceDisparity" }.Select(x => new StringValue(x)).ToList()); 44 47 } 45 46 [StorableConstructor]47 private QAPCharacteristicCalculator(bool deserializing) : base(deserializing) { }48 private QAPCharacteristicCalculator(QAPCharacteristicCalculator original, Cloner cloner) : base(original, cloner) { }49 public QAPCharacteristicCalculator() { }50 48 51 49 public override IDeepCloneable Clone(Cloner cloner) { … … 53 51 } 54 52 55 public override bool CanCalculate( IProblem problem) {56 return problem is QuadraticAssignmentProblem;53 public override bool CanCalculate() { 54 return Problem is QuadraticAssignmentProblem; 57 55 } 58 56 59 public override IEnumerable<KeyValuePair<string, IItem>> Calculate(IProblem problem, IEnumerable<string> characteristics = null) { 60 var qap = problem as QuadraticAssignmentProblem; 61 if (qap == null) throw new ArgumentException("Instance is not of type QuadraticAssignmentProblem", "problem"); 62 var allowed = new HashSet<string>(characteristics ?? Characteristics); 63 if (allowed.Contains("Dimension")) 64 yield return new KeyValuePair<string, IItem>("Dimension", new Data.IntValue(qap.Weights.Rows)); 65 if (allowed.Contains("FlowDominance")) 66 yield return new KeyValuePair<string, IItem>("FlowDominance", new Data.DoubleValue(DoubleMatrixCharacteristicCalculator.CoeffVariation(qap.Weights))); 67 if (allowed.Contains("DistanceDominance")) 68 yield return new KeyValuePair<string, IItem>("DistanceDominance", new Data.DoubleValue(DoubleMatrixCharacteristicCalculator.CoeffVariation(qap.Distances))); 69 if (allowed.Contains("FlowAsymmetry")) 70 yield return new KeyValuePair<string, IItem>("FlowAsymmetry", new Data.DoubleValue(DoubleMatrixCharacteristicCalculator.Asymmetry(qap.Weights))); 71 if (allowed.Contains("DistanceAsymmetry")) 72 yield return new KeyValuePair<string, IItem>("DistanceAsymmetry", new Data.DoubleValue(DoubleMatrixCharacteristicCalculator.Asymmetry(qap.Distances))); 73 if (allowed.Contains("FlowSparsity")) 74 yield return new KeyValuePair<string, IItem>("FlowSparsity", new Data.DoubleValue(DoubleMatrixCharacteristicCalculator.Sparsity(qap.Weights))); 75 if (allowed.Contains("DistanceSparsity")) 76 yield return new KeyValuePair<string, IItem>("DistanceSparsity", new Data.DoubleValue(DoubleMatrixCharacteristicCalculator.Sparsity(qap.Distances))); 77 if (allowed.Contains("FlowSkewness")) 78 yield return new KeyValuePair<string, IItem>("FlowSkewness", new Data.DoubleValue(DoubleMatrixCharacteristicCalculator.Skewness(qap.Weights))); 79 if (allowed.Contains("DistanceSkewness")) 80 yield return new KeyValuePair<string, IItem>("DistanceSkewness", new Data.DoubleValue(DoubleMatrixCharacteristicCalculator.Skewness(qap.Distances))); 81 if (allowed.Contains("FlowDisparity")) 82 yield return new KeyValuePair<string, IItem>("FlowDisparity", new Data.DoubleValue(DoubleMatrixCharacteristicCalculator.Disparity(qap.Weights))); 83 if (allowed.Contains("DistanceDisparity")) 84 yield return new KeyValuePair<string, IItem>("DistanceDisparity", new Data.DoubleValue(DoubleMatrixCharacteristicCalculator.Disparity(qap.Distances))); 57 public override IEnumerable<IResult> Calculate() { 58 var qap = Problem as QuadraticAssignmentProblem; 59 if (qap == null) throw new ArgumentException("Instance is not of type QuadraticAssignmentProblem"); 60 foreach (var chara in characteristics.CheckedItems.Select(x => x.Value.Value)) { 61 if (chara == "Dimension") 62 yield return new Result(chara, new IntValue(qap.Weights.Rows)); 63 if (chara == "FlowDominance") 64 yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.CoeffVariation(qap.Weights))); 65 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))); 71 if (chara == "FlowSparsity") 72 yield return new Result(chara, new DoubleValue(DoubleMatrixCharacteristicCalculator.Sparsity(qap.Weights))); 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))); 83 } 85 84 } 86 85 }
Note: See TracChangeset
for help on using the changeset viewer.