Changeset 13594 for branches/PerformanceComparison
- Timestamp:
- 02/07/16 23:14:22 (9 years ago)
- Location:
- branches/PerformanceComparison
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/CharacteristicCalculator/AdaptiveWalkCalculator.cs
r13583 r13594 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data; 24 25 using HeuristicLab.Optimization; 25 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 33 34 [StorableClass] 34 35 public class AdaptiveWalkCalculator : NamedItem, ICharacteristicCalculator { 36 37 [Storable] 38 private IProblem problem; 39 public IProblem Problem { 40 get { return problem; } 41 set { 42 if (problem == value) return; 43 problem = value; 44 var soProblem = problem as ISingleObjectiveHeuristicOptimizationProblem; 45 walker.Problem = soProblem; 46 } 47 } 48 35 49 [Storable] 36 50 private AdaptiveWalk walker; … … 40 54 private AdaptiveWalkCalculator(AdaptiveWalkCalculator original, Cloner cloner) 41 55 : base(original, cloner) { 56 problem = cloner.Clone(original.problem); 42 57 walker = cloner.Clone(original.walker); 58 characteristics = cloner.Clone(original.characteristics); 43 59 } 44 60 public AdaptiveWalkCalculator() { … … 46 62 Description = ItemDescription; 47 63 walker = new AdaptiveWalk(); 64 characteristics = new CheckedItemList<StringValue>( 65 new[] { "AutoCorrelation1", "CorrelationLength", "InformationContent", 66 "PartialInformationContent", "DensityBasinInformation", "InformationStability", 67 "Diversity", "Regularity", "TotalEntropy", "PeakInformationContent", 68 "PeakDensityBasinInformation" }.Select(x => new StringValue(x))); 48 69 } 49 70 … … 52 73 } 53 74 54 public IEnumerable<string> Characteristics { 55 get { 56 return new[] { "AutoCorrelation1", "CorrelationLength", "InformationContent", 57 "PartialInformationContent", "DensityBasinInformation", "InformationStability", 58 "Diversity", "Regularity", "TotalEntropy", "PeakInformationContent", 59 "PeakDensityBasinInformation" }; 60 } 75 private CheckedItemList<StringValue> characteristics; 76 public ReadOnlyCheckedItemList<StringValue> Characteristics { 77 get { return characteristics.AsReadOnly(); } 61 78 } 62 79 63 public bool CanCalculate( IProblem problem) {64 return problem is ISingleObjectiveHeuristicOptimizationProblem65 && problem.Operators.Any(x => x is IManipulator);80 public bool CanCalculate() { 81 return Problem is ISingleObjectiveHeuristicOptimizationProblem 82 && Problem.Operators.Any(x => x is IManipulator); 66 83 } 67 84 68 public IEnumerable<KeyValuePair<string, IItem>> Calculate(IProblem problem, IEnumerable<string> characteristics = null) { 69 var soProb = (ISingleObjectiveHeuristicOptimizationProblem)problem; 70 walker.Problem = soProb; 85 public IEnumerable<IResult> Calculate() { 71 86 walker.Prepare(true); 72 87 using (var waitHandle = new AutoResetEvent(false)) { … … 80 95 walker.ExecutionStateChanged -= evHandle; 81 96 } 82 var props = (characteristics ?? Characteristics).ToList(); 83 foreach (var p in props) { 84 yield return new KeyValuePair<string, IItem>(p, walker.Results[p].Value); 97 foreach (var p in characteristics.CheckedItems) { 98 yield return new Result("AdaptiveWalk." + walker.MutatorParameter.Value.Name + "." + p.Value.Value, walker.Results[p.Value.Value].Value); 85 99 } 86 100 walker.Prepare(true); 87 101 } 102 103 public void CollectParameterValues(IDictionary<string, IItem> values) { 104 walker.CollectParameterValues(values); 105 } 106 107 public IKeyedItemCollection<string, IParameter> Parameters { 108 get { return ((IParameterizedItem)walker).Parameters; } 109 } 88 110 } 89 111 } -
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/CharacteristicCalculator/RandomWalkCalculator.cs
r13583 r13594 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data; 24 25 using HeuristicLab.Optimization; 25 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 33 34 [StorableClass] 34 35 public class RandomWalkCalculator : NamedItem, ICharacteristicCalculator { 36 37 [Storable] 38 private IProblem problem; 39 public IProblem Problem { 40 get { return problem; } 41 set { 42 if (problem == value) return; 43 problem = value; 44 var soProblem = problem as ISingleObjectiveHeuristicOptimizationProblem; 45 walker.Problem = soProblem; 46 } 47 } 48 35 49 [Storable] 36 50 private RandomWalk walker; … … 40 54 private RandomWalkCalculator(RandomWalkCalculator original, Cloner cloner) 41 55 : base(original, cloner) { 56 problem = cloner.Clone(original.problem); 42 57 walker = cloner.Clone(original.walker); 58 characteristics = cloner.Clone(original.characteristics); 43 59 } 44 60 public RandomWalkCalculator() { … … 46 62 Description = ItemDescription; 47 63 walker = new RandomWalk(); 64 characteristics = new CheckedItemList<StringValue>( 65 new[] { "AutoCorrelation1", "CorrelationLength", "InformationContent", 66 "PartialInformationContent", "DensityBasinInformation", "InformationStability", 67 "Diversity", "Regularity", "TotalEntropy", "PeakInformationContent", 68 "PeakDensityBasinInformation" }.Select(x => new StringValue(x))); 48 69 } 49 70 … … 52 73 } 53 74 54 public IEnumerable<string> Characteristics { 55 get { 56 return new[] { "AutoCorrelation1", "CorrelationLength", "InformationContent", 57 "PartialInformationContent", "DensityBasinInformation", "InformationStability", 58 "Diversity", "Regularity", "TotalEntropy", "PeakInformationContent", 59 "PeakDensityBasinInformation" }; 60 } 75 private CheckedItemList<StringValue> characteristics; 76 public ReadOnlyCheckedItemList<StringValue> Characteristics { 77 get { return characteristics.AsReadOnly(); } 61 78 } 62 79 63 public bool CanCalculate( IProblem problem) {64 return problem is ISingleObjectiveHeuristicOptimizationProblem65 && problem.Operators.Any(x => x is IManipulator);80 public bool CanCalculate() { 81 return Problem is ISingleObjectiveHeuristicOptimizationProblem 82 && Problem.Operators.Any(x => x is IManipulator); 66 83 } 67 84 68 public IEnumerable<KeyValuePair<string, IItem>> Calculate(IProblem problem, IEnumerable<string> characteristics = null) { 69 var soProb = (ISingleObjectiveHeuristicOptimizationProblem)problem; 70 walker.Problem = soProb; 85 public IEnumerable<IResult> Calculate() { 71 86 walker.Prepare(true); 72 87 using (var waitHandle = new AutoResetEvent(false)) { … … 80 95 walker.ExecutionStateChanged -= evHandle; 81 96 } 82 var props = (characteristics ?? Characteristics).ToList(); 83 foreach (var p in props) { 84 yield return new KeyValuePair<string, IItem>(p, walker.Results[p].Value); 97 foreach (var p in characteristics.CheckedItems) { 98 yield return new Result("RandomWalk." + walker.MutatorParameter.Value.Name + "." + p.Value.Value, walker.Results[p.Value.Value].Value); 85 99 } 86 100 walker.Prepare(true); 87 101 } 102 103 public void CollectParameterValues(IDictionary<string, IItem> values) { 104 walker.CollectParameterValues(values); 105 } 106 107 public IKeyedItemCollection<string, IParameter> Parameters { 108 get { return ((IParameterizedItem)walker).Parameters; } 109 } 88 110 } 89 111 } -
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/CharacteristicCalculator/UpDownWalkCalculator.cs
r13583 r13594 22 22 using HeuristicLab.Common; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data; 24 25 using HeuristicLab.Optimization; 25 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 33 34 [StorableClass] 34 35 public class UpDownWalkCalculator : NamedItem, ICharacteristicCalculator { 36 37 [Storable] 38 private IProblem problem; 39 public IProblem Problem { 40 get { return problem; } 41 set { 42 if (problem == value) return; 43 problem = value; 44 var soProblem = problem as ISingleObjectiveHeuristicOptimizationProblem; 45 walker.Problem = soProblem; 46 } 47 } 48 35 49 [Storable] 36 50 private UpDownWalk walker; … … 40 54 private UpDownWalkCalculator(UpDownWalkCalculator original, Cloner cloner) 41 55 : base(original, cloner) { 56 problem = cloner.Clone(original.problem); 42 57 walker = cloner.Clone(original.walker); 58 characteristics = cloner.Clone(original.characteristics); 43 59 } 44 60 public UpDownWalkCalculator() { … … 46 62 Description = ItemDescription; 47 63 walker = new UpDownWalk(); 64 characteristics = new CheckedItemList<StringValue>( 65 new[] { "AutoCorrelation1", "CorrelationLength", "InformationContent", 66 "PartialInformationContent", "DensityBasinInformation", "InformationStability", 67 "Diversity", "Regularity", "TotalEntropy", "PeakInformationContent", 68 "PeakDensityBasinInformation", "DownWalkLength", "UpWalkLength", "UpWalkLenVar", 69 "DownWalkLenVar", "LowerVariance", "UpperVariance" }.Select(x => new StringValue(x))); 48 70 } 49 71 … … 52 74 } 53 75 54 public IEnumerable<string> Characteristics { 55 get { 56 return new[] { "AutoCorrelation1", "CorrelationLength", "InformationContent", 57 "PartialInformationContent", "DensityBasinInformation", "InformationStability", 58 "Diversity", "Regularity", "TotalEntropy", "PeakInformationContent", 59 "PeakDensityBasinInformation", "DownWalkLength", "UpWalkLength", "UpWalkLenVar", 60 "DownWalkLenVar", "LowerVariance", "UpperVariance" }; 61 } 76 private CheckedItemList<StringValue> characteristics; 77 public ReadOnlyCheckedItemList<StringValue> Characteristics { 78 get { return characteristics.AsReadOnly(); } 62 79 } 63 80 64 public bool CanCalculate( IProblem problem) {65 return problem is ISingleObjectiveHeuristicOptimizationProblem66 && problem.Operators.Any(x => x is IManipulator);81 public bool CanCalculate() { 82 return Problem is ISingleObjectiveHeuristicOptimizationProblem 83 && Problem.Operators.Any(x => x is IManipulator); 67 84 } 68 85 69 public IEnumerable<KeyValuePair<string, IItem>> Calculate(IProblem problem, IEnumerable<string> characteristics = null) { 70 var soProb = (ISingleObjectiveHeuristicOptimizationProblem)problem; 71 walker.Problem = soProb; 86 public IEnumerable<IResult> Calculate() { 72 87 walker.Prepare(true); 73 88 using (var waitHandle = new AutoResetEvent(false)) { … … 81 96 walker.ExecutionStateChanged -= evHandle; 82 97 } 83 var props = (characteristics ?? Characteristics).ToList(); 84 foreach (var p in props) { 85 yield return new KeyValuePair<string, IItem>(p, walker.Results[p].Value); 98 foreach (var p in characteristics.CheckedItems) { 99 yield return new Result("UpDownWalk." + walker.MutatorParameter.Value.Name + "." + p.Value.Value, walker.Results[p.Value.Value].Value); 86 100 } 87 101 walker.Prepare(true); 88 102 } 103 104 public void CollectParameterValues(IDictionary<string, IItem> values) { 105 walker.CollectParameterValues(values); 106 } 107 108 public IKeyedItemCollection<string, IParameter> Parameters { 109 get { return ((IParameterizedItem)walker).Parameters; } 110 } 89 111 } 90 112 } -
branches/PerformanceComparison/HeuristicLab.Optimization/3.3/Interfaces/ICharacteristicCalculator.cs
r13551 r13594 22 22 using System.Collections.Generic; 23 23 using HeuristicLab.Core; 24 using HeuristicLab.Data; 24 25 25 26 namespace HeuristicLab.Optimization { 26 public interface ICharacteristicCalculator : INamedItem { 27 IEnumerable<string> Characteristics { get; } 28 bool CanCalculate(IProblem problem); 29 IEnumerable<KeyValuePair<string, IItem>> Calculate(IProblem problem, IEnumerable<string> characteristics = null); 27 public interface ICharacteristicCalculator : IParameterizedNamedItem { 28 IProblem Problem { get; set; } 29 ReadOnlyCheckedItemList<StringValue> Characteristics { get; } 30 31 bool CanCalculate(); 32 IEnumerable<IResult> Calculate(); 30 33 } 31 34 } -
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.