Changeset 14456 for branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch
- Timestamp:
- 12/06/16 15:07:45 (8 years ago)
- Location:
- branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/Exhaustive.cs
r14450 r14456 35 35 public static Tuple<int, int> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm, 36 36 ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, double> eval, 37 CancellationToken token, bool[,] noTouch= null) {37 CancellationToken token, bool[,] subspace = null) { 38 38 if (double.IsNaN(quality)) quality = eval(perm); 39 39 Tuple<int, int> changes; 40 40 switch (perm.PermutationType) { 41 41 case PermutationTypes.Absolute: 42 changes = ExhaustiveSwap2.HillClimb(random, perm, ref quality, maximization, eval, token, noTouch);42 changes = ExhaustiveSwap2.HillClimb(random, perm, ref quality, maximization, eval, token, subspace); 43 43 break; 44 44 case PermutationTypes.RelativeDirected: 45 changes = Exhaustive1Shift.HillClimb(random, perm, ref quality, maximization, eval, token, noTouch);45 changes = Exhaustive1Shift.HillClimb(random, perm, ref quality, maximization, eval, token, subspace); 46 46 break; 47 47 case PermutationTypes.RelativeUndirected: 48 changes = Exhaustive2Opt.HillClimb(random, perm, ref quality, maximization, eval, token, noTouch);48 changes = Exhaustive2Opt.HillClimb(random, perm, ref quality, maximization, eval, token, subspace); 49 49 break; 50 50 default: throw new ArgumentException(string.Format("Permutation type {0} is not known", perm.PermutationType)); -
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/Exhaustive1Shift.cs
r14453 r14456 21 21 22 22 using System; 23 using System.Linq; 23 24 using System.Threading; 24 25 using HeuristicLab.Algorithms.MemPR.Util; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Encodings.PermutationEncoding; 28 using HeuristicLab.Random; 27 29 28 30 namespace HeuristicLab.Algorithms.MemPR.Permutation.LocalSearch { … … 30 32 public static Tuple<int, int> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm, 31 33 ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, double> eval, 32 CancellationToken token, bool[,] noTouch = null) { 34 CancellationToken token, bool[,] subspace = null) { 35 var evaluations = 0; 33 36 var current = perm; 34 if (double.IsNaN(quality)) quality = eval(current); 37 if (double.IsNaN(quality)) { 38 quality = eval(current); 39 evaluations++; 40 } 35 41 TranslocationMove lastSuccessMove = null; 36 int steps = 0, evaluations = 0; 42 var steps = 0; 43 var neighborhood = ExhaustiveInsertionMoveGenerator.Generate(current).Shuffle(random).ToList(); 37 44 while (true) { 38 foreach (var shift in ExhaustiveInsertionMoveGenerator.Generate(current)) {45 foreach (var shift in neighborhood) { 39 46 if (lastSuccessMove != null && shift.Index1 == lastSuccessMove.Index1 && shift.Index2 == lastSuccessMove.Index2 && shift.Index3 == lastSuccessMove.Index3) { 40 47 // been there, done that … … 48 55 var next3 = (shift.Index3 + 1) % current.Length; 49 56 if (prev3 < 0) prev3 += current.Length; 50 if ( noTouch != null && ((noTouch[current[prev1], current[shift.Index1]] || noTouch[current[shift.Index1], current[next1]]51 || noTouch[current[prev3], current[shift.Index3]] || noTouch[current[shift.Index3], current[next3]])))57 if (subspace != null && !(subspace[current[prev1], current[shift.Index1]] && subspace[current[shift.Index1], current[next1]] 58 && subspace[current[prev3], current[shift.Index3]] && subspace[current[shift.Index3], current[next3]])) 52 59 continue; 53 60 TranslocationManipulator.Apply(current, shift.Index1, shift.Index2, shift.Index3); -
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/Exhaustive2Opt.cs
r14453 r14456 21 21 22 22 using System; 23 using System.Linq; 23 24 using System.Threading; 24 25 using HeuristicLab.Algorithms.MemPR.Util; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Encodings.PermutationEncoding; 28 using HeuristicLab.Random; 27 29 28 30 namespace HeuristicLab.Algorithms.MemPR.Permutation.LocalSearch { … … 30 32 public static Tuple<int, int> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm, 31 33 ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, double> eval, 32 CancellationToken token, bool[,] noTouch = null) { 34 CancellationToken token, bool[,] subspace = null) { 35 var evaluations = 0; 33 36 var current = perm; 34 if (double.IsNaN(quality)) quality = eval(current); 37 if (double.IsNaN(quality)) { 38 quality = eval(current); 39 evaluations++; 40 } 35 41 InversionMove lastSuccessMove = null; 36 int steps = 0, evaluations = 0; 42 var steps = 0; 43 var neighborhood = ExhaustiveInversionMoveGenerator.Generate(current).Shuffle(random).ToList(); 37 44 while (true) { 38 foreach (var opt in ExhaustiveInversionMoveGenerator.Generate(current)) {45 foreach (var opt in neighborhood) { 39 46 if (lastSuccessMove != null && opt.Index1 == lastSuccessMove.Index1 && opt.Index2 == lastSuccessMove.Index2) { 40 47 // been there, done that … … 45 52 var next = (opt.Index2 + 1) % current.Length; 46 53 if (prev < 0) prev += current.Length; 47 if ( noTouch != null && ((noTouch[current[prev], current[opt.Index1]]) || (noTouch[current[opt.Index2], current[next]])))54 if (subspace != null && !(subspace[current[prev], current[opt.Index1]] && subspace[current[opt.Index2], current[next]])) 48 55 continue; 49 56 -
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/ExhaustiveSwap2.cs
r14453 r14456 21 21 22 22 using System; 23 using System.Linq; 23 24 using System.Threading; 24 25 using HeuristicLab.Algorithms.MemPR.Util; 25 26 using HeuristicLab.Core; 26 27 using HeuristicLab.Encodings.PermutationEncoding; 28 using HeuristicLab.Random; 27 29 28 30 namespace HeuristicLab.Algorithms.MemPR.Permutation.LocalSearch { … … 30 32 public static Tuple<int, int> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm, 31 33 ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, double> eval, 32 CancellationToken token, bool[,] noTouch = null) { 34 CancellationToken token, bool[,] subspace = null) { 35 var evaluations = 0; 33 36 var current = perm; 34 if (double.IsNaN(quality)) quality = eval(current); 37 if (double.IsNaN(quality)) { 38 quality = eval(current); 39 evaluations++; 40 } 35 41 Swap2Move lastSuccessMove = null; 36 int steps = 0, evaluations = 0; 42 var steps = 0; 43 var neighborhood = ExhaustiveSwap2MoveGenerator.Generate(current).Shuffle(random).ToList(); 37 44 while (true) { 38 foreach (var swap in ExhaustiveSwap2MoveGenerator.Generate(current)) {45 foreach (var swap in neighborhood) { 39 46 if (lastSuccessMove != null && swap.Index1 == lastSuccessMove.Index1 && swap.Index2 == lastSuccessMove.Index2) { 40 47 // been there, done that … … 42 49 break; 43 50 } 44 if ( noTouch != null && (noTouch[swap.Index1, 0] || noTouch[swap.Index2, 0]))51 if (subspace != null && !(subspace[swap.Index1, 0] && subspace[swap.Index2, 0])) 45 52 continue; 46 53
Note: See TracChangeset
for help on using the changeset viewer.