Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/20/17 20:41:33 (8 years ago)
Author:
abeham
Message:

#2457: working on identification of problem instances

Location:
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/CharacteristicCalculator/RandomWalkCalculator.cs

    r13920 r14690  
    5858      characteristics = cloner.Clone(original.characteristics);
    5959    }
    60     public RandomWalkCalculator() {
     60    public RandomWalkCalculator() : this(new RandomWalk()) { }
     61    public RandomWalkCalculator(RandomWalk walker) {
    6162      Name = ItemName;
    6263      Description = ItemDescription;
    63       walker = new RandomWalk();
     64      this.walker = walker;
    6465      characteristics = new CheckedItemList<StringValue>(
    6566        new[] { "AutoCorrelation1", "CorrelationLength", "InformationContent",
    66         "PartialInformationContent", "DensityBasinInformation", "InformationStability", 
     67        "PartialInformationContent", "DensityBasinInformation", "InformationStability",
    6768        "Diversity", "Regularity", "TotalEntropy", "PeakInformationContent",
    6869        "PeakDensityBasinInformation" }.Select(x => new StringValue(x)));
     
    9192        };
    9293        walker.ExecutionStateChanged += evHandle;
    93         walker.Start();
    94         waitHandle.WaitOne();
    95         walker.ExecutionStateChanged -= evHandle;
     94        try {
     95          walker.Start();
     96          waitHandle.WaitOne();
     97        } finally { walker.ExecutionStateChanged -= evHandle; }
    9698      }
    9799      foreach (var p in characteristics.CheckedItems) {
    98         yield return new Result("RandomWalk." + walker.MutatorParameter.Value.Name + "." + p.Value.Value, walker.Results[p.Value.Value].Value);
     100        var resultName = "RandomWalk." + walker.MutatorParameter.Value.Name + "." + p.Value.Value;
     101        IResult result;
     102        if (walker.Results.TryGetValue(p.Value.Value, out result)) {
     103          yield return new Result(resultName, result.Value);
     104        } else yield return new Result(resultName, new DoubleValue(0));
    99105      }
    100106      walker.Prepare(true);
  • branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/ProblemCharacteristicAnalysis/QAP/QAPDirectedWalk.cs

    r14678 r14690  
    3232using System.Collections.Generic;
    3333using System.Linq;
     34using System.Threading;
    3435
    3536namespace HeuristicLab.Analysis.FitnessLandscape {
     
    5051    }
    5152
     53    public IFixedValueParameter<BoolValue> LocalOptimaParameter {
     54      get { return (IFixedValueParameter<BoolValue>)Parameters["LocalOptima"]; }
     55    }
     56
    5257    public int Paths {
    5358      get { return PathsParameter.Value.Value; }
     
    6368      get { return SeedParameter.Value != null ? SeedParameter.Value.Value : (int?)null; }
    6469      set { SeedParameter.Value = value.HasValue ? new IntValue(value.Value) : null; }
     70    }
     71
     72    public bool LocalOptima {
     73      get { return LocalOptimaParameter.Value.Value; }
     74      set { LocalOptimaParameter.Value.Value = value; }
    6575    }
    6676
     
    7484      Parameters.Add(new FixedValueParameter<BoolValue>("BestImprovement", "Whether the best of all alternatives should be chosen for each step in the path or just the first improving (least degrading) move should be made.", new BoolValue(true)));
    7585      Parameters.Add(new OptionalValueParameter<IntValue>("Seed", "The seed for the random number generator."));
     86      Parameters.Add(new FixedValueParameter<BoolValue>("LocalOptima", "Whether to perform walks between local optima.", new BoolValue(false)));
    7687    }
    7788
     
    90101
    91102      var perm = new Permutation(PermutationTypes.Absolute, qap.Weights.Rows, random);
     103      if (LocalOptima) {
     104        var fit = new DoubleValue(QAPEvaluator.Apply(perm, qap.Weights, qap.Distances));
     105        QAPExhaustiveSwap2LocalImprovement.ImproveFast(perm, qap.Weights, qap.Distances, fit, new IntValue(0), new IntValue(0), qap.Maximization.Value, int.MaxValue, CancellationToken.None);
     106      }
    92107      var permutations = new List<Permutation> { perm };
    93108      while (permutations.Count < pathCount + 1) {
    94109        perm = (Permutation)permutations.Last().Clone();
    95110        BiasedShuffle(perm, random);
    96         permutations.Add(perm);
     111        if (LocalOptima) {
     112          var fit = new DoubleValue(QAPEvaluator.Apply(perm, qap.Weights, qap.Distances));
     113          QAPExhaustiveSwap2LocalImprovement.ImproveFast(perm, qap.Weights, qap.Distances, fit, new IntValue(0), new IntValue(0), qap.Maximization.Value, int.MaxValue, CancellationToken.None);
     114        }
     115        if (HammingSimilarityCalculator.CalculateSimilarity(permutations.Last(), perm) < 0.75)
     116          permutations.Add(perm);
    97117      }
    98118
     
    151171
    152172      for (var p = 0; p < f2.Count; p++) {
     173        if (f2[p].Count <= 2) continue;
    153174        var bump = 0;
    154175        var flat = 0;
     
    266287    }
    267288
     289    // Center-of-Mass
    268290    private static double ComBelowZero(IEnumerable<Tuple<Permutation, double>> path) {
    269291      var area = 0.0;
Note: See TracChangeset for help on using the changeset viewer.