Changeset 14456 for branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/Exhaustive1Shift.cs
- Timestamp:
- 12/06/16 15:07:45 (7 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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);
Note: See TracChangeset
for help on using the changeset viewer.