Ignore:
Timestamp:
02/25/15 10:59:20 (6 years ago)
Author:
jkarder
Message:

#2332: added SolutionSimilarityCalculator.IsCommutative

Location:
trunk/sources/HeuristicLab.Optimization.Operators/3.3
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/NoSimilarityCalculator.cs

    r12012 r12070  
    3232  [Item("NoSimilarityCalculator", "An item that performs similarity calculation between two solutions. The item always considers two solutions to be distinct.")]
    3333  public sealed class NoSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
     34    protected override bool IsCommutative { get { return true; } }
     35
    3436    private NoSimilarityCalculator(bool deserializing) : base(deserializing) { }
    3537    private NoSimilarityCalculator(NoSimilarityCalculator original, Cloner cloner) : base(original, cloner) { }
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/QualitySimilarityCalculator.cs

    r12012 r12070  
    3434  [Item("QualitySimilarityCalculator", "An item that performs similarity calculation between two solutions. The item only considers the qualities of the two solutions.")]
    3535  public sealed class QualitySimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator {
     36    protected override bool IsCommutative { get { return true; } }
     37
    3638    private QualitySimilarityCalculator(bool deserializing) : base(deserializing) { }
    3739    private QualitySimilarityCalculator(QualitySimilarityCalculator original, Cloner cloner) : base(original, cloner) { }
  • trunk/sources/HeuristicLab.Optimization.Operators/3.3/SolutionSimilarityCalculator.cs

    r12012 r12070  
    3333  [StorableClass]
    3434  public abstract class SolutionSimilarityCalculator : Item, ISolutionSimilarityCalculator {
     35    protected abstract bool IsCommutative { get; }
     36
    3537    [StorableConstructor]
    3638    protected SolutionSimilarityCalculator(bool deserializing) : base(deserializing) { }
     
    7173      for (int i = 0; i < individuals.Count; i++) similarityMatrix[i] = new double[individuals.Count];
    7274
    73       for (int i = 0; i < individuals.Count; i++) {
    74         for (int j = i; j < individuals.Count; j++) {
    75           similarityMatrix[i][j] = similarityMatrix[j][i] = CalculateSolutionSimilarity(individuals[i], individuals[j]);
     75      if (IsCommutative) {
     76        for (int i = 0; i < individuals.Count; i++) {
     77          for (int j = i; j < individuals.Count; j++) {
     78            similarityMatrix[i][j] = similarityMatrix[j][i] = CalculateSolutionSimilarity(individuals[i], individuals[j]);
     79          }
     80        }
     81      } else {
     82        for (int i = 0; i < individuals.Count; i++) {
     83          for (int j = i; j < individuals.Count; j++) {
     84            similarityMatrix[i][j] = CalculateSolutionSimilarity(individuals[i], individuals[j]);
     85            if (i == j) continue;
     86            similarityMatrix[j][i] = CalculateSolutionSimilarity(individuals[j], individuals[i]);
     87          }
    7688        }
    7789      }
Note: See TracChangeset for help on using the changeset viewer.