Changeset 8304 for branches/ScatterSearch (trunk integration)
- Timestamp:
- 07/19/12 13:19:12 (12 years ago)
- Location:
- branches/ScatterSearch (trunk integration)
- Files:
-
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/ReferenceSetUpdateMethod.cs
r8086 r8304 80 80 double similarity = 0; 81 81 foreach (var rScope in CurrentScope.SubScopes[1].SubScopes) { 82 similarity += SimilarityCalculator. ExecuteCalculation(pScope, rScope);82 similarity += SimilarityCalculator.CalculateIndividualSimilarity(pScope, rScope); 83 83 } 84 84 population[pScope] = similarity; -
branches/ScatterSearch (trunk integration)/HeuristicLab.Algorithms.ScatterSearch/3.3/SolutionPoolUpdateMethod.cs
r8086 r8304 130 130 if (orderedOffspring.Any(hasBetterQuality)) { 131 131 // produce the set union 132 var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), new SolutionEqualityComparer<IScope>(SimilarityCalculator. ExecuteCalculation));132 var union = orderedParents.Union(orderedOffspring.Where(hasBetterQuality), new SolutionEqualityComparer<IScope>(SimilarityCalculator.CalculateIndividualSimilarity)); 133 133 if (union.Count() > orderedParents.Count()) { 134 134 var orderedUnion = Maximization.Value ? union.OrderByDescending(x => x.Variables[QualityParameter.ActualName].Value) : -
branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization.Operators/3.3/SimilarityCalculator.cs
r8303 r8304 21 21 22 22 using System; 23 using System.Linq; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 50 51 protected SimilarityCalculator() : base() { } 51 52 52 public double ExecuteCalculation(IScope left, IScope right) {53 if (left == null || right== null)54 throw new ArgumentException("Cannot calculate diversity because one or both of the provided scopes isnull.");53 public double[][] CalculateCrowdSimilarity(IScope leftCrowd, IScope rightCrowd) { 54 if (leftCrowd == null || rightCrowd == null) 55 throw new ArgumentException("Cannot calculate similarity because one of the provided crowds or both are null."); 55 56 56 if (left == right) return 1.0; 57 else return CalculateSimilarity(left, right); 57 var leftIndividuals = leftCrowd.SubScopes; 58 var rightIndividuals = rightCrowd.SubScopes; 59 60 if (!leftIndividuals.Any() || !rightIndividuals.Any()) 61 throw new ArgumentException("Cannot calculate similarity because one of the provided crowds or both are empty."); 62 63 var similarityMatrix = new double[leftIndividuals.Count][]; 64 for (int i = 0; i < leftIndividuals.Count; i++) { 65 similarityMatrix[i] = new double[rightIndividuals.Count]; 66 for (int j = 0; j < rightIndividuals.Count; j++) { 67 similarityMatrix[i][j] = CalculateIndividualSimilarity(leftIndividuals[i], rightIndividuals[j]); 68 } 69 } 70 71 return similarityMatrix; 58 72 } 59 73 60 p rotected abstract double CalculateSimilarity(IScope left, IScope right);74 public abstract double CalculateIndividualSimilarity(IScope leftIndividual, IScope rightIndividual); 61 75 } 62 76 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Optimization/3.3/Interfaces/ISimilarityCalculator.cs
r8086 r8304 29 29 string Target { get; set; } 30 30 31 double ExecuteCalculation(IScope left, IScope right); 31 double CalculateIndividualSimilarity(IScope leftIndividual, IScope rightIndividual); 32 double[][] CalculateCrowdSimilarity(IScope leftCrowd, IScope rightCrowd); 32 33 } 33 34 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.Knapsack/3.3/SimilarityCalculators/KnapsackSimilarityCalculator.cs
r8303 r8304 42 42 public static double CalculateSimilarity(BinaryVector left, BinaryVector right) { 43 43 if (left == null || right == null) 44 throw new ArgumentException("Cannot calculate similarity because one of the provided solutions or both are null."); 44 throw new ArgumentException("Cannot calculate diversity because one or both of the provided scopes is null."); 45 if (left == right) return 1.0; 45 46 46 47 double similarity = 0.0; … … 50 51 } 51 52 52 p rotected override double CalculateSimilarity(IScope left, IScope right) {53 BinaryVector sol1 = left.Variables[Target].Value as BinaryVector;54 BinaryVector sol2 = right.Variables[Target].Value as BinaryVector;53 public override double CalculateIndividualSimilarity(IScope left, IScope right) { 54 var sol1 = left.Variables[Target].Value as BinaryVector; 55 var sol2 = right.Variables[Target].Value as BinaryVector; 55 56 56 57 return CalculateSimilarity(sol1, sol2); -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TestFunctions/3.3/SimilarityCalculators/SingleObjectiveTestFunctionSimilarityCalculator.cs
r8303 r8304 57 57 if (bounds == null) 58 58 throw new ArgumentException("Cannot calculate similarity because no bounds were provided."); 59 if (left == right) return 1.0; 59 60 60 61 double maxSum = 0.0; … … 71 72 } 72 73 73 p rotected override double CalculateSimilarity(IScope left, IScope right) {74 RealVector sol1 = left.Variables[Target].Value as RealVector;75 RealVector sol2 = right.Variables[Target].Value as RealVector;74 public override double CalculateIndividualSimilarity(IScope left, IScope right) { 75 var sol1 = left.Variables[Target].Value as RealVector; 76 var sol2 = right.Variables[Target].Value as RealVector; 76 77 77 78 return CalculateSimilarity(sol1, sol2, Bounds); -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/SimilarityCalculators/TSPSimilarityCalculator.cs
r8303 r8304 43 43 if (left == null || right == null) 44 44 throw new ArgumentException("Cannot calculate similarity because one of the provided solutions or both are null."); 45 if (left == right) return 1.0; 45 46 46 47 int[,] edges = new int[right.Length, 2]; … … 60 61 } 61 62 62 p rotected override double CalculateSimilarity(IScope left, IScope right) {63 Permutationsol1 = left.Variables[Target].Value as Permutation;64 Permutationsol2 = right.Variables[Target].Value as Permutation;63 public override double CalculateIndividualSimilarity(IScope left, IScope right) { 64 var sol1 = left.Variables[Target].Value as Permutation; 65 var sol2 = right.Variables[Target].Value as Permutation; 65 66 66 67 return CalculateSimilarity(sol1, sol2); -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.VehicleRouting/3.3/SimilarityCalculators/VRPSimilarityCalculator.cs
r8303 r8304 46 46 if (left == null || right == null) 47 47 throw new ArgumentException("Cannot calculate similarity because one of the provided solutions or both are null."); 48 if (left == right) return 1.0; 48 49 49 50 // extract edges from first solution … … 77 78 } 78 79 79 p rotected override double CalculateSimilarity(IScope left, IScope right) {80 PotvinEncodingsol1 = left.Variables[Target].Value as PotvinEncoding;81 PotvinEncodingsol2 = right.Variables[Target].Value as PotvinEncoding;80 public override double CalculateIndividualSimilarity(IScope left, IScope right) { 81 var sol1 = left.Variables[Target].Value as PotvinEncoding; 82 var sol2 = right.Variables[Target].Value as PotvinEncoding; 82 83 83 84 return CalculateSimilarity(sol1, sol2);
Note: See TracChangeset
for help on using the changeset viewer.