Changeset 13412 for branches/PTSP/HeuristicLab.Problems.PTSP/3.3/Improvers
- Timestamp:
- 11/28/15 23:38:51 (9 years ago)
- Location:
- branches/PTSP/HeuristicLab.Problems.PTSP/3.3/Improvers
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PTSP/HeuristicLab.Problems.PTSP/3.3/Improvers/PTSPExhaustiveInsertionLocalImprovement.cs
r12261 r13412 21 21 22 22 using System; 23 using System.Threading; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 29 30 using HeuristicLab.Parameters; 30 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using System.Threading;32 32 33 33 namespace HeuristicLab.Problems.PTSP { … … 36 36 /// </summary> 37 37 /// <remarks> 38 /// The operator tries to improve the probabilistic traveling salesman solution by swapping two randomly chosen edges for a certain number of times.38 /// The operator tries to improve the probabilistic traveling salesman solution by inserting a city in the tour between two other cities for a certain number of times. 39 39 /// </remarks> 40 40 [Item("PTSPExhaustiveInsertionLocalImprovement", "An operator that improves probabilistic traveling salesman solutions. The operator tries to improve the probabilistic traveling salesman solution by swapping two randomly chosen edges for a certain number of times.")] 41 41 [StorableClass] 42 public sealed class PTSPExhaustiveInsertionLocalImprovement : SingleSuccessorOperator, I LocalImprovementOperator {43 42 public sealed class PTSPExhaustiveInsertionLocalImprovement : SingleSuccessorOperator, IEstimatedPTSPOperator, ILocalImprovementOperator { 43 44 44 public ILookupParameter<IntValue> LocalIterationsParameter { 45 45 get { return (ILookupParameter<IntValue>)Parameters["LocalIterations"]; } … … 74 74 } 75 75 76 public I ValueParameter<ItemList<ItemList<IntValue>>> RealizationsParameter {77 get { return (I ValueParameter<ItemList<ItemList<IntValue>>>)Parameters["Realizations"]; }76 public ILookupParameter<ItemList<BoolArray>> RealizationsParameter { 77 get { return (ILookupParameter<ItemList<BoolArray>>)Parameters["Realizations"]; } 78 78 } 79 79 80 80 [StorableConstructor] 81 protected PTSPExhaustiveInsertionLocalImprovement(bool deserializing) : base(deserializing) { } 82 protected PTSPExhaustiveInsertionLocalImprovement(PTSPExhaustiveInsertionLocalImprovement original, Cloner cloner) 83 : base(original, cloner) { 84 } 81 private PTSPExhaustiveInsertionLocalImprovement(bool deserializing) : base(deserializing) { } 82 private PTSPExhaustiveInsertionLocalImprovement(PTSPExhaustiveInsertionLocalImprovement original, Cloner cloner) : base(original, cloner) { } 85 83 public PTSPExhaustiveInsertionLocalImprovement() 86 84 : base() { … … 93 91 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem should be maximized or minimized.")); 94 92 Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities.")); 95 Parameters.Add(new ValueParameter<ItemList<ItemList<IntValue>>>("Realizations", "The concrete..."));93 Parameters.Add(new LookupParameter<ItemList<BoolArray>>("Realizations", "The list of samples drawn from all possible stochastic instances.")); 96 94 } 97 95 … … 100 98 } 101 99 102 public static void Improve(Permutation assignment, DoubleMatrix distances, DoubleValue quality, IntValue localIterations, IntValue evaluatedSolutions, bool maximization, int maxIterations, CancellationToken cancellation, ItemList< ItemList<IntValue>> realizations) {103 DistanceMatrixdistanceM = (DistanceMatrix)distances;104 for ( inti = localIterations.Value; i < maxIterations; i++) {100 public static void Improve(Permutation assignment, DoubleMatrix distances, DoubleValue quality, IntValue localIterations, IntValue evaluatedSolutions, bool maximization, int maxIterations, CancellationToken cancellation, ItemList<BoolArray> realizations) { 101 var distanceM = (DistanceMatrix)distances; 102 for (var i = localIterations.Value; i < maxIterations; i++) { 105 103 TranslocationMove bestMove = null; 106 104 double bestQuality = 0; // we have to make an improvement, so 0 is the baseline 107 105 double evaluations = 0.0; 108 106 foreach (var move in ExhaustiveInsertionMoveGenerator.Generate(assignment)) { 109 double moveQuality = PTSPEstimatedInsertion Evaluator.EvaluateByDistanceMatrix(assignment, move, distanceM, realizations);107 double moveQuality = PTSPEstimatedInsertionMoveEvaluator.EvaluateByDistanceMatrix(assignment, move, distanceM, realizations); 110 108 int min = Math.Min(move.Index1, move.Index3); 111 109 int max = Math.Max(move.Index2, move.Index3 + (move.Index2 - move.Index1)); … … 135 133 var localIterations = LocalIterationsParameter.ActualValue; 136 134 var evaluations = EvaluatedSolutionsParameter.ActualValue; 137 var realizations = RealizationsParameter. Value;135 var realizations = RealizationsParameter.ActualValue; 138 136 if (localIterations == null) { 139 137 localIterations = new IntValue(0); -
branches/PTSP/HeuristicLab.Problems.PTSP/3.3/Improvers/PTSPExhaustiveInversionLocalImprovement.cs
r12380 r13412 21 21 22 22 using System; 23 using System.Threading; 23 24 using HeuristicLab.Common; 24 25 using HeuristicLab.Core; … … 29 30 using HeuristicLab.Parameters; 30 31 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 31 using System.Threading;32 32 33 33 namespace HeuristicLab.Problems.PTSP { … … 40 40 [Item("PTSPExhaustiveInversionLocalImprovement", "An operator that improves probabilistic traveling salesman solutions. The operator tries to improve the probabilistic traveling salesman solution by swapping two randomly chosen edges for a certain number of times.")] 41 41 [StorableClass] 42 public sealed class PTSPExhaustiveInversionLocalImprovement : SingleSuccessorOperator, I LocalImprovementOperator {43 42 public sealed class PTSPExhaustiveInversionLocalImprovement : SingleSuccessorOperator, IEstimatedPTSPOperator, ILocalImprovementOperator { 43 44 44 public ILookupParameter<IntValue> LocalIterationsParameter { 45 45 get { return (ILookupParameter<IntValue>)Parameters["LocalIterations"]; } … … 74 74 } 75 75 76 public I ValueParameter<ItemList<ItemList<IntValue>>> RealizationsParameter {77 get { return (I ValueParameter<ItemList<ItemList<IntValue>>>)Parameters["Realizations"]; }76 public ILookupParameter<ItemList<BoolArray>> RealizationsParameter { 77 get { return (ILookupParameter<ItemList<BoolArray>>)Parameters["Realizations"]; } 78 78 } 79 79 80 80 [StorableConstructor] 81 protected PTSPExhaustiveInversionLocalImprovement(bool deserializing) : base(deserializing) { } 82 protected PTSPExhaustiveInversionLocalImprovement(PTSPExhaustiveInversionLocalImprovement original, Cloner cloner) 83 : base(original, cloner) { 84 } 81 private PTSPExhaustiveInversionLocalImprovement(bool deserializing) : base(deserializing) { } 82 private PTSPExhaustiveInversionLocalImprovement(PTSPExhaustiveInversionLocalImprovement original, Cloner cloner) : base(original, cloner) { } 85 83 public PTSPExhaustiveInversionLocalImprovement() 86 84 : base() { … … 93 91 Parameters.Add(new LookupParameter<BoolValue>("Maximization", "True if the problem should be maximized or minimized.")); 94 92 Parameters.Add(new LookupParameter<DistanceMatrix>("DistanceMatrix", "The matrix which contains the distances between the cities.")); 95 Parameters.Add(new ValueParameter<ItemList<ItemList<IntValue>>>("Realizations", "The concrete..."));93 Parameters.Add(new LookupParameter<ItemList<BoolArray>>("Realizations", "The list of samples drawn from all possible stochastic instances.")); 96 94 } 97 95 … … 100 98 } 101 99 102 public static void Improve(Permutation assignment, DoubleMatrix distances, DoubleValue quality, IntValue localIterations, IntValue evaluatedSolutions, bool maximization, int maxIterations, CancellationToken cancellation, ItemList< ItemList<IntValue>> realizations) {103 DistanceMatrixdistanceM = (DistanceMatrix)distances;104 for ( inti = localIterations.Value; i < maxIterations; i++) {100 public static void Improve(Permutation assignment, DoubleMatrix distances, DoubleValue quality, IntValue localIterations, IntValue evaluatedSolutions, bool maximization, int maxIterations, CancellationToken cancellation, ItemList<BoolArray> realizations) { 101 var distanceM = (DistanceMatrix)distances; 102 for (var i = localIterations.Value; i < maxIterations; i++) { 105 103 InversionMove bestMove = null; 106 104 double bestQuality = 0; // we have to make an improvement, so 0 is the baseline 107 105 double evaluations = 0.0; 108 106 foreach (var move in ExhaustiveInversionMoveGenerator.Generate(assignment)) { 109 double moveQuality = PTSPEstimatedInversion Evaluator.EvaluateByDistanceMatrix(assignment, move, distanceM, realizations);107 double moveQuality = PTSPEstimatedInversionMoveEvaluator.EvaluateByDistanceMatrix(assignment, move, distanceM, realizations); 110 108 evaluations += 2 * (move.Index2 - move.Index1 + 1) / (double)assignment.Length; 111 109 if (maximization && moveQuality > bestQuality … … 132 130 var localIterations = LocalIterationsParameter.ActualValue; 133 131 var evaluations = EvaluatedSolutionsParameter.ActualValue; 134 var realizations = RealizationsParameter. Value;132 var realizations = RealizationsParameter.ActualValue; 135 133 if (localIterations == null) { 136 134 localIterations = new IntValue(0);
Note: See TracChangeset
for help on using the changeset viewer.