Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/03/18 00:28:51 (7 years ago)
Author:
abeham
Message:

#1614:

  • fixed a bug in GRASP where solutions in the elite set would be mutated
  • introduced termination criteria when reaching best-known quality
  • tweaked generating random numbers in StochasticNMoveSingleMoveGenerator
  • changed DiscreteLocationCrossover to use an allele from one of the parents instead of introducing a mutation in case no feasible insert location is found
  • changed OSGA maxselpress to 500
  • slight change to contexts, introduced single-objectiveness much earlier in the class hierachy
    • limited ContextAlgorithm to SingleObjectiveBasicProblems (doesn't matter here)
File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/GeneralizedQAP/HeuristicLab.Problems.GeneralizedQuadraticAssignment.Algorithms/3.3/GRASP/GRASP.cs

    r15564 r15572  
    3636  /// This is an implementation of the algorithm described in Mateus, G.R., Resende, M.G.C. & Silva, R.M.A. J Heuristics (2011) 17: 527. https://doi.org/10.1007/s10732-010-9144-0
    3737  /// </summary>
     38  /// <remarks>
     39  /// A fine distinction to the described algorithm is that newly found best solutions are always accepted into the elite set. This is reasonable, but not mentioned in the paper by Mateus et al.
     40  /// </remarks>
    3841  [Item("GRASP+PR (GQAP)", "The algorithm implements the Greedy Randomized Adaptive Search Procedure (GRASP) with Path Relinking as described in Mateus, G., Resende, M., and Silva, R. 2011. GRASP with path-relinking for the generalized quadratic assignment problem. Journal of Heuristics 17, Springer Netherlands, pp. 527-565.")]
    3942  [Creatable(CreatableAttribute.Categories.PopulationBasedAlgorithms)]
    4043  [StorableClass]
    41   public sealed class GRASP : StochasticAlgorithm<GRASPContext> {
     44  public sealed class GRASP : StochasticAlgorithm<GRASPContext, IntegerVectorEncoding> {
    4245
    4346    public override bool SupportsPause {
     
    175178          GQAPSolution pi_prime;
    176179          if (!Problem.ProblemInstance.IsFeasible(pi_prime_vec)) // line 5 in Algorithm 1
    177             pi_prime = Context.AtPopulation(Context.Random.Next(Context.PopulationCount)).Solution; // line 6 in Algorithm 1
     180            pi_prime = (GQAPSolution)Context.AtPopulation(Context.Random.Next(Context.PopulationCount)).Solution.Clone(); // line 6 in Algorithm 1
    178181          else {
    179182            // This is necessary, because pi_prime has not been evaluated yet and such details are not covered in Algorithm 1
     
    188191          var fitness = Problem.ProblemInstance.ToSingleObjective(pi_prime.Evaluation);
    189192          // Book-keeping
    190           if (Context.BestQuality > fitness) {
     193          var newBest = Context.BestQuality > fitness;
     194          if (newBest) {
    191195            Context.BestQuality = fitness;
    192196            Context.BestSolution = (GQAPSolution)pi_prime.Clone();
     
    194198
    195199          if (Context.PopulationCount == EliteSetSize) { // line 12 in Algorithm 1
    196             var fit = Problem.ProblemInstance.ToSingleObjective(pi_prime.Evaluation);
    197200            double[] similarities = Context.Population.Select(x => HammingSimilarityCalculator.CalculateSimilarity(x.Solution.Assignment, pi_prime.Assignment)).ToArray();
    198             if (similarities.Max() <= 1.0 - (MinimumDifference / (double)pi_prime.Assignment.Length)) { // cond. 2 of line 13 in Algorithm 1
    199               var replacement = Context.Population.Select((v, i) => new { V = v, Index = i })
    200                                           .Where(x => x.V.Fitness >= fit).ToArray();
    201               if (replacement.Length > 0) { // cond. 1 of line 13 in Algorithm 1
    202                 // next two lines: line 14 in Algorithm 1
    203                 replacement = replacement.OrderBy(x => similarities[x.Index]).ToArray();
    204                 Context.ReplaceAtPopulation(replacement.Last().Index, Context.ToScope(pi_prime, fit));
     201            // NOTE: In the original paper it is not described that new best solutions are accepted regardless of difference
     202            // in this implementation a new best solution is always accepted into the elite set
     203            if (newBest || similarities.Max() <= 1.0 - (MinimumDifference / (double)pi_prime.Assignment.Length)) { // cond. 2 of line 13 in Algorithm 1
     204              var replacement = Context.Population.Select((v, i) => new { Scope = v, Index = i })
     205                                          .Where(x => x.Scope.Fitness >= fitness) // cond. 1 of line 13 in Algorithm 1
     206                                          .OrderByDescending(x => similarities[x.Index]) // line 14 in Algorithm 1
     207                                          .FirstOrDefault();
     208              if (replacement != null) {
     209                Context.ReplaceAtPopulation(replacement.Index, Context.ToScope(pi_prime, fitness)); // line 14 in Algorithm 1
    205210              }
    206211            }
    207           } else if (IsSufficientlyDifferent(pi_prime.Assignment)) { // line 17 in Algorithm 1
     212            // NOTE: In the original paper it is not described that new best solutions are accepted regardless of difference
     213            // in this implementation a new best solution is always accepted into the elite set
     214          } else if (newBest || IsSufficientlyDifferent(pi_prime.Assignment)) { // line 17 in Algorithm 1
    208215            Context.AddToPopulation(Context.ToScope(pi_prime, Problem.ProblemInstance.ToSingleObjective(pi_prime.Evaluation))); // line 18 in Algorithm 1
    209216          }
Note: See TracChangeset for help on using the changeset viewer.