Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
07/12/17 21:02:01 (7 years ago)
Author:
abeham
Message:

#2666, #2706, #2730, #2736: merged revisions 14412, 14475, 14476, 14659, 14660, 14663, 14779, 14780, 14912, 15050, 15067, 15069, 15079, 15162, 15166, 15172, 15173 to stable

Location:
stable
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.QuadraticAssignment

  • stable/HeuristicLab.Problems.QuadraticAssignment/3.3/QAPSimilarityCalculator.cs

    r14186 r15217  
    2323using HeuristicLab.Common;
    2424using HeuristicLab.Core;
     25using HeuristicLab.Data;
    2526using HeuristicLab.Encodings.PermutationEncoding;
    2627using HeuristicLab.Optimization.Operators;
     28using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    2729
    2830namespace HeuristicLab.Problems.QuadraticAssignment {
     
    3436  /// </remarks>
    3537  [Item("QAPSimilarityCalculator", "An operator that performs similarity calculation between two quadratic assignment solutions. The operator calculates the similarity based on the number of edges the two solutions have in common.")]
     38  [StorableClass]
    3639  public sealed class QAPSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
    3740    protected override bool IsCommutative { get { return true; } }
    3841
     42    [Storable]
     43    public DoubleMatrix Weights { get; set; }
     44    [Storable]
     45    public DoubleMatrix Distances { get; set; }
     46
    3947    private QAPSimilarityCalculator(bool deserializing) : base(deserializing) { }
    40     private QAPSimilarityCalculator(QAPSimilarityCalculator original, Cloner cloner) : base(original, cloner) { }
     48    private QAPSimilarityCalculator(QAPSimilarityCalculator original, Cloner cloner)
     49      : base(original, cloner) {
     50      Weights = cloner.Clone(original.Weights);
     51      Distances = cloner.Clone(original.Distances);
     52    }
    4153    public QAPSimilarityCalculator() : base() { }
    4254
     
    4557    }
    4658
    47     public static double CalculateSimilarity(Permutation left, Permutation right) {
     59    public static double CalculateSimilarity(Permutation left, Permutation right, DoubleMatrix weights, DoubleMatrix distances) {
    4860      if (left == null || right == null)
    4961        throw new ArgumentException("Cannot calculate similarity because one of the provided solutions or both are null.");
    5062      if (left.Length != right.Length)
    5163        throw new ArgumentException("Cannot calculate similarity because the provided solutions have different lengths.");
    52       if (object.ReferenceEquals(left, right)) return 1.0;
     64      if (left.Length == 0)
     65        throw new ArgumentException("Cannot calculate similarity because solutions are of length 0.");
     66      if (ReferenceEquals(left, right)) return 1.0;
    5367
    54       return QAPPermutationProximityCalculator.CalculateGenotypeSimilarity(left, right);
     68      return QAPPermutationProximityCalculator.CalculatePhenotypeSimilarity(left, right, weights, distances);
    5569    }
    5670
     
    5973      var sol2 = rightSolution.Variables[SolutionVariableName].Value as Permutation;
    6074
    61       return CalculateSimilarity(sol1, sol2);
     75      return CalculateSimilarity(sol1, sol2, Weights, Distances);
    6276    }
    6377  }
Note: See TracChangeset for help on using the changeset viewer.