Changeset 14691 for branches/PerformanceComparison/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch
- Timestamp:
- 02/23/17 10:42:58 (8 years ago)
- Location:
- branches/PerformanceComparison/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/ExhaustiveHillClimb.cs
r14690 r14691 28 28 using HeuristicLab.Optimization; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Problems.QuadraticAssignment; 30 31 31 32 namespace HeuristicLab.Algorithms.MemPR.Permutation.LocalSearch { … … 54 55 var quality = context.Solution.Fitness; 55 56 try { 57 58 var min = 0.0; 59 var max = 1.0; 60 var qap = context.Problem as QuadraticAssignmentProblem; 61 if (qap != null) { 62 min = qap.LowerBound.Value; 63 max = qap.AverageQuality.Value; 64 } 65 56 66 var path = new List<Tuple<Encodings.PermutationEncoding.Permutation, double>>(); 57 path.Add(Tuple.Create((Encodings.PermutationEncoding.Permutation)context.Solution.Solution.Clone(), quality));67 path.Add(Tuple.Create((Encodings.PermutationEncoding.Permutation)context.Solution.Solution.Clone(), (quality - min) / (max - min))); 58 68 59 69 var result = Exhaustive.HillClimb(context.Random, context.Solution.Solution, quality, 60 70 context.Maximization, context.Evaluate, CancellationToken.None); 61 62 Tuple<Encodings.PermutationEncoding.Permutation, double, int> last = null;71 72 var evaluations = 0; 63 73 foreach (var step in result) { 64 path.Add(Tuple.Create((Encodings.PermutationEncoding.Permutation)step.Item1.Clone(), step.Item2));65 last = step;74 path.Add(Tuple.Create((Encodings.PermutationEncoding.Permutation)step.Item1.Clone(), (step.Item2 - min) / (max - min))); 75 evaluations = step.Item3; // last one will be actual evaluations 66 76 } 67 77 context.LocalSearchPaths.AddPath(path); 68 context.IncrementEvaluatedSolutions( last.Item3);78 context.IncrementEvaluatedSolutions(evaluations); 69 79 context.Iterations = path.Count - 2; 70 80 } finally { -
branches/PerformanceComparison/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/ExhaustiveHillClimbSubspace.cs
r14690 r14691 28 28 using HeuristicLab.Optimization; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Problems.QuadraticAssignment; 30 31 31 32 namespace HeuristicLab.Algorithms.MemPR.Permutation.LocalSearch { … … 54 55 var quality = context.Solution.Fitness; 55 56 try { 57 var min = 0.0; 58 var max = 1.0; 59 var qap = context.Problem as QuadraticAssignmentProblem; 60 if (qap != null) { 61 min = qap.LowerBound.Value; 62 max = qap.AverageQuality.Value; 63 } 64 56 65 var path = new List<Tuple<Encodings.PermutationEncoding.Permutation, double>>(); 57 path.Add(Tuple.Create((Encodings.PermutationEncoding.Permutation)context.Solution.Solution.Clone(), quality));66 path.Add(Tuple.Create((Encodings.PermutationEncoding.Permutation)context.Solution.Solution.Clone(), (quality - min) / (max - min))); 58 67 59 68 var result = Exhaustive.HillClimb(context.Random, context.Solution.Solution, quality, 60 69 context.Maximization, context.Evaluate, CancellationToken.None, context.Subspace.Subspace); 61 70 62 Tuple<Encodings.PermutationEncoding.Permutation, double, int> last = null;71 var evaluations = 0; 63 72 foreach (var step in result) { 64 path.Add(Tuple.Create((Encodings.PermutationEncoding.Permutation)step.Item1.Clone(), step.Item2));65 last = step;73 path.Add(Tuple.Create((Encodings.PermutationEncoding.Permutation)step.Item1.Clone(), (step.Item2 - min) / (max - min))); 74 evaluations = step.Item3; // last one will be actual evaluations 66 75 } 67 76 context.LocalSearchPaths.AddPath(path); 68 context.IncrementEvaluatedSolutions( last.Item3);77 context.IncrementEvaluatedSolutions(evaluations); 69 78 context.Iterations = path.Count - 2; 70 79 } finally {
Note: See TracChangeset
for help on using the changeset viewer.