Changeset 14690 for branches/PerformanceComparison/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI
- Timestamp:
- 02/20/17 20:41:33 (8 years ago)
- Location:
- branches/PerformanceComparison/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/PerformanceComparison/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/Exhaustive.cs
r14552 r14690 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Threading; 24 25 using HeuristicLab.Core; … … 33 34 #endif 34 35 35 public static Tuple<int, int> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm,36 refdouble quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, CancellationToken, double> eval,36 public static IEnumerable<Tuple<Encodings.PermutationEncoding.Permutation, double, int>> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm, 37 double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, CancellationToken, double> eval, 37 38 CancellationToken token, bool[,] subspace = null) { 38 39 if (double.IsNaN(quality)) quality = eval(perm, token); 39 Tuple<int, int> changes;40 IEnumerable<Tuple<Encodings.PermutationEncoding.Permutation, double, int>> localSearchPath; 40 41 switch (perm.PermutationType) { 41 42 case PermutationTypes.Absolute: 42 changes = ExhaustiveSwap2.HillClimb(random, perm, refquality, maximization, eval, token, subspace);43 localSearchPath = ExhaustiveSwap2.HillClimb(random, perm, quality, maximization, eval, token, subspace); 43 44 break; 44 45 case PermutationTypes.RelativeDirected: 45 changes = Exhaustive1Shift.HillClimb(random, perm, refquality, maximization, eval, token, subspace);46 localSearchPath = Exhaustive1Shift.HillClimb(random, perm, quality, maximization, eval, token, subspace); 46 47 break; 47 48 case PermutationTypes.RelativeUndirected: 48 changes = Exhaustive2Opt.HillClimb(random, perm, refquality, maximization, eval, token, subspace);49 localSearchPath = Exhaustive2Opt.HillClimb(random, perm, quality, maximization, eval, token, subspace); 49 50 break; 50 51 default: throw new ArgumentException(string.Format("Permutation type {0} is not known", perm.PermutationType)); 51 52 } 52 53 if (VALIDATE && !perm.Validate()) throw new ArgumentException("HillClimb produced invalid child"); 53 return changes;54 return localSearchPath; 54 55 } 55 56 } -
branches/PerformanceComparison/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/Exhaustive1Shift.cs
r14552 r14690 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using System.Threading; … … 30 31 namespace HeuristicLab.Algorithms.MemPR.Permutation.LocalSearch { 31 32 public static class Exhaustive1Shift { 32 public static Tuple<int, int> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm, 33 ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, CancellationToken, double> eval, 33 public static IEnumerable<Tuple<Encodings.PermutationEncoding.Permutation, double, int>> 34 HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm, 35 double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, CancellationToken, double> eval, 34 36 CancellationToken token, bool[,] subspace = null) { 35 37 var evaluations = 0; … … 40 42 } 41 43 TranslocationMove lastSuccessMove = null; 42 var steps = 0;43 44 var neighborhood = ExhaustiveInsertionMoveGenerator.Generate(current).Shuffle(random).ToList(); 44 45 while (true) { … … 62 63 evaluations++; 63 64 if (FitnessComparer.IsBetter(maximization, q, quality)) { 64 steps++;65 yield return Tuple.Create(current, q, evaluations); 65 66 quality = q; 66 67 lastSuccessMove = shift; … … 74 75 if (lastSuccessMove == null) break; 75 76 } 76 return Tuple.Create(evaluations, steps);77 yield return Tuple.Create(current, quality, evaluations); 77 78 } 78 79 } -
branches/PerformanceComparison/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/Exhaustive2Opt.cs
r14556 r14690 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using System.Threading; … … 30 31 namespace HeuristicLab.Algorithms.MemPR.Permutation.LocalSearch { 31 32 public static class Exhaustive2Opt { 32 public static Tuple<int, int> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm, 33 ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, CancellationToken, double> eval, 33 public static IEnumerable<Tuple<Encodings.PermutationEncoding.Permutation, double, int>> 34 HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm, 35 double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, CancellationToken, double> eval, 34 36 CancellationToken token, bool[,] subspace = null) { 35 37 var evaluations = 0; … … 40 42 } 41 43 InversionMove lastSuccessMove = null; 42 var steps = 0;43 44 var neighborhood = ExhaustiveInversionMoveGenerator.Generate(current).Shuffle(random).ToList(); 44 45 while (true) { … … 59 60 evaluations++; 60 61 if (FitnessComparer.IsBetter(maximization, q, quality)) { 61 steps++;62 yield return Tuple.Create(current, q, evaluations); 62 63 quality = q; 63 64 lastSuccessMove = opt; … … 71 72 if (lastSuccessMove == null) break; 72 73 } 73 return Tuple.Create(evaluations, steps);74 yield return Tuple.Create(current, quality, evaluations); 74 75 } 75 76 } -
branches/PerformanceComparison/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/ExhaustiveSwap2.cs
r14552 r14690 21 21 22 22 using System; 23 using System.Collections.Generic; 23 24 using System.Linq; 24 25 using System.Threading; … … 30 31 namespace HeuristicLab.Algorithms.MemPR.Permutation.LocalSearch { 31 32 public static class ExhaustiveSwap2 { 32 public static Tuple<int, int> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm, 33 ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, CancellationToken, double> eval, 33 public static IEnumerable<Tuple<Encodings.PermutationEncoding.Permutation, double, int>> 34 HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm, 35 double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, CancellationToken, double> eval, 34 36 CancellationToken token, bool[,] subspace = null) { 35 37 var evaluations = 0; … … 40 42 } 41 43 Swap2Move lastSuccessMove = null; 42 var steps = 0;43 44 var neighborhood = ExhaustiveSwap2MoveGenerator.Generate(current).Shuffle(random).ToList(); 44 45 while (true) { … … 58 59 evaluations++; 59 60 if (FitnessComparer.IsBetter(maximization, q, quality)) { 60 steps++;61 yield return Tuple.Create(current, q, evaluations); 61 62 quality = q; 62 63 lastSuccessMove = swap; … … 73 74 if (lastSuccessMove == null) break; 74 75 } 75 return Tuple.Create(evaluations, steps);76 yield return Tuple.Create(current, quality, evaluations); 76 77 } 77 78 }
Note: See TracChangeset
for help on using the changeset viewer.