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/HeuristicLab.Analysis.FitnessLandscape/3.3/ProblemCharacteristicAnalysis/QAP/QAPDirectedWalk.cs

    r14691 r15031  
    7979    private QAPDirectedWalk(QAPDirectedWalk original, Cloner cloner) : base(original, cloner) { }
    8080    public QAPDirectedWalk() {
    81       characteristics.AddRange(new[] { "Swap2.Sharpness", "Swap2.Bumpiness", "Swap2.Flatness", /*"Swap2.Steadiness"*/ }
     81      characteristics.AddRange(new[] { "Swap2.Sharpness", "Swap2.Bumpiness", "Swap2.Flatness" }
    8282        .Select(x => new StringValue(x)).ToList());
    8383      Parameters.Add(new FixedValueParameter<IntValue>("Paths", "The number of paths to explore (a path is a set of solutions that connect two randomly chosen solutions).", new IntValue(50)));
     
    9898      IRandom random = Seed.HasValue ? new MersenneTwister((uint)Seed.Value) : new MersenneTwister();
    9999      var qap = (QuadraticAssignmentProblem)Problem;
    100       var pathCount = Paths;
    101 
     100      List<Permutation> permutations = CalculateRelinkingPoints(random, qap, Paths, LocalOptima);
     101
     102      var trajectories = Run(random, (QuadraticAssignmentProblem)Problem, permutations, BestImprovement).ToList();
     103      var result = PermutationPathAnalysis.GetCharacteristics(trajectories);
     104
     105      foreach (var chara in characteristics.CheckedItems.Select(x => x.Value.Value)) {
     106        if (chara == "Swap2.Sharpness") yield return new Result("Swap2.Sharpness", new DoubleValue(result.Sharpness));
     107        if (chara == "Swap2.Bumpiness") yield return new Result("Swap2.Bumpiness", new DoubleValue(result.Bumpiness));
     108        if (chara == "Swap2.Flatness") yield return new Result("Swap2.Flatness", new DoubleValue(result.Flatness));
     109      }
     110    }
     111
     112    public static List<Permutation> CalculateRelinkingPoints(IRandom random, QuadraticAssignmentProblem qap, int pathCount, bool localOptima) {
    102113      var perm = new Permutation(PermutationTypes.Absolute, qap.Weights.Rows, random);
    103       if (LocalOptima) {
     114      if (localOptima) {
    104115        var fit = new DoubleValue(QAPEvaluator.Apply(perm, qap.Weights, qap.Distances));
    105116        QAPExhaustiveSwap2LocalImprovement.ImproveFast(perm, qap.Weights, qap.Distances, fit, new IntValue(0), new IntValue(0), qap.Maximization.Value, int.MaxValue, CancellationToken.None);
     
    109120        perm = (Permutation)permutations.Last().Clone();
    110121        BiasedShuffle(perm, random);
    111         if (LocalOptima) {
     122        if (localOptima) {
    112123          var fit = new DoubleValue(QAPEvaluator.Apply(perm, qap.Weights, qap.Distances));
    113124          QAPExhaustiveSwap2LocalImprovement.ImproveFast(perm, qap.Weights, qap.Distances, fit, new IntValue(0), new IntValue(0), qap.Maximization.Value, int.MaxValue, CancellationToken.None);
     
    117128      }
    118129
    119       var trajectories = Run(random, (QuadraticAssignmentProblem)Problem, permutations, BestImprovement).ToList();
    120       var result = PermutationPathAnalysis.GetCharacteristics(trajectories);
    121      
    122       foreach (var chara in characteristics.CheckedItems.Select(x => x.Value.Value)) {
    123         if (chara == "Swap2.Sharpness") yield return new Result("Swap2.Sharpness", new DoubleValue(result.Sharpness));
    124         if (chara == "Swap2.Bumpiness") yield return new Result("Swap2.Bumpiness", new DoubleValue(result.Bumpiness));
    125         if (chara == "Swap2.Flatness") yield return new Result("Swap2.Flatness", new DoubleValue(result.Flatness));
    126       }
     130      return permutations;
    127131    }
    128132
Note: See TracChangeset for help on using the changeset viewer.