Changeset 13594 for branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/CharacteristicCalculator/UpDownWalkCalculator.cs
- Timestamp:
- 02/07/16 23:14:22 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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.