Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/06/16 15:07:45 (7 years ago)
Author:
abeham
Message:

#2701:

  • Using evaluated solutions from HC as max evaluations for tabu walking in MemPR
  • Fixed some bugs in MemPR (permutation) regarding subspace calculation (true means okay, false means no)
  • Fixed bug in TSP
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/Exhaustive1Shift.cs

    r14453 r14456  
    2121
    2222using System;
     23using System.Linq;
    2324using System.Threading;
    2425using HeuristicLab.Algorithms.MemPR.Util;
    2526using HeuristicLab.Core;
    2627using HeuristicLab.Encodings.PermutationEncoding;
     28using HeuristicLab.Random;
    2729
    2830namespace HeuristicLab.Algorithms.MemPR.Permutation.LocalSearch {
     
    3032    public static Tuple<int, int> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm,
    3133      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;
    3336      var current = perm;
    34       if (double.IsNaN(quality)) quality = eval(current);
     37      if (double.IsNaN(quality)) {
     38        quality = eval(current);
     39        evaluations++;
     40      }
    3541      TranslocationMove lastSuccessMove = null;
    36       int steps = 0, evaluations = 0;
     42      var steps = 0;
     43      var neighborhood = ExhaustiveInsertionMoveGenerator.Generate(current).Shuffle(random).ToList();
    3744      while (true) {
    38         foreach (var shift in ExhaustiveInsertionMoveGenerator.Generate(current)) {
     45        foreach (var shift in neighborhood) {
    3946          if (lastSuccessMove != null && shift.Index1 == lastSuccessMove.Index1 && shift.Index2 == lastSuccessMove.Index2 && shift.Index3 == lastSuccessMove.Index3) {
    4047            // been there, done that
     
    4855          var next3 = (shift.Index3 + 1) % current.Length;
    4956          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]]))
    5259            continue;
    5360          TranslocationManipulator.Apply(current, shift.Index1, shift.Index2, shift.Index3);
Note: See TracChangeset for help on using the changeset viewer.