- Timestamp:
- 02/07/16 23:14:22 (9 years ago)
- Location:
- branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/CharacteristicCalculator
- Files:
-
- 3 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 }
Note: See TracChangeset
for help on using the changeset viewer.