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.OptimizationExpertSystem/3.3/ProblemCharacteristicAnalysis
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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.