Changeset 17241 for branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/PathRelinkers
- Timestamp:
- 09/10/19 21:55:35 (5 years ago)
- Location:
- branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/PathRelinkers
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/PathRelinkers/TSPMultipleGuidesPathRelinker.cs
r17226 r17241 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 29 30 using HeuristicLab.Optimization.Operators; 30 31 using HeuristicLab.Parameters; 31 using HEAL.Attic;32 32 33 33 namespace HeuristicLab.Problems.TravelingSalesman { … … 39 39 /// </remarks> 40 40 [Item("TSPMultipleGuidesPathRelinker", "An operator that relinks paths between traveling salesman solutions using a multiple guiding strategy. 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.")] 41 [StorableType(" 6B5B2622-AB1D-47E6-8BBC-C6088D393149")]41 [StorableType("13e879fd-7621-402e-9345-7dbfdd78e3b6")] 42 42 public sealed class TSPMultipleGuidesPathRelinker : SingleObjectivePathRelinker { 43 #region Parameter properties 44 public ILookupParameter<DistanceMatrix> DistanceMatrixParameter { 45 get { return (ILookupParameter<DistanceMatrix>)Parameters["DistanceMatrix"]; } 46 } 47 #endregion 48 49 #region Properties 50 public DistanceMatrix DistanceMatrix { 51 get { return DistanceMatrixParameter.ActualValue; } 52 } 53 #endregion 43 [Storable] public ILookupParameter<ITSPData> TSPDataParameter { get; private set; } 54 44 55 45 [StorableConstructor] 56 46 private TSPMultipleGuidesPathRelinker(StorableConstructorFlag _) : base(_) { } 57 private TSPMultipleGuidesPathRelinker(TSPMultipleGuidesPathRelinker original, Cloner cloner) : base(original, cloner) { } 47 private TSPMultipleGuidesPathRelinker(TSPMultipleGuidesPathRelinker original, Cloner cloner) 48 : base(original, cloner) { 49 TSPDataParameter = cloner.Clone(original.TSPDataParameter); 50 } 58 51 public TSPMultipleGuidesPathRelinker() 59 52 : base() { 60 #region Create parameters 61 Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities.")); 62 #endregion 53 Parameters.Add(TSPDataParameter = new LookupParameter<ITSPData>("TSPData", "The main parameters of the TSP.")); 63 54 } 64 55 … … 67 58 } 68 59 69 public static ItemArray<IItem> Apply(IItem initiator, IItem[] guides, DistanceMatrix distances, PercentValue n) {60 public static ItemArray<IItem> Apply(IItem initiator, IItem[] guides, ITSPData tspData, PercentValue n) { 70 61 if (!(initiator is Permutation) || guides.Any(x => !(x is Permutation))) 71 62 throw new ArgumentException("Cannot relink path because some of the provided solutions have the wrong type."); … … 84 75 int currCityIndex = i; 85 76 int bestCityIndex = (i + 1) % v1.Length; 86 double currDistance = distances[v1[currCityIndex], v1[bestCityIndex]];77 double currDistance = tspData.GetDistance(v1[currCityIndex], v1[bestCityIndex]); 87 78 // check each guiding solution 88 79 targets.ToList().ForEach(solution => { … … 92 83 int succ = solution[(node.Index + 1) % solution.Length]; 93 84 // get distances to neighbors 94 var results = new[] { pred, succ }.Select(x => new { Id = x, Distance = distances[x, node.Id]});85 var results = new[] { pred, succ }.Select(x => new { Id = x, Distance = tspData.GetDistance(x, node.Id) }); 95 86 var bestCity = results.Where(x => x.Distance < currDistance).OrderBy(x => x.Distance).FirstOrDefault(); 96 87 if (bestCity != null) { … … 129 120 if (parents.Length < 2) 130 121 throw new ArgumentException("The number of parents is smaller than 2."); 131 return Apply(parents[0], parents.Skip(1).ToArray(), DistanceMatrix, n);122 return Apply(parents[0], parents.Skip(1).ToArray(), TSPDataParameter.ActualValue, n); 132 123 } 133 124 } -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/PathRelinkers/TSPPathRelinker.cs
r17226 r17241 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 28 29 using HeuristicLab.Encodings.PermutationEncoding; 29 30 using HeuristicLab.Optimization.Operators; 30 using HEAL.Attic;31 31 32 32 namespace HeuristicLab.Problems.TravelingSalesman { 33 33 34 /// <summary> 34 35 /// An operator that relinks paths between traveling salesman solutions. … … 38 39 /// </remarks> 39 40 [Item("TSPPathRelinker", "An operator that relinks paths between traveling salesman solutions. The operator incrementally assimilates the initiating solution into the guiding solution by correcting edges as needed.")] 40 [StorableType(" 0997A24C-0592-4CE4-A681-70C97890D3F7")]41 [StorableType("a2c5de50-a050-4269-b80e-1c995eb51626")] 41 42 public sealed class TSPPathRelinker : SingleObjectivePathRelinker { 42 43 [StorableConstructor] -
branches/2521_ProblemRefactoring/HeuristicLab.Problems.TravelingSalesman/3.3/PathRelinkers/TSPSimultaneousPathRelinker.cs
r17226 r17241 23 23 using System.Collections.Generic; 24 24 using System.Linq; 25 using HEAL.Attic; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 28 29 using HeuristicLab.Encodings.PermutationEncoding; 29 30 using HeuristicLab.Optimization.Operators; 30 using HEAL.Attic;31 31 32 32 namespace HeuristicLab.Problems.TravelingSalesman { … … 38 38 /// </remarks> 39 39 [Item("TSPSimultaneousPathRelinker", "An operator that relinks paths between traveling salesman solutions starting from both ends. The operator incrementally assimilates the initiating solution into the guiding solution and vice versa by correcting edges as needed.")] 40 [StorableType(" D44D112E-5139-4848-8A2B-66CFC5784EE4")]40 [StorableType("73457ec0-1d71-4d9f-b646-2ba3639317e2")] 41 41 public sealed class TSPSimultaneousPathRelinker : SingleObjectivePathRelinker { 42 42 [StorableConstructor]
Note: See TracChangeset
for help on using the changeset viewer.