Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/07/16 23:14:22 (9 years ago)
Author:
abeham
Message:

#2457: Adapted branch to trunk changes

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/CharacteristicCalculator/UpDownWalkCalculator.cs

    r13583 r13594  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Data;
    2425using HeuristicLab.Optimization;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3334  [StorableClass]
    3435  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
    3549    [Storable]
    3650    private UpDownWalk walker;
     
    4054    private UpDownWalkCalculator(UpDownWalkCalculator original, Cloner cloner)
    4155      : base(original, cloner) {
     56      problem = cloner.Clone(original.problem);
    4257      walker = cloner.Clone(original.walker);
     58      characteristics = cloner.Clone(original.characteristics);
    4359    }
    4460    public UpDownWalkCalculator() {
     
    4662      Description = ItemDescription;
    4763      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)));
    4870    }
    4971
     
    5274    }
    5375
    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(); }
    6279    }
    6380
    64     public bool CanCalculate(IProblem problem) {
    65       return problem is ISingleObjectiveHeuristicOptimizationProblem
    66         && problem.Operators.Any(x => x is IManipulator);
     81    public bool CanCalculate() {
     82      return Problem is ISingleObjectiveHeuristicOptimizationProblem
     83        && Problem.Operators.Any(x => x is IManipulator);
    6784    }
    6885
    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() {
    7287      walker.Prepare(true);
    7388      using (var waitHandle = new AutoResetEvent(false)) {
     
    8196        walker.ExecutionStateChanged -= evHandle;
    8297      }
    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);
    86100      }
    87101      walker.Prepare(true);
    88102    }
     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    }
    89111  }
    90112}
Note: See TracChangeset for help on using the changeset viewer.