Changeset 8319 for branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman
- Timestamp:
- 07/24/12 15:04:37 (12 years ago)
- Location:
- branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/Improvers/TSPImprovementOperator.cs
r8086 r8319 34 34 /// An operator that improves traveling salesman solutions. 35 35 /// </summary> 36 /// <remarks> 37 /// The operator tries to improve the traveling salesman solution by swapping two randomly chosen edges for a certain number of times. 38 /// </remarks> 36 39 [Item("TSPImprovementOperator", "An operator that improves traveling salesman solutions.")] 37 40 [StorableClass] 38 public sealed class TSPImprovementOperator : SingleSuccessorOperator, I ImprovementOperator {41 public sealed class TSPImprovementOperator : SingleSuccessorOperator, ISingleObjectiveImprovementOperator { 39 42 #region Parameter properties 40 43 public ScopeParameter CurrentScopeParameter { … … 50 53 get { return (ILookupParameter<IRandom>)Parameters["Random"]; } 51 54 } 52 public IValueLookupParameter<IItem> TargetParameter {53 get { return (IValueLookupParameter<IItem>)Parameters[" Target"]; }55 public IValueLookupParameter<IItem> SolutionParameter { 56 get { return (IValueLookupParameter<IItem>)Parameters["Solution"]; } 54 57 } 55 58 #endregion … … 83 86 Parameters.Add(new ValueParameter<IntValue>("ImprovementAttempts", "The number of improvement attempts the operator should perform.", new IntValue(100))); 84 87 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."));88 Parameters.Add(new ValueLookupParameter<IItem>("Solution", "The solution to be improved. This parameter is used for name translation only.")); 86 89 #endregion 87 90 } … … 92 95 93 96 public override IOperation Apply() { 94 Permutation currSol = CurrentScope.Variables[ TargetParameter.ActualName].Value as Permutation;97 Permutation currSol = CurrentScope.Variables[SolutionParameter.ActualName].Value as Permutation; 95 98 if (currSol == null) 96 99 throw new ArgumentException("Cannot improve solution because it has the wrong type."); -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/PathRelinkers/TSPMultipleGuidesPathRelinker.cs
r8086 r8319 35 35 /// An operator that relinks paths between traveling salesman solutions using a multiple guiding strategy. 36 36 /// </summary> 37 /// <remarks> 38 /// The operator incrementally changes the initiating solution towards the guiding solution by correcting edges as needed. For each city it choses the best edge from all guiding solutions. 39 /// </remarks> 37 40 [Item("TSPMultipleGuidesPathRelinker", "An operator that relinks paths between traveling salesman solutions using a multiple guiding strategy.")] 38 41 [StorableClass] 39 public sealed class TSPMultipleGuidesPathRelinker : PathRelinker {42 public sealed class TSPMultipleGuidesPathRelinker : SingleObjectivePathRelinker { 40 43 #region Parameter properties 41 44 public ILookupParameter<DistanceMatrix> DistanceMatrixParameter { … … 93 96 } 94 97 }); 95 Invert(v1, i, bestCityIndex);98 Invert(v1, currCityIndex + 1, bestCityIndex); 96 99 solutions.Add(v1.Clone() as Permutation); 97 100 } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/PathRelinkers/TSPPathRelinker.cs
r7789 r8319 34 34 /// An operator that relinks paths between traveling salesman solutions. 35 35 /// </summary> 36 /// <remarks> 37 /// The operator incrementally assimilates the initiating solution into the guiding solution by correcting edges as needed. 38 /// </remarks> 36 39 [Item("TSPPathRelinker", "An operator that relinks paths between traveling salesman solutions.")] 37 40 [StorableClass] 38 public sealed class TSPPathRelinker : PathRelinker {41 public sealed class TSPPathRelinker : SingleObjectivePathRelinker { 39 42 [StorableConstructor] 40 43 private TSPPathRelinker(bool deserializing) : base(deserializing) { } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/PathRelinkers/TSPSimultaneousPathRelinker.cs
r7789 r8319 34 34 /// An operator that relinks paths between traveling salesman solutions starting from both ends. 35 35 /// </summary> 36 /// <remarks> 37 /// The operator incrementally assimilates the initiating solution into the guiding solution and vice versa by correcting edges as needed. 38 /// </remarks> 36 39 [Item("TSPSimultaneousPathRelinker", "An operator that relinks paths between traveling salesman solutions starting from both ends.")] 37 40 [StorableClass] 38 public sealed class TSPSimultaneousPathRelinker : PathRelinker {41 public sealed class TSPSimultaneousPathRelinker : SingleObjectivePathRelinker { 39 42 [StorableConstructor] 40 43 private TSPSimultaneousPathRelinker(bool deserializing) : base(deserializing) { } -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/SimilarityCalculators/TSPSimilarityCalculator.cs
r8304 r8319 30 30 /// An operator that performs similarity calculation between two traveling salesman solutions. 31 31 /// </summary> 32 /// <remarks> 33 /// The operator calculates the similarity based on the number of edges the two solutions have in common. 34 /// </remarks> 32 35 [Item("TSPSimilarityCalculator", "An operator that performs similarity calculation between two traveling salesman solutions.")] 33 public sealed class TSPSimilarityCalculator : Si milarityCalculator {36 public sealed class TSPSimilarityCalculator : SingleObjectiveSolutionSimilarityCalculator { 34 37 private TSPSimilarityCalculator(bool deserializing) : base(deserializing) { } 35 38 private TSPSimilarityCalculator(TSPSimilarityCalculator original, Cloner cloner) : base(original, cloner) { } … … 43 46 if (left == null || right == null) 44 47 throw new ArgumentException("Cannot calculate similarity because one of the provided solutions or both are null."); 45 if (left == right) return 1.0; 48 if (left.PermutationType != right.PermutationType) 49 throw new ArgumentException("Cannot calculate similarity because the provided solutions have different types."); 50 if (left.Length != right.Length) 51 throw new ArgumentException("Cannot calculate similarity because the provided solutions have different lengths."); 52 var comparer = new PermutationEqualityComparer(); 53 if (object.ReferenceEquals(left, right) || comparer.Equals(left, right)) return 1.0; 46 54 55 switch (left.PermutationType) { 56 case PermutationTypes.Absolute: 57 return CalculateAbsolute(left, right); 58 case PermutationTypes.RelativeDirected: 59 return CalculateRelativeDirected(left, right); 60 case PermutationTypes.RelativeUndirected: 61 return CalculateRelativeUndirected(left, right); 62 default: 63 throw new InvalidOperationException("unknown permutation type"); 64 } 65 } 66 67 private static double CalculateAbsolute(Permutation left, Permutation right) { 68 double similarity = 0.0; 69 for (int i = 0; i < left.Length && left[i] == right[i]; similarity = ++i) ; 70 return similarity / left.Length; 71 } 72 73 private static double CalculateRelativeDirected(Permutation left, Permutation right) { 74 throw new NotImplementedException(); 75 } 76 77 private static double CalculateRelativeUndirected(Permutation left, Permutation right) { 47 78 int[,] edges = new int[right.Length, 2]; 48 79 for (int i = 0; i < right.Length; i++) { … … 61 92 } 62 93 63 public override double Calculate IndividualSimilarity(IScope left, IScope right) {64 var sol1 = left .Variables[Target].Value as Permutation;65 var sol2 = right .Variables[Target].Value as Permutation;94 public override double CalculateSolutionSimilarity(IScope leftSolution, IScope rightSolution) { 95 var sol1 = leftSolution.Variables[SolutionVariableName].Value as Permutation; 96 var sol2 = rightSolution.Variables[SolutionVariableName].Value as Permutation; 66 97 67 98 return CalculateSimilarity(sol1, sol2); -
branches/ScatterSearch (trunk integration)/HeuristicLab.Problems.TravelingSalesman/3.3/TravelingSalesmanProblem.cs
r8086 r8319 342 342 op.PermutationParameter.Hidden = true; 343 343 } 344 foreach (I ImprovementOperator op in Operators.OfType<IImprovementOperator>()) {345 op. TargetParameter.ActualName = SolutionCreator.PermutationParameter.ActualName;346 op. TargetParameter.Hidden = true;347 } 348 foreach (I PathRelinker op in Operators.OfType<IPathRelinker>()) {344 foreach (ISingleObjectiveImprovementOperator op in Operators.OfType<ISingleObjectiveImprovementOperator>()) { 345 op.SolutionParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 346 op.SolutionParameter.Hidden = true; 347 } 348 foreach (ISingleObjectivePathRelinker op in Operators.OfType<ISingleObjectivePathRelinker>()) { 349 349 op.ParentsParameter.ActualName = SolutionCreator.PermutationParameter.ActualName; 350 350 op.ParentsParameter.Hidden = true; 351 351 } 352 foreach ( ISimilarityCalculator op in Operators.OfType<ISimilarityCalculator>()) {353 op. Target= SolutionCreator.PermutationParameter.ActualName;352 foreach (TSPSimilarityCalculator op in Operators.OfType<TSPSimilarityCalculator>()) { 353 op.SolutionVariableName = SolutionCreator.PermutationParameter.ActualName; 354 354 } 355 355 }
Note: See TracChangeset
for help on using the changeset viewer.