Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
12/06/16 15:07:45 (8 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
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  
    3535    public static Tuple<int, int> HillClimb(IRandom random, Encodings.PermutationEncoding.Permutation perm,
    3636      ref double quality, bool maximization, Func<Encodings.PermutationEncoding.Permutation, double> eval,
    37       CancellationToken token, bool[,] noTouch = null) {
     37      CancellationToken token, bool[,] subspace = null) {
    3838      if (double.IsNaN(quality)) quality = eval(perm);
    3939      Tuple<int, int> changes;
    4040      switch (perm.PermutationType) {
    4141        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);
    4343          break;
    4444        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);
    4646          break;
    4747        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);
    4949          break;
    5050        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  
    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);
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/Exhaustive2Opt.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      InversionMove lastSuccessMove = null;
    36       int steps = 0, evaluations = 0;
     42      var steps = 0;
     43      var neighborhood = ExhaustiveInversionMoveGenerator.Generate(current).Shuffle(random).ToList();
    3744      while (true) {
    38         foreach (var opt in ExhaustiveInversionMoveGenerator.Generate(current)) {
     45        foreach (var opt in neighborhood) {
    3946          if (lastSuccessMove != null && opt.Index1 == lastSuccessMove.Index1 && opt.Index2 == lastSuccessMove.Index2) {
    4047            // been there, done that
     
    4552          var next = (opt.Index2 + 1) % current.Length;
    4653          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]]))
    4855            continue;
    4956
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/LocalSearch/StaticAPI/ExhaustiveSwap2.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      Swap2Move lastSuccessMove = null;
    36       int steps = 0, evaluations = 0;
     42      var steps = 0;
     43      var neighborhood = ExhaustiveSwap2MoveGenerator.Generate(current).Shuffle(random).ToList();
    3744      while (true) {
    38         foreach (var swap in ExhaustiveSwap2MoveGenerator.Generate(current)) {
     45        foreach (var swap in neighborhood) {
    3946          if (lastSuccessMove != null && swap.Index1 == lastSuccessMove.Index1 && swap.Index2 == lastSuccessMove.Index2) {
    4047            // been there, done that
     
    4249            break;
    4350          }
    44           if (noTouch != null && (noTouch[swap.Index1, 0] || noTouch[swap.Index2, 0]))
     51          if (subspace != null && !(subspace[swap.Index1, 0] && subspace[swap.Index2, 0]))
    4552            continue;
    4653
Note: See TracChangeset for help on using the changeset viewer.