- Timestamp:
- 02/20/17 20:41:33 (8 years ago)
- 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 58 58 characteristics = cloner.Clone(original.characteristics); 59 59 } 60 public RandomWalkCalculator() { 60 public RandomWalkCalculator() : this(new RandomWalk()) { } 61 public RandomWalkCalculator(RandomWalk walker) { 61 62 Name = ItemName; 62 63 Description = ItemDescription; 63 walker = new RandomWalk();64 this.walker = walker; 64 65 characteristics = new CheckedItemList<StringValue>( 65 66 new[] { "AutoCorrelation1", "CorrelationLength", "InformationContent", 66 "PartialInformationContent", "DensityBasinInformation", "InformationStability", 67 "PartialInformationContent", "DensityBasinInformation", "InformationStability", 67 68 "Diversity", "Regularity", "TotalEntropy", "PeakInformationContent", 68 69 "PeakDensityBasinInformation" }.Select(x => new StringValue(x))); … … 91 92 }; 92 93 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; } 96 98 } 97 99 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)); 99 105 } 100 106 walker.Prepare(true); -
branches/PerformanceComparison/HeuristicLab.Analysis.FitnessLandscape/3.3/ProblemCharacteristicAnalysis/QAP/QAPDirectedWalk.cs
r14678 r14690 32 32 using System.Collections.Generic; 33 33 using System.Linq; 34 using System.Threading; 34 35 35 36 namespace HeuristicLab.Analysis.FitnessLandscape { … … 50 51 } 51 52 53 public IFixedValueParameter<BoolValue> LocalOptimaParameter { 54 get { return (IFixedValueParameter<BoolValue>)Parameters["LocalOptima"]; } 55 } 56 52 57 public int Paths { 53 58 get { return PathsParameter.Value.Value; } … … 63 68 get { return SeedParameter.Value != null ? SeedParameter.Value.Value : (int?)null; } 64 69 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; } 65 75 } 66 76 … … 74 84 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))); 75 85 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))); 76 87 } 77 88 … … 90 101 91 102 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 } 92 107 var permutations = new List<Permutation> { perm }; 93 108 while (permutations.Count < pathCount + 1) { 94 109 perm = (Permutation)permutations.Last().Clone(); 95 110 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); 97 117 } 98 118 … … 151 171 152 172 for (var p = 0; p < f2.Count; p++) { 173 if (f2[p].Count <= 2) continue; 153 174 var bump = 0; 154 175 var flat = 0; … … 266 287 } 267 288 289 // Center-of-Mass 268 290 private static double ComBelowZero(IEnumerable<Tuple<Permutation, double>> path) { 269 291 var area = 0.0;
Note: See TracChangeset
for help on using the changeset viewer.