Ignore:
Timestamp:
06/10/17 23:19:11 (5 years ago)
Author:
abeham
Message:

#2457: worked on code for eurocast paper

File:
1 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/ProblemInstanceIdentifier/InstanceExplorer.cs

    r14776 r15031  
    11using System;
    22using System.Linq;
    3 using System.Threading;
    43using HeuristicLab.Algorithms.MemPR.Permutation;
    54using HeuristicLab.Analysis.FitnessLandscape;
     
    76using HeuristicLab.Encodings.PermutationEncoding;
    87using HeuristicLab.Problems.QuadraticAssignment;
     8using HeuristicLab.Random;
    99using HeuristicLab.SequentialEngine;
    1010
     
    4545  }
    4646
     47  public class PathRelinkingOldFeaturedExplorer : InstanceExplorer {
     48    public int Paths { get; set; }
     49    public bool LocalOptima { get; set; }
     50
     51    public override string Name { get { return "Path-Relinking Explorer"; } }
     52    public override int Effort { get { return Paths; } }
     53
     54    public PathRelinkingOldFeaturedExplorer() {
     55
     56    }
     57
     58    public override InstanceDescriptor Explore(QuadraticAssignmentProblem problem, int? seed = null) {
     59      var random = new MersenneTwister();
     60      var samples = QAPDirectedWalk.CalculateRelinkingPoints(random, problem, Paths, LocalOptima);
     61      var trajectories = QAPDirectedWalk.Run(random, problem, samples);
     62
     63      double avgAc1 = 0, avgCorLen = 0, avgIc = 0, avgDbi = 0, avgPic = 0, avgIs = 0, avgDiv = 0,
     64        avgReg = 0, avgEnt = 0, avgPkIc = 0, avgPkDbi = 0;
     65      int count = 0;
     66      foreach (var t in trajectories) {
     67        var trail = t.Select(x => x.Item2).ToArray();
     68        if (trail.Length < 4) continue;
     69        count++;
     70        double[] acf;
     71        var len = RuggednessCalculator.CalculateCorrelationLength(trail, out acf);
     72        avgAc1 += acf[0];
     73        avgCorLen += len;
     74        var analysis = new InformationAnalysis(trail, 20, 2);
     75        avgIc += analysis.InformationContent[0];
     76        avgDbi += analysis.DensityBasinInformation[0];
     77        avgPic += analysis.PartialInformationContent[0];
     78        avgIs += analysis.InformationStability;
     79        avgDiv += analysis.Diversity;
     80        avgReg += analysis.Regularity;
     81        avgEnt += analysis.TotalEntropy[0];
     82        avgPkIc += analysis.PeakInformationContent.Value;
     83        avgPkDbi += analysis.PeakDensityBasinInformation.Value;
     84      }
     85      avgAc1 /= count;
     86      avgCorLen /= count;
     87      avgIc /= count;
     88      avgDbi /= count;
     89      avgPic /= count;
     90      avgIs /= count;
     91      avgDiv /= count;
     92      avgReg /= count;
     93      avgEnt /= count;
     94      avgPkIc /= count;
     95      avgPkDbi /= count;
     96
     97      return new InstanceDescriptor(problem.Name, InstanceDescriptor.GetClass(problem.Name), problem.Weights.Rows,
     98        new[] { "Autocorrelation(1)", "CorrelationLength", "InformationContent", "DensityBasinInformation",
     99          "PartialInformationContent", "InformationStability", "Diversity", "Regularity", "TotalEntropy",
     100          "PeakInformationContent", "PeakDensityBasinInformation" },
     101        new[] { avgAc1, avgCorLen, avgIc, avgDbi,
     102          avgPic, avgIs, avgDiv, avgReg, avgEnt,
     103          avgPkIc, avgPkDbi });
     104    }
     105  }
     106
    47107
    48108  public class RandomWalkExplorer : InstanceExplorer {
     
    76136  public class AdaptiveWalkExplorer : InstanceExplorer {
    77137    public int Iterations { get; set; }
     138    public int SampleSize { get; set; }
    78139
    79140    public override string Name { get { return "Adaptive-Walk Explorer"; } }
    80     public override int Effort { get { return Iterations; } }
     141    public override int Effort { get { return Iterations * SampleSize; } }
    81142
    82143    public AdaptiveWalkExplorer() {
     
    87148      var walk = new AdaptiveWalk() {
    88149        SeedParameter = { Value = { Value = seed ?? 0 } },
    89         SetSeedRandomlyParameter = { Value = { Value = seed.HasValue } },
     150        SetSeedRandomlyParameter = { Value = { Value = !seed.HasValue } },
    90151        MaximumIterationsParameter = { Value = { Value = Iterations } },
    91         RepetitionsParameter = { Value = { Value = 1 } }
     152        RepetitionsParameter = { Value = { Value = 1 } },
     153        SampleSizeParameter = { Value = { Value = SampleSize } }
    92154      };
    93155      walk.Problem = problem;
     
    95157      walk.MutatorParameter.Value = walk.MutatorParameter.ValidValues.First(x => x is Swap2Manipulator);
    96158      var calculator = new AdaptiveWalkCalculator(walk) { Problem = problem };
     159      var features = calculator.Calculate().ToDictionary(x => x.Name, x => x.Value);
     160
     161      return new InstanceDescriptor(problem.Name, InstanceDescriptor.GetClass(problem.Name), problem.Weights.Rows,
     162        features.Keys.ToArray(), features.Values.Select(x => ((DoubleValue)x).Value).ToArray());
     163    }
     164  }
     165
     166  public class UpDownWalkExplorer : InstanceExplorer {
     167    public int Iterations { get; set; }
     168    public int SampleSize { get; set; }
     169
     170    public override string Name { get { return "Up/Down-Walk Explorer"; } }
     171    public override int Effort { get { return Iterations * SampleSize; } }
     172
     173    public UpDownWalkExplorer() {
     174
     175    }
     176
     177    public override InstanceDescriptor Explore(QuadraticAssignmentProblem problem, int? seed = null) {
     178      var walk = new UpDownWalk() {
     179        SeedParameter = { Value = { Value = seed ?? 0 } },
     180        SetSeedRandomlyParameter = { Value = { Value = !seed.HasValue } },
     181        MaximumIterationsParameter = { Value = { Value = Iterations } },
     182        RepetitionsParameter = { Value = { Value = 1 } },
     183        SampleSizeParameter = { Value = { Value = SampleSize } }
     184      };
     185      walk.Problem = problem;
     186      walk.Engine = new SequentialEngine();
     187      walk.MutatorParameter.Value = walk.MutatorParameter.ValidValues.First(x => x is Swap2Manipulator);
     188      var calculator = new UpDownWalkCalculator(walk) {  Problem = problem };
    97189      var features = calculator.Calculate().ToDictionary(x => x.Name, x => x.Value);
    98190
Note: See TracChangeset for help on using the changeset viewer.