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
Files:
6 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}
  • branches/PerformanceComparison/HeuristicLab.Optimization/3.3/Interfaces/ICharacteristicCalculator.cs

    r13551 r13594  
    2222using System.Collections.Generic;
    2323using HeuristicLab.Core;
     24using HeuristicLab.Data;
    2425
    2526namespace 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();
    3033  }
    3134}
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/ProblemCharacteristicAnalysis/CharacteristicCalculator.cs

    r13551 r13594  
    2020#endregion
    2121
    22 using System.Collections.Generic;
    2322using HeuristicLab.Common;
    2423using HeuristicLab.Core;
     24using HeuristicLab.Data;
    2525using HeuristicLab.Optimization;
    2626using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     27using System.Collections.Generic;
    2728
    2829namespace HeuristicLab.Problems.CharacteristicAnalysis {
    2930  [Item("Characteristic Calculator", "")]
    3031  [StorableClass]
    31   public abstract class CharacteristicCalculator : NamedItem, ICharacteristicCalculator {
     32  public abstract class CharacteristicCalculator : ParameterizedNamedItem, ICharacteristicCalculator {
    3233
    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(); } }
    3440
    3541    [StorableConstructor]
    3642    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    }
    3848    protected CharacteristicCalculator()
    3949      : base() {
    4050      name = ItemName;
    4151      description = ItemDescription;
     52      characteristics = new CheckedItemList<StringValue>();
    4253    }
    4354
    44     public abstract bool CanCalculate(IProblem problem);
     55    public abstract bool CanCalculate();
    4556
    46     public abstract IEnumerable<KeyValuePair<string, IItem>> Calculate(IProblem problem, IEnumerable<string> characteristics = null);
     57    public abstract IEnumerable<IResult> Calculate();
    4758  }
    4859}
  • branches/PerformanceComparison/HeuristicLab.OptimizationExpertSystem/3.3/ProblemCharacteristicAnalysis/QAP/QAPCharacteristicCalculator.cs

    r13551 r13594  
    2020#endregion
    2121
    22 using System;
    23 using System.Collections.Generic;
    2422using HeuristicLab.Common;
    2523using HeuristicLab.Core;
     24using HeuristicLab.Data;
    2625using HeuristicLab.Optimization;
    2726using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2827using HeuristicLab.Problems.QuadraticAssignment;
     28using System;
     29using System.Collections.Generic;
     30using System.Linq;
    2931
    3032namespace HeuristicLab.Problems.CharacteristicAnalysis.QAP {
     
    3335  public sealed class QAPCharacteristicCalculator : CharacteristicCalculator {
    3436
    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",
    3842        "FlowDominance", "DistanceDominance",
    3943        "FlowAsymmetry", "DistanceAsymmetry",
    4044        "FlowSparsity", "DistanceSparsity",
    4145        "FlowSkewness", "DistanceSkewness",
    42         "FlowDisparity", "DistanceDisparity" };
    43       }
     46        "FlowDisparity", "DistanceDisparity" }.Select(x => new StringValue(x)).ToList());
    4447    }
    45 
    46     [StorableConstructor]
    47     private QAPCharacteristicCalculator(bool deserializing) : base(deserializing) { }
    48     private QAPCharacteristicCalculator(QAPCharacteristicCalculator original, Cloner cloner) : base(original, cloner) { }
    49     public QAPCharacteristicCalculator() { }
    5048
    5149    public override IDeepCloneable Clone(Cloner cloner) {
     
    5351    }
    5452
    55     public override bool CanCalculate(IProblem problem) {
    56       return problem is QuadraticAssignmentProblem;
     53    public override bool CanCalculate() {
     54      return Problem is QuadraticAssignmentProblem;
    5755    }
    5856
    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      }
    8584    }
    8685  }
Note: See TracChangeset for help on using the changeset viewer.