- Timestamp:
- 02/23/17 10:42:58 (8 years ago)
- Location:
- branches/PerformanceComparison/HeuristicLab.Algorithms.MemPR/3.3/Permutation
- Files:
-
- 3 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 { -
branches/PerformanceComparison/HeuristicLab.Algorithms.MemPR/3.3/Permutation/PermutationMemPRContext.cs
r14552 r14691 23 23 using System.Runtime.Remoting.Contexts; 24 24 using HeuristicLab.Algorithms.MemPR.Interfaces; 25 using HeuristicLab.Analysis.FitnessLandscape; 25 26 using HeuristicLab.Common; 26 27 using HeuristicLab.Core; … … 61 62 [Item("MemPR Solution Context (permutation)", "MemPR solution context for permutation encoded problems.")] 62 63 [StorableClass] 63 public sealed class PermutationMemPRSolutionContext : MemPRSolutionContext<ISingleObjectiveHeuristicOptimizationProblem, Encodings.PermutationEncoding.Permutation, PermutationMemPRPopulationContext, PermutationMemPRSolutionContext>, IPermutationSubspaceContext { 64 public sealed class PermutationMemPRSolutionContext : MemPRSolutionContext<ISingleObjectiveHeuristicOptimizationProblem, Encodings.PermutationEncoding.Permutation, PermutationMemPRPopulationContext, PermutationMemPRSolutionContext>, IPermutationSubspaceContext, 65 ILocalSearchPathContext<Encodings.PermutationEncoding.Permutation> { 64 66 65 67 [Storable] … … 87 89 return new PermutationMemPRSolutionContext(this, cloner); 88 90 } 91 92 public DirectedPath<Encodings.PermutationEncoding.Permutation> LocalSearchPaths { 93 get { return BaseContext.LocalSearchPaths; } 94 } 89 95 } 90 96 }
Note: See TracChangeset
for help on using the changeset viewer.