Changeset 8086 for branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman
- Timestamp:
- 06/22/12 11:11:38 (12 years ago)
- Location:
- branches/ScatterSearch (trunk integration)
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch (trunk integration)
- Property svn:ignore
-
old new 20 20 bin 21 21 protoc.exe 22 _ReSharper.HeuristicLab 3.3 Tests
-
- Property svn:mergeinfo changed
- Property svn:ignore
-
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/Improvers/TSPImprovementOperator.cs
r7789 r8086 27 27 using HeuristicLab.Operators; 28 28 using HeuristicLab.Optimization; 29 using HeuristicLab.Optimization.Operators;30 29 using HeuristicLab.Parameters; 31 30 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 44 43 public ILookupParameter<DistanceMatrix> DistanceMatrixParameter { 45 44 get { return (ILookupParameter<DistanceMatrix>)Parameters["DistanceMatrix"]; } 46 }47 public ILookupParameter<IEvaluator> EvaluatorParameter {48 get { return (ILookupParameter<IEvaluator>)Parameters["Evaluator"]; }49 45 } 50 46 public IValueParameter<IntValue> ImprovementAttemptsParameter { … … 67 63 set { DistanceMatrixParameter.ActualValue = value; } 68 64 } 69 public IEvaluator Evaluator {70 get { return EvaluatorParameter.ActualValue; }71 set { EvaluatorParameter.ActualValue = value; }72 }73 65 public IntValue ImprovementAttempts { 74 66 get { return ImprovementAttemptsParameter.Value; } … … 78 70 get { return RandomParameter.ActualValue; } 79 71 set { RandomParameter.ActualValue = value; } 80 }81 private IItem Target {82 get { return TargetParameter.ActualValue; }83 72 } 84 73 #endregion … … 90 79 : base() { 91 80 #region Create parameters 92 Parameters.Add(new ScopeParameter("CurrentScope")); 93 Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix")); 94 Parameters.Add(new LookupParameter<IEvaluator>("Evaluator")); 95 Parameters.Add(new ValueParameter<IntValue>("ImprovementAttempts", new IntValue(100))); 96 Parameters.Add(new LookupParameter<IRandom>("Random")); 97 Parameters.Add(new ValueLookupParameter<IItem>("Target")); 81 Parameters.Add(new ScopeParameter("CurrentScope", "The current scope that contains the solution to be improved.")); 82 Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities.")); 83 Parameters.Add(new ValueParameter<IntValue>("ImprovementAttempts", "The number of improvement attempts the operator should perform.", new IntValue(100))); 84 Parameters.Add(new LookupParameter<IRandom>("Random", "A pseudo random number generator.")); 85 Parameters.Add(new ValueLookupParameter<IItem>("Target", "This parameter is used for name translation only.")); 98 86 #endregion 99 87 } … … 105 93 public override IOperation Apply() { 106 94 Permutation currSol = CurrentScope.Variables[TargetParameter.ActualName].Value as Permutation; 95 if (currSol == null) 96 throw new ArgumentException("Cannot improve solution because it has the wrong type."); 107 97 if (currSol.PermutationType != PermutationTypes.RelativeUndirected) 108 98 throw new ArgumentException("Cannot improve solution because the permutation type is not supported."); … … 118 108 Invert(currSol, a, b); 119 109 } 110 111 CurrentScope.Variables.Add(new Variable("LocalEvaluatedSolutions", ImprovementAttempts)); 120 112 121 113 return base.Apply(); -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/PathRelinkers/TSPMultipleGuidesPathRelinker.cs
r7789 r8086 47 47 public DistanceMatrix DistanceMatrix { 48 48 get { return DistanceMatrixParameter.ActualValue; } 49 set { DistanceMatrixParameter.ActualValue = value; }50 49 } 51 50 #endregion … … 57 56 : base() { 58 57 #region Create parameters 59 Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix" ));58 Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities.")); 60 59 #endregion 61 60 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/Plugin.cs.frame
r7558 r8086 37 37 [PluginDependency("HeuristicLab.Operators", "3.3")] 38 38 [PluginDependency("HeuristicLab.Optimization", "3.3")] 39 [PluginDependency("HeuristicLab.Optimization.Operators", "3.3")] 39 40 [PluginDependency("HeuristicLab.Parameters", "3.3")] 40 41 [PluginDependency("HeuristicLab.Persistence", "3.3")] -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/SimilarityCalculators/TSPSimilarityCalculator.cs
r7793 r8086 20 20 #endregion 21 21 22 using System; 22 23 using HeuristicLab.Common; 23 24 using HeuristicLab.Core; 24 25 using HeuristicLab.Encodings.PermutationEncoding; 25 26 using HeuristicLab.Optimization.Operators; 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;27 27 28 28 namespace HeuristicLab.Problems.TravelingSalesman { … … 31 31 /// </summary> 32 32 [Item("TSPSimilarityCalculator", "An operator that performs similarity calculation between two traveling salesman solutions.")] 33 [StorableClass]34 33 public sealed class TSPSimilarityCalculator : SimilarityCalculator { 35 [StorableConstructor]36 34 private TSPSimilarityCalculator(bool deserializing) : base(deserializing) { } 37 35 private TSPSimilarityCalculator(TSPSimilarityCalculator original, Cloner cloner) : base(original, cloner) { } 38 36 public TSPSimilarityCalculator() : base() { } 39 37 40 public override IDeepCloneable Clone(Cloner cloner) { 41 return new TSPSimilarityCalculator(this, cloner); 38 public static double CalculateSimilarity(Permutation left, Permutation right) { 39 if (left == null || right == null) 40 throw new ArgumentException("Cannot calculate similarity because one of the provided solutions or both are null."); 41 42 int[,] edges = new int[right.Length, 2]; 43 for (int i = 0; i < right.Length; i++) { 44 edges[right[i], 0] = right[(i + 1) % right.Length]; 45 edges[right[i], 1] = right[(i - 1 + right.Length) % right.Length]; 46 } 47 48 double similarity = 0.0; 49 for (int i = 0; i < left.Length; i++) { 50 int targetCity = left[(i + 1) % left.Length]; 51 if (targetCity == edges[left[i], 0] || targetCity == edges[left[i], 1]) 52 similarity++; 53 } 54 55 return similarity / left.Length; 42 56 } 43 57 44 58 protected override double CalculateSimilarity(IScope left, IScope right) { 45 Permutation v1 = left.Variables[TargetParameter.ActualName].Value as Permutation;46 Permutation v2 = right.Variables[TargetParameter.ActualName].Value as Permutation;59 Permutation sol1 = left.Variables[Target].Value as Permutation; 60 Permutation sol2 = right.Variables[Target].Value as Permutation; 47 61 48 int[,] edges = new int[v2.Length, 2]; 49 for (int i = 0; i < v2.Length; i++) { 50 edges[v2[i], 0] = v2[(i + 1) % v2.Length]; 51 edges[v2[i], 1] = v2[(i - 1 + v2.Length) % v2.Length]; 52 } 53 54 double similarity = 0.0; 55 for (int i = 0; i < v1.Length; i++) { 56 int targetCity = v1[(i + 1) % v1.Length]; 57 if (targetCity == edges[v1[i], 0] || targetCity == edges[v1[i], 1]) 58 similarity++; 59 } 60 61 return similarity / v1.Length; 62 return CalculateSimilarity(sol1, sol2); 62 63 } 63 64 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs
r7789 r8086 29 29 using HeuristicLab.Encodings.PermutationEncoding; 30 30 using HeuristicLab.Optimization; 31 using HeuristicLab.Optimization.Operators;32 31 using HeuristicLab.Parameters; 33 32 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; … … 352 351 } 353 352 foreach (ISimilarityCalculator op in Operators.OfType<ISimilarityCalculator>()) { 354 op.TargetParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 355 op.TargetParameter.Hidden = true; 353 op.Target = SolutionCreator.PermutationParameter.ActualName; 356 354 } 357 355 } … … 366 364 if (data.Coordinates == null && data.Distances == null) 367 365 throw new System.IO.InvalidDataException("The given instance specifies neither coordinates nor distances!"); 368 if (data.Dimension > DistanceMatrixSizeLimit && (data.DistanceMeasure == TSPDistanceMeasure.Att369 || data.DistanceMeasure == TSPDistanceMeasure.Manhattan370 || data.DistanceMeasure == TSPDistanceMeasure.Maximum371 || data.DistanceMeasure == TSPDistanceMeasure.UpperEuclidean))366 if (data.Dimension > DistanceMatrixSizeLimit && (data.DistanceMeasure == DistanceMeasure.Att 367 || data.DistanceMeasure == DistanceMeasure.Manhattan 368 || data.DistanceMeasure == DistanceMeasure.Maximum 369 || data.DistanceMeasure == DistanceMeasure.UpperEuclidean)) 372 370 throw new System.IO.InvalidDataException("The given instance uses an unsupported distance measure and is too large for using a distance matrix."); 373 371 if (data.Coordinates != null && data.Coordinates.GetLength(1) != 2) … … 382 380 383 381 TSPEvaluator evaluator; 384 if (data.DistanceMeasure == TSPDistanceMeasure.Att385 || data.DistanceMeasure == TSPDistanceMeasure.Manhattan386 || data.DistanceMeasure == TSPDistanceMeasure.Maximum387 || data.DistanceMeasure == TSPDistanceMeasure.UpperEuclidean) {382 if (data.DistanceMeasure == DistanceMeasure.Att 383 || data.DistanceMeasure == DistanceMeasure.Manhattan 384 || data.DistanceMeasure == DistanceMeasure.Maximum 385 || data.DistanceMeasure == DistanceMeasure.UpperEuclidean) { 388 386 evaluator = new TSPDistanceMatrixEvaluator(); 389 387 UseDistanceMatrix = new BoolValue(true); 390 388 DistanceMatrix = new DistanceMatrix(data.GetDistanceMatrix()); 391 } else if (data.DistanceMeasure == TSPDistanceMeasure.Direct && data.Distances != null) {389 } else if (data.DistanceMeasure == DistanceMeasure.Direct && data.Distances != null) { 392 390 evaluator = new TSPDistanceMatrixEvaluator(); 393 391 UseDistanceMatrix = new BoolValue(true); … … 397 395 UseDistanceMatrix = new BoolValue(data.Dimension <= DistanceMatrixSizeLimit); 398 396 switch (data.DistanceMeasure) { 399 case TSPDistanceMeasure.Euclidean:397 case DistanceMeasure.Euclidean: 400 398 evaluator = new TSPEuclideanPathEvaluator(); 401 399 break; 402 case TSPDistanceMeasure.RoundedEuclidean:400 case DistanceMeasure.RoundedEuclidean: 403 401 evaluator = new TSPRoundedEuclideanPathEvaluator(); 404 402 break; 405 case TSPDistanceMeasure.Geo:403 case DistanceMeasure.Geo: 406 404 evaluator = new TSPGeoPathEvaluator(); 407 405 break;
Note: See TracChangeset
for help on using the changeset viewer.