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

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  
    2222using HeuristicLab.Common;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Data;
    2425using HeuristicLab.Optimization;
    2526using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3334  [StorableClass]
    3435  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
    3549    [Storable]
    3650    private AdaptiveWalk walker;
     
    4054    private AdaptiveWalkCalculator(AdaptiveWalkCalculator 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 AdaptiveWalkCalculator() {
     
    4662      Description = ItemDescription;
    4763      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)));
    4869    }
    4970
     
    5273    }
    5374
    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(); }
    6178    }
    6279
    63     public bool CanCalculate(IProblem problem) {
    64       return problem is ISingleObjectiveHeuristicOptimizationProblem
    65         && problem.Operators.Any(x => x is IManipulator);
     80    public bool CanCalculate() {
     81      return Problem is ISingleObjectiveHeuristicOptimizationProblem
     82        && Problem.Operators.Any(x => x is IManipulator);
    6683    }
    6784
    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() {
    7186      walker.Prepare(true);
    7287      using (var waitHandle = new AutoResetEvent(false)) {
     
    8095        walker.ExecutionStateChanged -= evHandle;
    8196      }
    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);
    8599      }
    86100      walker.Prepare(true);
    87101    }
     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    }
    88110  }
    89111}
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/CharacteristicCalculator/RandomWalkCalculator.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 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
    3549    [Storable]
    3650    private RandomWalk walker;
     
    4054    private RandomWalkCalculator(RandomWalkCalculator 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 RandomWalkCalculator() {
     
    4662      Description = ItemDescription;
    4763      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)));
    4869    }
    4970
     
    5273    }
    5374
    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(); }
    6178    }
    6279
    63     public bool CanCalculate(IProblem problem) {
    64       return problem is ISingleObjectiveHeuristicOptimizationProblem
    65         && problem.Operators.Any(x => x is IManipulator);
     80    public bool CanCalculate() {
     81      return Problem is ISingleObjectiveHeuristicOptimizationProblem
     82        && Problem.Operators.Any(x => x is IManipulator);
    6683    }
    6784
    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() {
    7186      walker.Prepare(true);
    7287      using (var waitHandle = new AutoResetEvent(false)) {
     
    8095        walker.ExecutionStateChanged -= evHandle;
    8196      }
    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);
    8599      }
    86100      walker.Prepare(true);
    87101    }
     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    }
    88110  }
    89111}
  • 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.