Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
01/13/17 18:18:37 (7 years ago)
Author:
abeham
Message:

#2701:

  • Tagged unbiased models with property
  • Changed default configuration
  • Added solution distance to breeding, relinking and delinking performance models
  • Changed sampling model to base prediction on average distance in genotype space
  • Changed target for hillclimber and relinking to relative (quality improvement)
  • changed breeding to count cache hits per crossover
Location:
branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3
Files:
11 edited

Legend:

Unmodified
Added
Removed
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Binary/BinaryMemPR.cs

    r14557 r14563  
    4545      foreach (var trainer in ApplicationManager.Manager.GetInstances<ISolutionModelTrainer<BinaryMemPRPopulationContext>>())
    4646        SolutionModelTrainerParameter.ValidValues.Add(trainer);
    47      
     47
     48      if (SolutionModelTrainerParameter.ValidValues.Count > 0) {
     49        var unbiased = SolutionModelTrainerParameter.ValidValues.FirstOrDefault(x => !x.Bias);
     50        if (unbiased != null) SolutionModelTrainerParameter.Value = unbiased;
     51      }
     52
    4853      foreach (var localSearch in ApplicationManager.Manager.GetInstances<ILocalSearch<BinaryMemPRSolutionContext>>()) {
    4954        LocalSearchParameter.ValidValues.Add(localSearch);
     
    156161      cache.Add(p2.Solution);
    157162
    158       var cacheHits = 0;
     163      var cacheHits = new Dictionary<int, int>() { { 0, 0 }, { 1, 0 }, { 2, 0 } };
    159164      ISingleObjectiveSolutionScope<BinaryVector> offspring = null;
     165     
    160166      while (evaluations < N) {
    161167        BinaryVector c = null;
    162         var xochoice = Context.Random.Next(3);
     168        var xochoice = cacheHits.SampleRandom(Context.Random).Key;
    163169        switch (xochoice) {
    164170          case 0: c = NPointCrossover.Apply(Context.Random, p1.Solution, p2.Solution, new IntValue(1)); break;
     
    167173        }
    168174        if (cache.Contains(c)) {
    169           cacheHits++;
    170           if (cacheHits > 50) break;
     175          cacheHits[xochoice]++;
     176          if (cacheHits[xochoice] > 10) {
     177            cacheHits.Remove(xochoice);
     178            if (cacheHits.Count == 0) break;
     179          }
    171180          continue;
    172181        }
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Binary/SolutionModel/Univariate/BiasedModelTrainer.cs

    r14552 r14563  
    3636    where TContext : IPopulationBasedHeuristicAlgorithmContext<ISingleObjectiveHeuristicOptimizationProblem, BinaryVector>, ISolutionModelContext<BinaryVector> {
    3737   
     38    public bool Bias { get { return true; } }
     39
    3840    [Storable]
    3941    private IValueParameter<EnumValue<ModelBiasOptions>> modelBiasParameter;
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Binary/SolutionModel/Univariate/UnbiasedModelTrainer.cs

    r14552 r14563  
    3333  public class UniasedModelTrainer<TContext> : NamedItem, ISolutionModelTrainer<TContext>
    3434    where TContext : IPopulationBasedHeuristicAlgorithmContext<ISingleObjectiveHeuristicOptimizationProblem, BinaryVector>, ISolutionModelContext<BinaryVector> {
    35    
     35
     36    public bool Bias { get { return false; } }
     37
    3638    [StorableConstructor]
    3739    protected UniasedModelTrainer(bool deserializing) : base(deserializing) { }
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Interfaces/Interfaces.cs

    r14552 r14563  
    5050   
    5151  public interface ISolutionModelTrainer<TContext> : IItem {
     52    bool Bias { get; }
    5253    void TrainModel(TContext context);
    5354  }
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/LinearLinkage/LinearLinkageMemPR.cs

    r14556 r14563  
    3232using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
    3333using HeuristicLab.PluginInfrastructure;
     34using HeuristicLab.Random;
    3435
    3536namespace HeuristicLab.Algorithms.MemPR.Grouping {
     
    4445      foreach (var trainer in ApplicationManager.Manager.GetInstances<ISolutionModelTrainer<LinearLinkageMemPRPopulationContext>>())
    4546        SolutionModelTrainerParameter.ValidValues.Add(trainer);
    46      
     47
     48      if (SolutionModelTrainerParameter.ValidValues.Count > 0) {
     49        var unbiased = SolutionModelTrainerParameter.ValidValues.FirstOrDefault(x => !x.Bias);
     50        if (unbiased != null) SolutionModelTrainerParameter.Value = unbiased;
     51      }
     52
    4753      foreach (var localSearch in ApplicationManager.Manager.GetInstances<ILocalSearch<LinearLinkageMemPRSolutionContext>>()) {
    4854        LocalSearchParameter.ValidValues.Add(localSearch);
     
    245251      cache.Add(p2.Solution);
    246252
    247       var cachehits = 0;
     253      var cacheHits = new Dictionary<int, int>() { { 0, 0 }, { 1, 0 } };
    248254      var evaluations = 0;
    249255      var probe = Context.ToScope((LinearLinkage)p1.Solution.Clone());
     
    251257      while (evaluations < p1.Solution.Length) {
    252258        LinearLinkage c = null;
    253         if (Context.Random.NextDouble() < 0.8)
    254           c = GroupCrossover.Apply(Context.Random, p1.Solution, p2.Solution);
    255         else c = SinglePointCrossover.Apply(Context.Random, p1.Solution, p2.Solution);
    256        
     259        var xochoice = cacheHits.SampleRandom(Context.Random).Key;
     260        switch (xochoice) {
     261          case 0: c = GroupCrossover.Apply(Context.Random, p1.Solution, p2.Solution); break;
     262          case 1: c = SinglePointCrossover.Apply(Context.Random, p1.Solution, p2.Solution); break;
     263        }
    257264        if (cache.Contains(c)) {
    258           cachehits++;
    259           if (cachehits > 10) break;
     265          cacheHits[xochoice]++;
     266          if (cacheHits[xochoice] > 10) {
     267            cacheHits.Remove(xochoice);
     268            if (cacheHits.Count == 0) break;
     269          }
    260270          continue;
    261271        }
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/LinearLinkage/SolutionModel/Univariate/UnbiasedModelTrainer.cs

    r14552 r14563  
    3333  public class UniasedModelTrainer<TContext> : NamedItem, ISolutionModelTrainer<TContext>
    3434    where TContext : IPopulationBasedHeuristicAlgorithmContext<ISingleObjectiveHeuristicOptimizationProblem, LinearLinkage>, ISolutionModelContext<LinearLinkage> {
    35    
     35
     36    public bool Bias { get { return false; } }
     37
    3638    [StorableConstructor]
    3739    protected UniasedModelTrainer(bool deserializing) : base(deserializing) { }
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/MemPRAlgorithm.cs

    r14562 r14563  
    138138    [Storable]
    139139    private BestAverageWorstQualityAnalyzer qualityAnalyzer;
     140    [Storable]
     141    private QualityPerClockAnalyzer qualityPerClockAnalyzer;
     142    [Storable]
     143    private QualityPerEvaluationsAnalyzer qualityPerEvaluationsAnalyzer;
    140144
    141145    [StorableConstructor]
     
    144148      context = cloner.Clone(original.context);
    145149      qualityAnalyzer = cloner.Clone(original.qualityAnalyzer);
     150      qualityPerClockAnalyzer = cloner.Clone(original.qualityPerClockAnalyzer);
     151      qualityPerEvaluationsAnalyzer = cloner.Clone(original.qualityPerEvaluationsAnalyzer);
     152
    146153      RegisterEventHandlers();
    147154    }
     
    150157      Parameters.Add(new FixedValueParameter<IntValue>("MaximumPopulationSize", "The maximum size of the population that is evolved.", new IntValue(20)));
    151158      Parameters.Add(new OptionalValueParameter<IntValue>("MaximumEvaluations", "The maximum number of solution evaluations."));
    152       Parameters.Add(new OptionalValueParameter<TimeSpanValue>("MaximumExecutionTime", "The maximum runtime.", new TimeSpanValue(TimeSpan.FromMinutes(1))));
     159      Parameters.Add(new OptionalValueParameter<TimeSpanValue>("MaximumExecutionTime", "The maximum runtime.", new TimeSpanValue(TimeSpan.FromMinutes(10))));
    153160      Parameters.Add(new OptionalValueParameter<DoubleValue>("TargetQuality", "The target quality at which the algorithm terminates."));
    154161      Parameters.Add(new FixedValueParameter<BoolValue>("SetSeedRandomly", "Whether each run of the algorithm should be conducted with a new random seed.", new BoolValue(true)));
     
    158165
    159166      qualityAnalyzer = new BestAverageWorstQualityAnalyzer();
     167      qualityPerClockAnalyzer = new QualityPerClockAnalyzer();
     168      qualityPerEvaluationsAnalyzer = new QualityPerEvaluationsAnalyzer();
     169
    160170      RegisterEventHandlers();
    161171    }
     
    193203            foreach (var param in analyzer.Parameters.OfType<IScopeTreeLookupParameter>())
    194204              param.Depth = 1;
    195             multiAnalyzer.Operators.Add(analyzer, analyzer.EnabledByDefault);
     205            multiAnalyzer.Operators.Add(analyzer, analyzer.EnabledByDefault || analyzer is ISimilarityBasedOperator);
    196206          }
    197207        }
    198208        multiAnalyzer.Operators.Add(qualityAnalyzer, qualityAnalyzer.EnabledByDefault);
     209        multiAnalyzer.Operators.Add(qualityPerClockAnalyzer, true);
     210        multiAnalyzer.Operators.Add(qualityPerEvaluationsAnalyzer, true);
    199211      }
    200212    }
     
    300312
    301313      if (!replaced) {
    302         offspring = (ISingleObjectiveSolutionScope<TSolution>)Context.Population.SampleRandom(Context.Random).Clone();
    303         var before = offspring.Fitness;
     314        var before = Context.Population.SampleRandom(Context.Random);
     315        offspring = (ISingleObjectiveSolutionScope<TSolution>)before.Clone();
    304316        AdaptiveWalk(offspring, Context.LocalSearchEvaluations * 2, token);
    305         Context.AdaptivewalkingStat.Add(Tuple.Create(before, offspring.Fitness));
    306         if (Context.AdaptivewalkingStat.Count % 10 == 0) Context.RelearnAdaptiveWalkPerformanceModel();
     317        if (!Eq(before, offspring))
     318          Context.AddAdaptivewalkingResult(before, offspring);
    307319        if (Replace(offspring, token)) {
    308320          Context.ByAdaptivewalking++;
     
    345357
    346358      var sp = new ScatterPlot("Breeding Correlation", "");
    347       sp.Rows.Add(new ScatterPlotDataRow("Parent1 vs Offspring", "", Context.BreedingStat.Select(x => new Point2D<double>(x.Item1, x.Item3))) { VisualProperties = { PointSize = 6 }});
    348       sp.Rows.Add(new ScatterPlotDataRow("Parent2 vs Offspring", "", Context.BreedingStat.Select(x => new Point2D<double>(x.Item2, x.Item3))) { VisualProperties = { PointSize = 6 } });
     359      sp.Rows.Add(new ScatterPlotDataRow("Parent1 vs Offspring", "", Context.BreedingStat.Select(x => new Point2D<double>(x.Item1, x.Item4))) { VisualProperties = { PointSize = 6 }});
     360      sp.Rows.Add(new ScatterPlotDataRow("Parent2 vs Offspring", "", Context.BreedingStat.Select(x => new Point2D<double>(x.Item2, x.Item4))) { VisualProperties = { PointSize = 6 } });
     361      sp.Rows.Add(new ScatterPlotDataRow("Parent Distance vs Offspring", "", Context.BreedingStat.Select(x => new Point2D<double>(x.Item3, x.Item4))) { VisualProperties = { PointSize = 6 } });
    349362      if (!Results.TryGetValue("BreedingStat", out res)) {
    350363        Results.Add(new Result("BreedingStat", sp));
     
    352365
    353366      sp = new ScatterPlot("Relinking Correlation", "");
    354       sp.Rows.Add(new ScatterPlotDataRow("A vs Relink", "", Context.RelinkingStat.Select(x => new Point2D<double>(x.Item1, x.Item3))) { VisualProperties = { PointSize = 6 } });
    355       sp.Rows.Add(new ScatterPlotDataRow("B vs Relink", "", Context.RelinkingStat.Select(x => new Point2D<double>(x.Item2, x.Item3))) { VisualProperties = { PointSize = 6 } });
     367      sp.Rows.Add(new ScatterPlotDataRow("A vs Relink", "", Context.RelinkingStat.Select(x => new Point2D<double>(x.Item1, x.Item4))) { VisualProperties = { PointSize = 6 } });
     368      sp.Rows.Add(new ScatterPlotDataRow("B vs Relink", "", Context.RelinkingStat.Select(x => new Point2D<double>(x.Item2, x.Item4))) { VisualProperties = { PointSize = 6 } });
     369      sp.Rows.Add(new ScatterPlotDataRow("d(A,B) vs Offspring", "", Context.RelinkingStat.Select(x => new Point2D<double>(x.Item3, x.Item4))) { VisualProperties = { PointSize = 6 } });
    356370      if (!Results.TryGetValue("RelinkingStat", out res)) {
    357371        Results.Add(new Result("RelinkingStat", sp));
     
    359373
    360374      sp = new ScatterPlot("Delinking Correlation", "");
    361       sp.Rows.Add(new ScatterPlotDataRow("A vs Delink", "", Context.DelinkingStat.Select(x => new Point2D<double>(x.Item1, x.Item3))) { VisualProperties = { PointSize = 6 } });
    362       sp.Rows.Add(new ScatterPlotDataRow("B vs Delink", "", Context.DelinkingStat.Select(x => new Point2D<double>(x.Item2, x.Item3))) { VisualProperties = { PointSize = 6 } });
     375      sp.Rows.Add(new ScatterPlotDataRow("A vs Delink", "", Context.DelinkingStat.Select(x => new Point2D<double>(x.Item1, x.Item4))) { VisualProperties = { PointSize = 6 } });
     376      sp.Rows.Add(new ScatterPlotDataRow("B vs Delink", "", Context.DelinkingStat.Select(x => new Point2D<double>(x.Item2, x.Item4))) { VisualProperties = { PointSize = 6 } });
     377      sp.Rows.Add(new ScatterPlotDataRow("d(A,B) vs Offspring", "", Context.DelinkingStat.Select(x => new Point2D<double>(x.Item3, x.Item4))) { VisualProperties = { PointSize = 6 } });
    363378      if (!Results.TryGetValue("DelinkingStat", out res)) {
    364379        Results.Add(new Result("DelinkingStat", sp));
     
    372387
    373388      sp = new ScatterPlot("Hillclimbing Correlation", "");
    374       sp.Rows.Add(new ScatterPlotDataRow("Start vs End", "", Context.HillclimbingStat.Select(x => new Point2D<double>(x.Item1, x.Item2))) { VisualProperties = { PointSize = 6 } });
     389      sp.Rows.Add(new ScatterPlotDataRow("Start vs Improvement", "", Context.HillclimbingStat.Select(x => new Point2D<double>(x.Item1, x.Item2))) { VisualProperties = { PointSize = 6 } });
    375390      if (!Results.TryGetValue("HillclimbingStat", out res)) {
    376391        Results.Add(new Result("HillclimbingStat", sp));
     
    535550        Context.IncrementEvaluatedSolutions(1);
    536551      }
    537       var before = scope.Fitness;
     552      var before = (ISingleObjectiveSolutionScope<TSolution>)scope.Clone();
    538553      var lscontext = Context.CreateSingleSolutionContext(scope);
    539554      LocalSearchParameter.Value.Optimize(lscontext);
    540       var after = scope.Fitness;
    541       Context.HillclimbingStat.Add(Tuple.Create(before, after));
    542       if (Context.HillclimbingStat.Count % 10 == 0) Context.RelearnHillclimbingPerformanceModel();
     555      Context.AddHillclimbingResult(before, scope);
    543556      Context.IncrementEvaluatedSolutions(lscontext.EvaluatedSolutions);
    544557      return lscontext.EvaluatedSolutions;
     
    550563        Context.IncrementEvaluatedSolutions(1);
    551564      }
    552       var before = scope.Fitness;
    553565      var newScope = (ISingleObjectiveSolutionScope<TSolution>)scope.Clone();
    554566      AdaptiveWalk(newScope, maxEvals, token, subspace);
    555       Context.AdaptivewalkingStat.Add(Tuple.Create(before, newScope.Fitness));
    556       if (Context.AdaptivewalkingStat.Count % 10 == 0) Context.RelearnAdaptiveWalkPerformanceModel();
    557       if (Context.IsBetter(newScope, scope))
     567     
     568      if (Context.IsBetter(newScope, scope)) {
     569        Context.AddAdaptivewalkingResult(scope, newScope);
    558570        scope.Adopt(newScope);
     571      } else if (!Eq(newScope, scope))
     572        Context.AddAdaptivewalkingResult(scope, newScope);
    559573    }
    560574    protected abstract void AdaptiveWalk(ISingleObjectiveSolutionScope<TSolution> scope, int maxEvals, CancellationToken token, ISolutionSubspace<TSolution> subspace = null);
     
    580594      }
    581595
    582       if (Context.BreedingSuited(p1, p2)) {
    583         var offspring = Breed(p1, p2, token);
    584 
    585         if (double.IsNaN(offspring.Fitness)) {
    586           Context.Evaluate(offspring, token);
    587           Context.IncrementEvaluatedSolutions(1);
    588         }
    589 
    590         // new best solutions are improved using hill climbing in full solution space
    591         if (Context.Population.All(p => Context.IsBetter(offspring, p)))
    592           HillClimb(offspring, token);
    593         else if (!Eq(offspring, p1) && !Eq(offspring, p2) && Context.HillclimbingSuited(offspring.Fitness))
    594           HillClimb(offspring, token, CalculateSubspace(new[] { p1.Solution, p2.Solution }, inverse: false));
    595 
    596         Context.AddBreedingResult(p1, p2, offspring);
    597         if (Context.BreedingStat.Count % 10 == 0) Context.RelearnBreedingPerformanceModel();
    598         return offspring;
    599       }
    600       return null;
     596      if (!Context.BreedingSuited(p1, p2, Dist(p1, p2))) return null;
     597
     598      var offspring = Breed(p1, p2, token);
     599
     600      if (double.IsNaN(offspring.Fitness)) {
     601        Context.Evaluate(offspring, token);
     602        Context.IncrementEvaluatedSolutions(1);
     603      }
     604
     605      Context.AddBreedingResult(p1, p2, Dist(p1, p2), offspring);
     606
     607      // new best solutions are improved using hill climbing in full solution space
     608      if (Context.Population.All(p => Context.IsBetter(offspring, p)))
     609        HillClimb(offspring, token);
     610      else if (!Eq(offspring, p1) && !Eq(offspring, p2) && Context.HillclimbingSuited(offspring.Fitness))
     611        HillClimb(offspring, token, CalculateSubspace(new[] { p1.Solution, p2.Solution }, inverse: false));
     612
     613      return offspring;
    601614    }
    602615
     
    613626      var p2 = Context.AtPopulation(i2);
    614627
    615       if (!Context.RelinkSuited(p1, p2)) return null;
     628      if (!Context.RelinkSuited(p1, p2, Dist(p1, p2))) return null;
    616629
    617630      var link = PerformRelinking(p1, p2, token, delink: false);
    618       if (double.IsNaN(link.Fitness)) {
    619         Context.Evaluate(link, token);
    620         Context.IncrementEvaluatedSolutions(1);
    621       }
     631
    622632      // new best solutions are improved using hill climbing in full solution space
    623633      if (Context.Population.All(p => Context.IsBetter(link, p)))
     
    637647      var p2 = Context.AtPopulation(i2);
    638648     
    639       if (!Context.DelinkSuited(p1, p2)) return null;
     649      if (!Context.DelinkSuited(p1, p2, Dist(p1, p2))) return null;
    640650
    641651      var link = PerformRelinking(p1, p2, token, delink: true);
    642       if (double.IsNaN(link.Fitness)) {
    643         Context.Evaluate(link, token);
    644         Context.IncrementEvaluatedSolutions(1);
    645       }
     652
    646653      // new best solutions are improved using hill climbing in full solution space
    647654      if (Context.Population.All(p => Context.IsBetter(link, p)))
    648655        HillClimb(link, token);
    649       // intentionally not making hill climbing after delinking in sub-space
     656      // intentionally not making hill climbing otherwise after delinking in sub-space
    650657      return link;
    651658    }
     
    659666      }
    660667
    661       // new best solutions are improved using hill climbing
    662       if (Context.Population.All(p => Context.IsBetter(relink, p)))
    663         HillClimb(relink, token);
    664 
    665668      if (delink) {
    666         Context.AddDelinkingResult(a, b, relink);
    667         if (Context.DelinkingStat.Count % 10 == 0) Context.RelearnDelinkingPerformanceModel();
     669        Context.AddDelinkingResult(a, b, Dist(a, b), relink);
    668670      } else {
    669         Context.AddRelinkingResult(a, b, relink);
    670         if (context.RelinkingStat.Count % 10 == 0) Context.RelearnRelinkingPerformanceModel();
    671       }
     671        Context.AddRelinkingResult(a, b, Dist(a, b), relink);
     672      }
     673
    672674      return relink;
    673675    }
     
    682684        ISingleObjectiveSolutionScope<TSolution> bestSample = null;
    683685        var tries = 1;
     686        var avgDist = (from a in Context.Population.Shuffle(Context.Random)
     687                       from b in Context.Population.Shuffle(Context.Random)
     688                       select Dist(a, b)).Average();
    684689        for (; tries < 100; tries++) {
    685690          var sample = Context.ToScope(Context.Model.Sample());
     
    689694            if (Context.Population.Any(x => !Context.IsBetter(x, bestSample))) break;
    690695          }
    691           if (!Context.SamplingSuited()) break;
     696          if (!Context.SamplingSuited(avgDist)) break;
    692697        }
    693698        Context.IncrementEvaluatedSolutions(tries);
    694         Context.AddSamplingResult(bestSample);
    695         if (Context.SamplingStat.Count % 10 == 0) Context.RelearnSamplingPerformanceModel();
     699        Context.AddSamplingResult(bestSample, avgDist);
    696700        return bestSample;
    697701      }
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/MemPRContext.cs

    r14552 r14563  
    197197    }
    198198    [Storable]
    199     private List<Tuple<double, double, double>> breedingStat;
    200     public List<Tuple<double, double, double>> BreedingStat {
     199    private List<Tuple<double, double, double, double>> breedingStat;
     200    public IEnumerable<Tuple<double, double, double, double>> BreedingStat {
    201201      get { return breedingStat; }
    202202    }
     
    207207    }
    208208    [Storable]
    209     private List<Tuple<double, double, double>> relinkingStat;
    210     public List<Tuple<double, double, double>> RelinkingStat {
     209    private List<Tuple<double, double, double, double>> relinkingStat;
     210    public IEnumerable<Tuple<double, double, double, double>> RelinkingStat {
    211211      get { return relinkingStat; }
    212212    }
     
    217217    }
    218218    [Storable]
    219     private List<Tuple<double, double, double>> delinkingStat;
    220     public List<Tuple<double, double, double>> DelinkingStat {
     219    private List<Tuple<double, double, double, double>> delinkingStat;
     220    public IEnumerable<Tuple<double, double, double, double>> DelinkingStat {
    221221      get { return delinkingStat; }
    222222    }
     
    228228    [Storable]
    229229    private List<Tuple<double, double>> samplingStat;
    230     public List<Tuple<double, double>> SamplingStat {
     230    public IEnumerable<Tuple<double, double>> SamplingStat {
    231231      get { return samplingStat; }
    232232    }
     
    238238    [Storable]
    239239    private List<Tuple<double, double>> hillclimbingStat;
    240     public List<Tuple<double, double>> HillclimbingStat {
     240    public IEnumerable<Tuple<double, double>> HillclimbingStat {
    241241      get { return hillclimbingStat; }
    242242    }
     
    248248    [Storable]
    249249    private List<Tuple<double, double>> adaptivewalkingStat;
    250     public List<Tuple<double, double>> AdaptivewalkingStat {
     250    public IEnumerable<Tuple<double, double>> AdaptivewalkingStat {
    251251      get { return adaptivewalkingStat; }
    252252    }
     
    276276      random = cloner.Clone(original.random);
    277277      breedingPerformanceModel = cloner.Clone(original.breedingPerformanceModel);
    278       breedingStat = original.breedingStat.Select(x => Tuple.Create(x.Item1, x.Item2, x.Item3)).ToList();
     278      breedingStat = original.breedingStat.Select(x => Tuple.Create(x.Item1, x.Item2, x.Item3, x.Item4)).ToList();
    279279      relinkingPerformanceModel = cloner.Clone(original.relinkingPerformanceModel);
    280       relinkingStat = original.relinkingStat.Select(x => Tuple.Create(x.Item1, x.Item2, x.Item3)).ToList();
     280      relinkingStat = original.relinkingStat.Select(x => Tuple.Create(x.Item1, x.Item2, x.Item3, x.Item4)).ToList();
    281281      delinkingPerformanceModel = cloner.Clone(original.delinkingPerformanceModel);
    282       delinkingStat = original.delinkingStat.Select(x => Tuple.Create(x.Item1, x.Item2, x.Item3)).ToList();
     282      delinkingStat = original.delinkingStat.Select(x => Tuple.Create(x.Item1, x.Item2, x.Item3, x.Item4)).ToList();
    283283      samplingPerformanceModel = cloner.Clone(original.samplingPerformanceModel);
    284284      samplingStat = original.samplingStat.Select(x => Tuple.Create(x.Item1, x.Item2)).ToList();
     
    310310      Parameters.Add(random = new ValueParameter<IRandom>("Random", new MersenneTwister()));
    311311
    312       breedingStat = new List<Tuple<double, double, double>>();
    313       relinkingStat = new List<Tuple<double, double, double>>();
    314       delinkingStat = new List<Tuple<double, double, double>>();
     312      breedingStat = new List<Tuple<double, double, double, double>>();
     313      relinkingStat = new List<Tuple<double, double, double, double>>();
     314      delinkingStat = new List<Tuple<double, double, double, double>>();
    315315      samplingStat = new List<Tuple<double, double>>();
    316316      hillclimbingStat = new List<Tuple<double, double>>();
     
    344344
    345345    public void RelearnBreedingPerformanceModel() {
    346       breedingPerformanceModel = RunRegression(PrepareRegression(BreedingStat), breedingPerformanceModel).Model;
    347     }
    348     public bool BreedingSuited(ISingleObjectiveSolutionScope<TSolution> p1, ISingleObjectiveSolutionScope<TSolution> p2) {
     346      breedingPerformanceModel = RunRegression(PrepareRegression(ToListRow(breedingStat)), breedingPerformanceModel).Model;
     347    }
     348    public bool BreedingSuited(ISingleObjectiveSolutionScope<TSolution> p1, ISingleObjectiveSolutionScope<TSolution> p2, double dist) {
    349349      if (breedingPerformanceModel == null) return true;
    350350      double minI1 = double.MaxValue, minI2 = double.MaxValue, maxI1 = double.MinValue, maxI2 = double.MinValue;
     
    355355        if (d.Item2 > maxI2) maxI2 = d.Item2;
    356356      }
    357       if (IsBetter(p1, p2)) {
    358         if (p1.Fitness < minI1 || p1.Fitness > maxI1 || p2.Fitness < minI2 || p2.Fitness > maxI2)
    359           return true;
    360         return Random.NextDouble() < ProbabilityAccept3dModel(p1.Fitness, p2.Fitness, breedingPerformanceModel);
    361       }
    362       if (p1.Fitness < minI2 || p1.Fitness > maxI2 || p2.Fitness < minI1 || p2.Fitness > maxI1)
     357      if (p1.Fitness < minI1 || p1.Fitness > maxI1 || p2.Fitness < minI2 || p2.Fitness > maxI2)
    363358        return true;
    364       return Random.NextDouble() < ProbabilityAccept3dModel(p2.Fitness, p1.Fitness, breedingPerformanceModel);
     359     
     360      return Random.NextDouble() < ProbabilityAcceptAbsolutePerformanceModel(new List<double> { p1.Fitness, p2.Fitness, dist }, breedingPerformanceModel);
    365361    }
    366362
    367363    public void RelearnRelinkingPerformanceModel() {
    368       relinkingPerformanceModel = RunRegression(PrepareRegression(RelinkingStat), relinkingPerformanceModel).Model;
    369     }
    370     public bool RelinkSuited(ISingleObjectiveSolutionScope<TSolution> p1, ISingleObjectiveSolutionScope<TSolution> p2) {
     364      relinkingPerformanceModel = RunRegression(PrepareRegression(ToListRow(relinkingStat)), relinkingPerformanceModel).Model;
     365    }
     366    public bool RelinkSuited(ISingleObjectiveSolutionScope<TSolution> p1, ISingleObjectiveSolutionScope<TSolution> p2, double dist) {
    371367      if (relinkingPerformanceModel == null) return true;
    372368      double minI1 = double.MaxValue, minI2 = double.MaxValue, maxI1 = double.MinValue, maxI2 = double.MinValue;
     
    377373        if (d.Item2 > maxI2) maxI2 = d.Item2;
    378374      }
     375      if (p1.Fitness < minI1 || p1.Fitness > maxI1 || p2.Fitness < minI2 || p2.Fitness > maxI2)
     376        return true;
     377
    379378      if (IsBetter(p1, p2)) {
    380         if (p1.Fitness < minI1 || p1.Fitness > maxI1 || p2.Fitness < minI2 || p2.Fitness > maxI2)
    381           return true;
    382         return Random.NextDouble() < ProbabilityAccept3dModel(p1.Fitness, p2.Fitness, relinkingPerformanceModel);
    383       }
    384       if (p1.Fitness < minI2 || p1.Fitness > maxI2 || p2.Fitness < minI1 || p2.Fitness > maxI1)
    385         return true;
    386       return Random.NextDouble() < ProbabilityAccept3dModel(p2.Fitness, p1.Fitness, relinkingPerformanceModel);
     379        return Random.NextDouble() < ProbabilityAcceptRelativePerformanceModel(p1.Fitness, new List<double> { p1.Fitness, p2.Fitness, dist }, relinkingPerformanceModel);
     380      }
     381      return Random.NextDouble() < ProbabilityAcceptRelativePerformanceModel(p2.Fitness, new List<double> { p1.Fitness, p2.Fitness, dist }, relinkingPerformanceModel);
    387382    }
    388383
    389384    public void RelearnDelinkingPerformanceModel() {
    390       delinkingPerformanceModel = RunRegression(PrepareRegression(DelinkingStat), delinkingPerformanceModel).Model;
    391     }
    392     public bool DelinkSuited(ISingleObjectiveSolutionScope<TSolution> p1, ISingleObjectiveSolutionScope<TSolution> p2) {
     385      delinkingPerformanceModel = RunRegression(PrepareRegression(ToListRow(delinkingStat)), delinkingPerformanceModel).Model;
     386    }
     387    public bool DelinkSuited(ISingleObjectiveSolutionScope<TSolution> p1, ISingleObjectiveSolutionScope<TSolution> p2, double dist) {
    393388      if (delinkingPerformanceModel == null) return true;
    394389      double minI1 = double.MaxValue, minI2 = double.MaxValue, maxI1 = double.MinValue, maxI2 = double.MinValue;
     
    399394        if (d.Item2 > maxI2) maxI2 = d.Item2;
    400395      }
     396      if (p1.Fitness < minI1 || p1.Fitness > maxI1 || p2.Fitness < minI2 || p2.Fitness > maxI2)
     397        return true;
    401398      if (IsBetter(p1, p2)) {
    402         if (p1.Fitness < minI1 || p1.Fitness > maxI1 || p2.Fitness < minI2 || p2.Fitness > maxI2)
    403           return true;
    404         return Random.NextDouble() < ProbabilityAccept3dModel(p1.Fitness, p2.Fitness, delinkingPerformanceModel);
    405       }
    406       if (p1.Fitness < minI2 || p1.Fitness > maxI2 || p2.Fitness < minI1 || p2.Fitness > maxI1)
    407         return true;
    408       return Random.NextDouble() < ProbabilityAccept3dModel(p2.Fitness, p1.Fitness, delinkingPerformanceModel);
     399        return Random.NextDouble() < ProbabilityAcceptRelativePerformanceModel(p1.Fitness, new List<double> { p1.Fitness, p2.Fitness, dist }, delinkingPerformanceModel);
     400      }
     401      return Random.NextDouble() < ProbabilityAcceptRelativePerformanceModel(p2.Fitness, new List<double> { p1.Fitness, p2.Fitness, dist }, delinkingPerformanceModel);
    409402    }
    410403
    411404    public void RelearnSamplingPerformanceModel() {
    412       samplingPerformanceModel = RunRegression(PrepareRegression(SamplingStat), samplingPerformanceModel).Model;
    413     }
    414     public bool SamplingSuited() {
     405      samplingPerformanceModel = RunRegression(PrepareRegression(ToListRow(samplingStat)), samplingPerformanceModel).Model;
     406    }
     407    public bool SamplingSuited(double avgDist) {
    415408      if (samplingPerformanceModel == null) return true;
    416       return Random.NextDouble() < ProbabilityAccept2dModel(Population.Average(x => x.Fitness), samplingPerformanceModel);
     409      if (avgDist < samplingStat.Min(x => x.Item1) || avgDist > samplingStat.Max(x => x.Item1)) return true;
     410      return Random.NextDouble() < ProbabilityAcceptAbsolutePerformanceModel(new List<double> { avgDist }, samplingPerformanceModel);
    417411    }
    418412
    419413    public void RelearnHillclimbingPerformanceModel() {
    420       hillclimbingPerformanceModel = RunRegression(PrepareRegression(HillclimbingStat), hillclimbingPerformanceModel).Model;
     414      hillclimbingPerformanceModel = RunRegression(PrepareRegression(ToListRow(hillclimbingStat)), hillclimbingPerformanceModel).Model;
    421415    }
    422416    public bool HillclimbingSuited(ISingleObjectiveSolutionScope<TSolution> scope) {
    423       if (hillclimbingPerformanceModel == null) return true;
    424       if (scope.Fitness < HillclimbingStat.Min(x => x.Item1) || scope.Fitness > HillclimbingStat.Max(x => x.Item1))
    425         return true;
    426       return Random.NextDouble() < ProbabilityAccept2dModel(scope.Fitness, hillclimbingPerformanceModel);
     417      return HillclimbingSuited(scope.Fitness);
    427418    }
    428419    public bool HillclimbingSuited(double startingFitness) {
     
    430421      if (startingFitness < HillclimbingStat.Min(x => x.Item1) || startingFitness > HillclimbingStat.Max(x => x.Item1))
    431422        return true;
    432       return Random.NextDouble() < ProbabilityAccept2dModel(startingFitness, hillclimbingPerformanceModel);
     423      return Random.NextDouble() < ProbabilityAcceptRelativePerformanceModel(startingFitness, new List<double> { startingFitness }, hillclimbingPerformanceModel);
    433424    }
    434425
    435426    public void RelearnAdaptiveWalkPerformanceModel() {
    436       adaptiveWalkPerformanceModel = RunRegression(PrepareRegression(AdaptivewalkingStat), adaptiveWalkPerformanceModel).Model;
     427      adaptiveWalkPerformanceModel = RunRegression(PrepareRegression(ToListRow(adaptivewalkingStat)), adaptiveWalkPerformanceModel).Model;
    437428    }
    438429    public bool AdaptivewalkingSuited(ISingleObjectiveSolutionScope<TSolution> scope) {
    439       if (adaptiveWalkPerformanceModel == null) return true;
    440       if (scope.Fitness < AdaptivewalkingStat.Min(x => x.Item1) || scope.Fitness > AdaptivewalkingStat.Max(x => x.Item1))
    441         return true;
    442       return Random.NextDouble() < ProbabilityAccept2dModel(scope.Fitness, adaptiveWalkPerformanceModel);
     430      return AdaptivewalkingSuited(scope.Fitness);
    443431    }
    444432    public bool AdaptivewalkingSuited(double startingFitness) {
     
    446434      if (startingFitness < AdaptivewalkingStat.Min(x => x.Item1) || startingFitness > AdaptivewalkingStat.Max(x => x.Item1))
    447435        return true;
    448       return Random.NextDouble() < ProbabilityAccept2dModel(startingFitness, adaptiveWalkPerformanceModel);
    449     }
    450 
    451     public IConfidenceRegressionSolution GetSolution(IConfidenceRegressionModel model, List<Tuple<double, double>> data) {
    452       return new ConfidenceRegressionSolution(model, PrepareRegression(data));
    453     }
    454     public IConfidenceRegressionSolution GetSolution(IConfidenceRegressionModel model, List<Tuple<double, double, double>> data) {
    455       return new ConfidenceRegressionSolution(model, PrepareRegression(data));
    456     }
    457 
    458     protected RegressionProblemData PrepareRegression(List<Tuple<double, double>> sample) {
    459       var inCol = new List<double>();
    460       var outCol = new List<double>();
     436      return Random.NextDouble() < ProbabilityAcceptAbsolutePerformanceModel(new List<double> { startingFitness }, adaptiveWalkPerformanceModel);
     437    }
     438
     439    public IConfidenceRegressionSolution GetSolution(IConfidenceRegressionModel model, IEnumerable<Tuple<double, double>> data) {
     440      return new ConfidenceRegressionSolution(model, PrepareRegression(ToListRow(data.ToList())));
     441    }
     442    public IConfidenceRegressionSolution GetSolution(IConfidenceRegressionModel model, IEnumerable<Tuple<double, double, double>> data) {
     443      return new ConfidenceRegressionSolution(model, PrepareRegression(ToListRow(data.ToList())));
     444    }
     445    public IConfidenceRegressionSolution GetSolution(IConfidenceRegressionModel model, IEnumerable<Tuple<double, double, double, double>> data) {
     446      return new ConfidenceRegressionSolution(model, PrepareRegression(ToListRow(data.ToList())));
     447    }
     448
     449    protected RegressionProblemData PrepareRegression(List<List<double>> sample) {
     450      var columns = sample.First().Select(y => new List<double>()).ToList();
    461451      foreach (var next in sample.Shuffle(Random)) {
    462         inCol.Add(next.Item1);
    463         outCol.Add(next.Item2);
    464       }
    465       var ds = new Dataset(new[] { "in", "out" }, new[] { inCol, outCol });
    466       var regPrb = new RegressionProblemData(ds, new[] { "in" }, "out") {
    467         TrainingPartition = { Start = 0, End = Math.Min(50, sample.Count) },
    468         TestPartition = { Start = Math.Min(50, sample.Count), End = sample.Count }
    469       };
    470       return regPrb;
    471     }
    472 
    473     protected RegressionProblemData PrepareRegression(List<Tuple<double, double, double>> sample) {
    474       var in1Col = new List<double>();
    475       var in2Col = new List<double>();
    476       var outCol = new List<double>();
    477       foreach (var next in sample.Shuffle(Random)) {
    478         in1Col.Add(next.Item1);
    479         in2Col.Add(next.Item2);
    480         outCol.Add(next.Item3);
    481       }
    482       var ds = new Dataset(new[] { "in1", "in2", "out" }, new[] { in1Col, in2Col, outCol });
    483       var regPrb = new RegressionProblemData(ds, new[] { "in1", "in2" }, "out") {
     452        for (var i = 0; i < next.Count; i++) {
     453          columns[i].Add(next[i]);
     454        }
     455      }
     456      var ds = new Dataset(columns.Select((v, i) => i < columns.Count - 1 ? "in" + i : "out").ToList(), columns);
     457      var regPrb = new RegressionProblemData(ds, Enumerable.Range(0, columns.Count - 1).Select(x => "in" + x), "out") {
    484458        TrainingPartition = { Start = 0, End = Math.Min(50, sample.Count) },
    485459        TestPartition = { Start = Math.Min(50, sample.Count), End = sample.Count }
     
    525499    }
    526500
    527     private double ProbabilityAccept2dModel(double a, IConfidenceRegressionModel model) {
    528       var ds = new Dataset(new[] { "in", "out" }, new[] { new List<double> { a }, new List<double> { double.NaN } });
     501    private double ProbabilityAcceptAbsolutePerformanceModel(List<double> inputs, IConfidenceRegressionModel model) {
     502      var inputVariables = inputs.Select((v, i) => "in" + i);
     503      var ds = new Dataset(inputVariables.Concat( new [] { "out" }), inputs.Select(x => new List<double> { x }).Concat(new [] { new List<double> { double.NaN } }));
    529504      var mean = model.GetEstimatedValues(ds, new[] { 0 }).Single();
    530505      var sdev = Math.Sqrt(model.GetEstimatedVariances(ds, new[] { 0 }).Single());
    531506
     507      // calculate the fitness goal
    532508      var goal = Maximization ? Population.Min(x => x.Fitness) : Population.Max(x => x.Fitness);
    533509      var z = (goal - mean) / sdev;
    534       return Maximization ? 1.0 - Phi(z) /* P(X >= z) */ : Phi(z); // P(X <= z)
    535     }
    536 
    537     private double ProbabilityAccept3dModel(double a, double b, IConfidenceRegressionModel model) {
    538       var ds = new Dataset(new[] { "in1", "in2", "out" }, new[] { new List<double> { a }, new List<double> { b }, new List<double> { double.NaN } });
     510      // return the probability of achieving or surpassing that goal
     511      var y = alglib.invnormaldistribution(z);
     512      return Maximization ? 1.0 - y /* P(X >= z) */ : y; // P(X <= z)
     513    }
     514
     515    private double ProbabilityAcceptRelativePerformanceModel(double basePerformance, List<double> inputs, IConfidenceRegressionModel model) {
     516      var inputVariables = inputs.Select((v, i) => "in" + i);
     517      var ds = new Dataset(inputVariables.Concat(new[] { "out" }), inputs.Select(x => new List<double> { x }).Concat(new[] { new List<double> { double.NaN } }));
    539518      var mean = model.GetEstimatedValues(ds, new[] { 0 }).Single();
    540519      var sdev = Math.Sqrt(model.GetEstimatedVariances(ds, new[] { 0 }).Single());
    541520
    542       var goal = Maximization ? Population.Min(x => x.Fitness) : Population.Max(x => x.Fitness);
     521      // calculate the improvement goal
     522      var goal = Maximization ? Population.Min(x => x.Fitness) - basePerformance : basePerformance - Population.Max(x => x.Fitness);
    543523      var z = (goal - mean) / sdev;
    544       return Maximization ? 1.0 - Phi(z) /* P(X >= z) */ : Phi(z); // P(X <= z)
     524      // return the probability of achieving or surpassing that goal
     525      return 1.0 - alglib.invnormaldistribution(z); /* P(X >= z) */
     526    }
     527
     528    private static List<List<double>> ToListRow(List<Tuple<double, double>> rows) {
     529      return rows.Select(x => new List<double> { x.Item1, x.Item2 }).ToList();
     530    }
     531    private static List<List<double>> ToListRow(List<Tuple<double, double, double>> rows) {
     532      return rows.Select(x => new List<double> { x.Item1, x.Item2, x.Item3 }).ToList();
     533    }
     534    private static List<List<double>> ToListRow(List<Tuple<double, double, double, double>> rows) {
     535      return rows.Select(x => new List<double> { x.Item1, x.Item2, x.Item3, x.Item4 }).ToList();
    545536    }
    546537
     
    556547    }
    557548
    558     public void AddBreedingResult(ISingleObjectiveSolutionScope<TSolution> a, ISingleObjectiveSolutionScope<TSolution> b, ISingleObjectiveSolutionScope<TSolution> child) {
     549    public void AddBreedingResult(ISingleObjectiveSolutionScope<TSolution> a, ISingleObjectiveSolutionScope<TSolution> b, double parentDist, ISingleObjectiveSolutionScope<TSolution> child) {
    559550      if (IsBetter(a, b))
    560         BreedingStat.Add(Tuple.Create(a.Fitness, b.Fitness, child.Fitness));
    561       else BreedingStat.Add(Tuple.Create(b.Fitness, a.Fitness, child.Fitness));
    562     }
    563 
    564     public void AddRelinkingResult(ISingleObjectiveSolutionScope<TSolution> a, ISingleObjectiveSolutionScope<TSolution> b, ISingleObjectiveSolutionScope<TSolution> child) {
     551        breedingStat.Add(Tuple.Create(a.Fitness, b.Fitness, parentDist, child.Fitness));
     552      else breedingStat.Add(Tuple.Create(b.Fitness, a.Fitness, parentDist, child.Fitness));
     553      if (breedingStat.Count % 10 == 0) RelearnBreedingPerformanceModel();
     554    }
     555
     556    public void AddRelinkingResult(ISingleObjectiveSolutionScope<TSolution> a, ISingleObjectiveSolutionScope<TSolution> b, double parentDist, ISingleObjectiveSolutionScope<TSolution> child) {
    565557      if (IsBetter(a, b))
    566         RelinkingStat.Add(Tuple.Create(a.Fitness, b.Fitness, child.Fitness));
    567       else RelinkingStat.Add(Tuple.Create(b.Fitness, a.Fitness, child.Fitness));
    568     }
    569 
    570     public void AddDelinkingResult(ISingleObjectiveSolutionScope<TSolution> a, ISingleObjectiveSolutionScope<TSolution> b, ISingleObjectiveSolutionScope<TSolution> child) {
     558        relinkingStat.Add(Tuple.Create(a.Fitness, b.Fitness, parentDist, Maximization ? child.Fitness - a.Fitness : a.Fitness - child.Fitness));
     559      else relinkingStat.Add(Tuple.Create(a.Fitness, b.Fitness, parentDist, Maximization ? child.Fitness - b.Fitness : b.Fitness - child.Fitness));
     560      if (relinkingStat.Count % 10 == 0) RelearnRelinkingPerformanceModel();
     561    }
     562
     563    public void AddDelinkingResult(ISingleObjectiveSolutionScope<TSolution> a, ISingleObjectiveSolutionScope<TSolution> b, double parentDist, ISingleObjectiveSolutionScope<TSolution> child) {
    571564      if (IsBetter(a, b))
    572         DelinkingStat.Add(Tuple.Create(a.Fitness, b.Fitness, child.Fitness));
    573       else DelinkingStat.Add(Tuple.Create(b.Fitness, a.Fitness, child.Fitness));
    574     }
    575 
    576     public void AddSamplingResult(ISingleObjectiveSolutionScope<TSolution> sample) {
    577       SamplingStat.Add(Tuple.Create(Population.Average(x => x.Fitness), sample.Fitness));
     565        delinkingStat.Add(Tuple.Create(a.Fitness, b.Fitness, parentDist, Maximization ? child.Fitness - a.Fitness : a.Fitness - child.Fitness));
     566      else delinkingStat.Add(Tuple.Create(a.Fitness, b.Fitness, parentDist, Maximization ? child.Fitness - b.Fitness : b.Fitness - child.Fitness));
     567      if (delinkingStat.Count % 10 == 0) RelearnDelinkingPerformanceModel();
     568    }
     569
     570    public void AddSamplingResult(ISingleObjectiveSolutionScope<TSolution> sample, double avgDist) {
     571      samplingStat.Add(Tuple.Create(avgDist, sample.Fitness));
     572      if (samplingStat.Count % 10 == 0) RelearnSamplingPerformanceModel();
    578573    }
    579574
    580575    public void AddHillclimbingResult(ISingleObjectiveSolutionScope<TSolution> input, ISingleObjectiveSolutionScope<TSolution> outcome) {
    581       HillclimbingStat.Add(Tuple.Create(input.Fitness, outcome.Fitness));
    582     }
    583 
    584     public void AddTabuwalkingResult(ISingleObjectiveSolutionScope<TSolution> input, ISingleObjectiveSolutionScope<TSolution> outcome) {
    585       AdaptivewalkingStat.Add(Tuple.Create(input.Fitness, outcome.Fitness));
     576      hillclimbingStat.Add(Tuple.Create(input.Fitness, Maximization ? outcome.Fitness - input.Fitness : input.Fitness - outcome.Fitness));
     577      if (hillclimbingStat.Count % 10 == 0) RelearnHillclimbingPerformanceModel();
     578    }
     579
     580    public void AddAdaptivewalkingResult(ISingleObjectiveSolutionScope<TSolution> input, ISingleObjectiveSolutionScope<TSolution> outcome) {
     581      adaptivewalkingStat.Add(Tuple.Create(input.Fitness, outcome.Fitness));
     582      if (adaptivewalkingStat.Count % 10 == 0) RelearnAdaptiveWalkPerformanceModel();
    586583    }
    587584
     
    609606    // license: "This code is in the public domain. Do whatever you want with it, no strings attached."
    610607    // added: 2016-11-19 21:46 CET
    611     protected static double Phi(double x) {
     608    /*protected static double Phi(double x) {
    612609      // constants
    613610      double a1 = 0.254829592;
     
    629626
    630627      return 0.5 * (1.0 + sign * y);
    631     }
     628    }*/
    632629    #endregion
    633630
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/PermutationMemPR.cs

    r14556 r14563  
    5252      foreach (var trainer in ApplicationManager.Manager.GetInstances<ISolutionModelTrainer<PermutationMemPRPopulationContext>>())
    5353        SolutionModelTrainerParameter.ValidValues.Add(trainer);
    54      
     54
     55      if (SolutionModelTrainerParameter.ValidValues.Count > 0) {
     56        var unbiased = SolutionModelTrainerParameter.ValidValues.FirstOrDefault(x => !x.Bias);
     57        if (unbiased != null) SolutionModelTrainerParameter.Value = unbiased;
     58      }
     59
    5560      foreach (var localSearch in ApplicationManager.Manager.GetInstances<ILocalSearch<PermutationMemPRSolutionContext>>()) {
    5661        LocalSearchParameter.ValidValues.Add(localSearch);
     
    290295        InversionMove bestOfTheRest = null;
    291296        var improved = false;
    292 
     297       
    293298        foreach (var opt in ExhaustiveInversionMoveGenerator.Generate(current).Shuffle(random)) {
    294299          var prev = opt.Index1 - 1;
     
    395400      cache.Add(p2.Solution);
    396401
    397       var cacheHits = 0;
     402      var cacheHits = new Dictionary<int, int>() { { 0, 0 }, { 1, 0 }, { 2, 0 } };
    398403      var evaluations = 0;
    399404      ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> offspring = null;
     
    401406      while (evaluations < p1.Solution.Length) {
    402407        Encodings.PermutationEncoding.Permutation c = null;
    403         var xochoice = Context.Random.Next(3);
     408        var xochoice = cacheHits.SampleRandom(Context.Random).Key;
    404409        switch (xochoice) {
    405410          case 0: c = CyclicCrossover2.Apply(Context.Random, p1.Solution, p2.Solution); break;
     
    408413        }
    409414        if (cache.Contains(c)) {
    410           cacheHits++;
    411           if (cacheHits > 10) break;
     415          cacheHits[xochoice]++;
     416          if (cacheHits[xochoice] > 10) {
     417            cacheHits.Remove(xochoice);
     418            if (cacheHits.Count == 0) break;
     419          }
    412420          continue;
    413421        }
     
    431439      cache.Add(p2.Solution);
    432440
    433       var cacheHits = 0;
     441      var cacheHits = new Dictionary<int, int>() { { 0, 0 }, { 1, 0 }, { 2, 0 } };
    434442      var evaluations = 0;
    435443      ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> offspring = null;
     
    437445      while (evaluations < p1.Solution.Length) {
    438446        Encodings.PermutationEncoding.Permutation c = null;
    439         var xochoice = Context.Random.Next(3);
     447        var xochoice = cacheHits.SampleRandom(Context.Random).Key;
    440448        switch (xochoice) {
    441449          case 0: c = OrderCrossover2.Apply(Context.Random, p1.Solution, p2.Solution); break;
     
    444452        }
    445453        if (cache.Contains(c)) {
    446           cacheHits++;
    447           if (cacheHits > 10) break;
     454          cacheHits[xochoice]++;
     455          if (cacheHits[xochoice] > 10) {
     456            cacheHits.Remove(xochoice);
     457            if (cacheHits.Count == 0) break;
     458          }
    448459          continue;
    449460        }
     
    467478      cache.Add(p2.Solution);
    468479
    469       var cacheHits = 0;
     480      var cacheHits = new Dictionary<int, int>() { { 0, 0 }, { 1, 0 }, { 2, 0 } };
    470481      var evaluations = 0;
    471482      ISingleObjectiveSolutionScope<Encodings.PermutationEncoding.Permutation> offspring = null;
     
    473484      while (evaluations <= p1.Solution.Length) {
    474485        Encodings.PermutationEncoding.Permutation c = null;
    475         var xochoice = Context.Random.Next(3);
     486        var xochoice = cacheHits.SampleRandom(Context.Random).Key;
    476487        switch (xochoice) {
    477488          case 0: c = OrderCrossover2.Apply(Context.Random, p1.Solution, p2.Solution); break;
     
    480491        }
    481492        if (cache.Contains(c)) {
    482           cacheHits++;
    483           if (cacheHits > 10) break;
     493          cacheHits[xochoice]++;
     494          if (cacheHits[xochoice] > 10) {
     495            cacheHits.Remove(xochoice);
     496            if (cacheHits.Count == 0) break;
     497          }
    484498          continue;
    485499        }
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/SolutionModel/Univariate/BiasedModelTrainer.cs

    r14552 r14563  
    2525using HeuristicLab.Core;
    2626using HeuristicLab.Data;
    27 using HeuristicLab.Encodings.PermutationEncoding;
    2827using HeuristicLab.Optimization;
    2928using HeuristicLab.Parameters;
     
    3635    where TContext : IPopulationBasedHeuristicAlgorithmContext<ISingleObjectiveHeuristicOptimizationProblem, Encodings.PermutationEncoding.Permutation>,
    3736    ISolutionModelContext<Encodings.PermutationEncoding.Permutation>, IEvaluationServiceContext<Encodings.PermutationEncoding.Permutation> {
     37
     38    public bool Bias { get { return true; } }
    3839
    3940    [Storable]
  • branches/MemPRAlgorithm/HeuristicLab.Algorithms.MemPR/3.3/Permutation/SolutionModel/Univariate/UnbiasedModelTrainer.cs

    r14552 r14563  
    2121
    2222using System.Linq;
    23 using HeuristicLab.Algorithms.MemPR.Binary.SolutionModel.Univariate;
    2423using HeuristicLab.Algorithms.MemPR.Interfaces;
    2524using HeuristicLab.Common;
    2625using HeuristicLab.Core;
    27 using HeuristicLab.Encodings.PermutationEncoding;
    2826using HeuristicLab.Optimization;
    2927using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     
    3533    where TContext : IPopulationBasedHeuristicAlgorithmContext<ISingleObjectiveHeuristicOptimizationProblem, Encodings.PermutationEncoding.Permutation>,
    3634    ISolutionModelContext<Encodings.PermutationEncoding.Permutation> {
    37    
     35
     36    public bool Bias { get { return false; } }
     37
    3838    [StorableConstructor]
    3939    protected UnbiasedModelTrainer(bool deserializing) : base(deserializing) { }
Note: See TracChangeset for help on using the changeset viewer.