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/MemPRAlgorithm.cs

    r14454 r14456  
    231231          Analyze(token);
    232232          token.ThrowIfCancellationRequested();
     233          if (Terminate()) return;
    233234        }
    234235        Context.HcSteps /= 2;
     
    314315        Results.Add(new Result("Iterations", new IntValue(Context.Iterations)));
    315316      else ((IntValue)res.Value).Value = Context.Iterations;
     317      if (!Results.TryGetValue("HcSteps", out res))
     318        Results.Add(new Result("HcSteps", new IntValue(Context.HcSteps)));
     319      else ((IntValue)res.Value).Value = Context.HcSteps;
    316320      if (!Results.TryGetValue("ByBreeding", out res))
    317321        Results.Add(new Result("ByBreeding", new IntValue(Context.ByBreeding)));
     
    491495      Context.HillclimbingStat.Add(Tuple.Create(before, after));
    492496      Context.IncrementEvaluatedSolutions(lscontext.EvaluatedSolutions);
    493       return lscontext.Iterations;
     497      return lscontext.EvaluatedSolutions;
    494498    }
    495499
     
    501505      var before = scope.Fitness;
    502506      var newScope = (ISingleObjectiveSolutionScope<TSolution>)scope.Clone();
    503       TabuWalk(newScope, steps, token, subspace);
     507      var newSteps = TabuWalk(newScope, steps, token, subspace);
    504508      Context.TabuwalkingStat.Add(Tuple.Create(before, newScope.Fitness));
     509      //Context.HcSteps = (int)Math.Ceiling(Context.HcSteps * (1.0 + Context.TabuwalkingStat.Count) / (2.0 + Context.TabuwalkingStat.Count) + newSteps / (2.0 + Context.TabuwalkingStat.Count));
    505510      if (IsBetter(newScope, scope) || (newScope.Fitness == scope.Fitness && Dist(newScope, scope) > 0))
    506511        scope.Adopt(newScope);
    507512    }
    508     protected abstract void TabuWalk(ISingleObjectiveSolutionScope<TSolution> scope, int steps, CancellationToken token, ISolutionSubspace<TSolution> subspace = null);
     513    protected abstract int TabuWalk(ISingleObjectiveSolutionScope<TSolution> scope, int maxEvals, CancellationToken token, ISolutionSubspace<TSolution> subspace = null);
    509514    protected virtual void TabuClimb(ISingleObjectiveSolutionScope<TSolution> scope, int steps, CancellationToken token, ISolutionSubspace<TSolution> subspace = null) {
    510515      if (double.IsNaN(scope.Fitness)) {
     
    514519      var before = scope.Fitness;
    515520      var newScope = (ISingleObjectiveSolutionScope<TSolution>)scope.Clone();
    516       TabuWalk(newScope, steps, token, subspace);
     521      var newSteps = TabuWalk(newScope, steps, token, subspace);
    517522      Context.TabuwalkingStat.Add(Tuple.Create(before, newScope.Fitness));
     523      //Context.HcSteps = (int)Math.Ceiling(Context.HcSteps * (1.0 + Context.TabuwalkingStat.Count) / (2.0 + Context.TabuwalkingStat.Count) + newSteps / (2.0 + Context.TabuwalkingStat.Count));
    518524      if (IsBetter(newScope, scope) || (newScope.Fitness == scope.Fitness && Dist(newScope, scope) > 0))
    519525        scope.Adopt(newScope);
     
    557563        || Context.Population.Any(p => IsBetter(offspring, p))) return offspring;
    558564
    559       if (IsBetter(offspring.Fitness, Context.BestQuality))
    560         HillClimb(offspring, token); // perform hillclimb in full solution space
    561       else if (HillclimbingSuited(offspring))
     565      if (HillclimbingSuited(offspring))
    562566        HillClimb(offspring, token, subspace); // perform hillclimb in the solution sub-space
    563567      return offspring;
     
    589593      if (dist1 > 0 && dist2 > 0) {
    590594        var subspace = CalculateSubspace(new[] { a.Solution, b.Solution }, inverse: true);
    591         if (IsBetter(child.Fitness, Context.BestQuality))
    592           HillClimb(child, token); // perform hillclimb in full solution space
    593         else if (HillclimbingSuited(child)) {
     595        if (HillclimbingSuited(child)) {
    594596          HillClimb(child, token, subspace); // perform hillclimb in solution sub-space
    595597        }
Note: See TracChangeset for help on using the changeset viewer.