- Timestamp:
- 07/24/12 15:04:37 (12 years ago)
- Location:
- branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization.Operators/3.3
- Files:
-
- 2 added
- 1 deleted
- 1 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization.Operators/3.3/HeuristicLab.Optimization.Operators-3.3.csproj
r8086 r8319 109 109 </ItemGroup> 110 110 <ItemGroup> 111 <Compile Include="SingleObjectiveSolutionSimilarityCalculator.cs" /> 111 112 <Compile Include="GeneralizedExponentialDiscreteDoubleValueModifier.cs" /> 112 113 <Compile Include="MultiObjective\CrowdedComparisonSorter.cs" /> … … 115 116 <Compile Include="MultiObjective\FastNonDominatedSort.cs" /> 116 117 <Compile Include="MultiObjective\RankAndCrowdingSorter.cs" /> 117 <Compile Include=" PathRelinker.cs" />118 <Compile Include="SingleObjectivePathRelinker.cs" /> 118 119 <Compile Include="Plugin.cs" /> 119 120 <Compile Include="ShakingOperator.cs" /> 120 <Compile Include="S imilarityCalculator.cs" />121 <Compile Include="SolutionSimilarityCalculator.cs" /> 121 122 <Compile Include="UserDefinedCrossover.cs" /> 122 123 <Compile Include="UserDefinedEvaluator.cs" /> -
branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization.Operators/3.3/SolutionSimilarityCalculator.cs
r8316 r8319 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using HeuristicLab.Common; … … 32 33 [Item("SimilarityCalculator", "A base class for items that perform similarity calculation between two solutions.")] 33 34 [StorableClass] 34 public abstract class SimilarityCalculator : Item, ISimilarityCalculator { 35 #region Properties 36 [Storable] 37 private string target; 38 public string Target { 39 get { return target; } 40 set { target = value; } 41 } 42 #endregion 35 public abstract class SolutionSimilarityCalculator : Item, ISolutionSimilarityCalculator, IEqualityComparer<IScope> { 36 [StorableConstructor] 37 protected SolutionSimilarityCalculator(bool deserializing) : base(deserializing) { } 38 protected SolutionSimilarityCalculator(SolutionSimilarityCalculator original, Cloner cloner) : base(original, cloner) { } 39 protected SolutionSimilarityCalculator() : base() { } 43 40 44 [StorableConstructor] 45 protected SimilarityCalculator(bool deserializing) : base(deserializing) { } 46 protected SimilarityCalculator(SimilarityCalculator original, Cloner cloner) 47 : base(original, cloner) { 48 if (original.Target != null) 49 this.target = (string)original.Target.Clone(); 50 } 51 protected SimilarityCalculator() : base() { } 52 53 public double[][] CalculateCrowdSimilarity(IScope leftCrowd, IScope rightCrowd) { 54 if (leftCrowd == null || rightCrowd == null) 41 public double[][] CalculateSolutionCrowdSimilarity(IScope leftSolutionCrowd, IScope rightSolutionCrowd) { 42 if (leftSolutionCrowd == null || rightSolutionCrowd == null) 55 43 throw new ArgumentException("Cannot calculate similarity because one of the provided crowds or both are null."); 56 44 57 var leftIndividuals = left Crowd.SubScopes;58 var rightIndividuals = right Crowd.SubScopes;45 var leftIndividuals = leftSolutionCrowd.SubScopes; 46 var rightIndividuals = rightSolutionCrowd.SubScopes; 59 47 60 48 if (!leftIndividuals.Any() || !rightIndividuals.Any()) … … 65 53 similarityMatrix[i] = new double[rightIndividuals.Count]; 66 54 for (int j = 0; j < rightIndividuals.Count; j++) { 67 similarityMatrix[i][j] = Calculate IndividualSimilarity(leftIndividuals[i], rightIndividuals[j]);55 similarityMatrix[i][j] = CalculateSolutionSimilarity(leftIndividuals[i], rightIndividuals[j]); 68 56 } 69 57 } … … 72 60 } 73 61 74 public abstract double CalculateIndividualSimilarity(IScope leftIndividual, IScope rightIndividual); 62 public double[][] CalculateSolutionCrowdSimilarity(IScope solutionCrowd) { 63 if (solutionCrowd == null) 64 throw new ArgumentException("Cannot calculate similarity because the provided crowd is null."); 65 66 var individuals = solutionCrowd.SubScopes; 67 68 if (!individuals.Any()) 69 throw new ArgumentException("Cannot calculate similarity because the provided crowd is empty."); 70 71 var similarityMatrix = new double[individuals.Count][]; 72 for (int i = 0; i < individuals.Count; i++) { 73 similarityMatrix[i] = new double[individuals.Count]; 74 for (int j = i; j < individuals.Count; j++) { 75 similarityMatrix[i][j] = similarityMatrix[j][i] = CalculateSolutionSimilarity(individuals[i], individuals[j]); 76 } 77 } 78 79 return similarityMatrix; 80 } 81 82 public bool Equals(IScope x, IScope y) { 83 if (object.ReferenceEquals(x, y)) return true; 84 if (x == null || y == null) return false; 85 return CalculateSolutionSimilarity(x, y) == 1.0; 86 } 87 88 public abstract double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution); 89 public abstract int GetHashCode(IScope obj); 75 90 } 76 91 }
Note: See TracChangeset
for help on using the changeset viewer.