Changeset 14552 for branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch
- Timestamp:
- 01/09/17 00:36:20 (8 years ago)
- Location:
- branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/ExhaustiveHillClimb.cs
r14450 r14552 33 33 [StorableClass] 34 34 public class ExhaustiveHillClimb<TContext> : NamedItem, ILocalSearch<TContext> 35 where TContext : ISingleSolutionHeuristicAlgorithmContext<SingleObjectiveBasicProblem<PermutationEncoding>, Encodings.PermutationEncoding.Permutation> { 35 where TContext : ISingleSolutionHeuristicAlgorithmContext<ISingleObjectiveHeuristicOptimizationProblem, Encodings.PermutationEncoding.Permutation>, 36 IEvaluationServiceContext<Encodings.PermutationEncoding.Permutation> { 36 37 37 38 [StorableConstructor] … … 48 49 49 50 public void Optimize(TContext context) { 50 var evalWrapper = new EvaluationWrapper<Encodings.PermutationEncoding.Permutation>(context.Problem, context.Solution);51 51 var quality = context.Solution.Fitness; 52 52 try { 53 53 var result = Exhaustive.HillClimb(context.Random, context.Solution.Solution, ref quality, 54 context. Problem.Maximization, evalWrapper.Evaluate, CancellationToken.None);54 context.Maximization, context.Evaluate, CancellationToken.None); 55 55 context.IncrementEvaluatedSolutions(result.Item1); 56 56 context.Iterations = result.Item2; -
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/ExhaustiveHillClimbSubspace.cs
r14450 r14552 34 34 public class ExhaustiveHillClimbSubspace<TContext> : NamedItem, ILocalSearch<TContext> 35 35 where TContext : ISingleSolutionHeuristicAlgorithmContext<SingleObjectiveBasicProblem<PermutationEncoding>, Encodings.PermutationEncoding.Permutation>, 36 IPermutationSubspaceContext {36 IPermutationSubspaceContext, IEvaluationServiceContext<Encodings.PermutationEncoding.Permutation> { 37 37 38 38 [StorableConstructor] … … 49 49 50 50 public void Optimize(TContext context) { 51 var evalWrapper = new EvaluationWrapper<Encodings.PermutationEncoding.Permutation>(context.Problem, context.Solution);52 51 var quality = context.Solution.Fitness; 53 52 try { 54 53 var result = Exhaustive.HillClimb(context.Random, context.Solution.Solution, ref quality, 55 context.Problem.Maximization, evalWrapper.Evaluate, CancellationToken.None, context.Subspace.Subspace);54 context.Problem.Maximization, context.Evaluate, CancellationToken.None, context.Subspace.Subspace); 56 55 context.IncrementEvaluatedSolutions(result.Item1); 57 56 context.Iterations = result.Item2; -
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/Exhaustive.cs
r14456 r14552 34 34 35 35 public static Tuple<int, int> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm, 36 ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, double> eval,36 ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, CancellationToken, double> eval, 37 37 CancellationToken token, bool[,] subspace = null) { 38 if (double.IsNaN(quality)) quality = eval(perm );38 if (double.IsNaN(quality)) quality = eval(perm, token); 39 39 Tuple<int, int> changes; 40 40 switch (perm.PermutationType) { -
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/Exhaustive1Shift.cs
r14456 r14552 31 31 public static class Exhaustive1Shift { 32 32 public static Tuple<int, int> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm, 33 ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, double> eval,33 ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, CancellationToken, double> eval, 34 34 CancellationToken token, bool[,] subspace = null) { 35 35 var evaluations = 0; 36 36 var current = perm; 37 37 if (double.IsNaN(quality)) { 38 quality = eval(current );38 quality = eval(current, token); 39 39 evaluations++; 40 40 } … … 59 59 continue; 60 60 TranslocationManipulator.Apply(current, shift.Index1, shift.Index2, shift.Index3); 61 var q = eval(current );61 var q = eval(current, token); 62 62 evaluations++; 63 63 if (FitnessComparer.IsBetter(maximization, q, quality)) { -
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/Exhaustive2Opt.cs
r14456 r14552 31 31 public static class Exhaustive2Opt { 32 32 public static Tuple<int, int> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm, 33 ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, double> eval,33 ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, CancellationToken, double> eval, 34 34 CancellationToken token, bool[,] subspace = null) { 35 35 var evaluations = 0; 36 36 var current = perm; 37 37 if (double.IsNaN(quality)) { 38 quality = eval(current );38 quality = eval(current, token); 39 39 evaluations++; 40 40 } … … 56 56 57 57 InversionManipulator.Apply(current, opt.Index1, opt.Index2); 58 var q = eval(current );58 var q = eval(current, token); 59 59 evaluations++; 60 60 if (FitnessComparer.IsBetter(maximization, q, quality)) { -
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/ExhaustiveSwap2.cs
r14456 r14552 31 31 public static class ExhaustiveSwap2 { 32 32 public static Tuple<int, int> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm, 33 ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, double> eval,33 ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, CancellationToken, double> eval, 34 34 CancellationToken token, bool[,] subspace = null) { 35 35 var evaluations = 0; 36 36 var current = perm; 37 37 if (double.IsNaN(quality)) { 38 quality = eval(current );38 quality = eval(current, token); 39 39 evaluations++; 40 40 } … … 55 55 current[swap.Index1] = current[swap.Index2]; 56 56 current[swap.Index2] = h; 57 var q = eval(current );57 var q = eval(current, token); 58 58 evaluations++; 59 59 if (FitnessComparer.IsBetter(maximization, q, quality)) {
Note: See TracChangeset
for help on using the changeset viewer.