Changeset 11667 for branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3
- Timestamp:
- 12/06/14 16:58:02 (10 years ago)
- Location:
- branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HeuristicLab.Algorithms.ParameterlessPopulationPyramid-3.3.csproj
r11666 r11667 104 104 <ItemGroup> 105 105 <Compile Include="AlgorithmBase.cs" /> 106 <Compile Include="EnumerableBoolEqualityComparer.cs" /> 106 107 <Compile Include="LinkageCrossover.cs" /> 108 <Compile Include="Plugin.cs" /> 107 109 <Compile Include="Problems\DeceptiveTrapProblem.cs" /> 108 110 <Compile Include="HillClimber.cs" /> … … 111 113 <Compile Include="Population.cs" /> 112 114 <Compile Include="Problems\BinaryVectorProblem.cs" /> 113 <Compile Include="Plugin.cs" />114 115 <Compile Include="Problems\EvaluationTracker.cs" /> 115 116 <Compile Include="Problems\HIFFProblem.cs" /> -
branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/LinkageCrossover.cs
r11666 r11667 57 57 if (changed) { 58 58 double newFitness = problem.Evaluate(solution); 59 if (problem.IsBetter(newFitness, fitness)) { 60 // improvement made, keep change to solution 61 fitness = newFitness; 62 } else { 63 // revert solution 59 // if the original is strictly better, revert the change 60 if (problem.IsBetter(fitness, newFitness)) { 64 61 foreach (var index in flipped) { 65 62 solution[index] = !solution[index]; 66 63 } 64 } else { 65 // new solution is no worse than original, keep change to solution 66 fitness = newFitness; 67 67 } 68 68 } -
branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/LinkageTree.cs
r11666 r11667 52 52 // Swap element "i" with a random earlier element (including itself) 53 53 int swapIndex = random.Next(i + 1); 54 yield return source[swapIndex]; 55 source[swapIndex] = source[i]; 56 // we don't actually perform the swap, we can forget about the 57 // swapped element because we already returned it. 54 source.Swap(i, swapIndex); 55 yield return source[i]; 58 56 } 59 57 yield return source[0]; … … 148 146 var topLevel = Enumerable.Range(0, length).ToList(); 149 147 bool[] useful = Enumerable.Repeat(true, clusters.Length).ToArray(); 150 151 148 152 149 // Store the distances between all clusters -
branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs
r11666 r11667 39 39 [StorableClass] 40 40 [Creatable("Parameterless Population Pyramid")] 41 41 42 42 public class ParameterlessPopulationPyramid : AlgorithmBase { 43 43 private readonly IRandom random = new MersenneTwister(); … … 46 46 47 47 // Tracks all solutions in Pyramid for quick membership checks 48 private readonly HashSet<bool[]> seen = new HashSet<bool[]>();48 private HashSet<bool[]> seen = new HashSet<bool[]>(new EnumerableBoolEqualityComparer()); 49 49 50 50 private const string MaximumIterationsParameterName = "Maximum Iterations"; … … 53 53 get { return (IFixedValueParameter<IntValue>)Parameters[MaximumIterationsParameterName]; } 54 54 } 55 55 56 56 public int MaximumIterations { 57 57 get { return MaximumIterationsParameter.Value.Value; } … … 70 70 } 71 71 72 72 73 73 private const string SeedParameterName = "Seed"; 74 74 … … 149 149 } 150 150 151 152 151 private void AddIfUnique(bool[] solution, int level) { 153 152 // Don't add things you have seen … … 156 155 pyramid.Add(new Population(tracker.Length, random)); 157 156 } 158 pyramid[level].Add(solution); 159 seen.Add(solution); 157 var copied = (bool[])solution.Clone(); 158 pyramid[level].Add(copied); 159 seen.Add(copied); 160 160 } 161 161 … … 169 169 fitness = HillClimber.ImproveToLocalOptimum(tracker, solution, fitness, random); 170 170 AddIfUnique(solution, 0); 171 171 172 for (int level = 0; level < pyramid.Count; level++) { 172 173 var current = pyramid[level]; … … 184 185 if (SetSeedRandomly) Seed = new System.Random().Next(); 185 186 pyramid = new List<Population>(); 187 seen.Clear(); 186 188 random.Reset(Seed); 187 189 tracker = new EvaluationTracker(Problem, MaximumEvaluations); … … 213 215 ResultsQualitiesBest.Values.Add(tracker.BestQuality); 214 216 ResultsQualitiesIteration.Values.Add(fitness); 215 } 217 } 216 218 } 217 219 } -
branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Plugin.cs.frame
r11632 r11667 31 31 [Plugin("HeuristicLab.Algorithms.ParameterlessPopulationPyramid", "3.3.10.$WCREV$")] 32 32 [PluginFile("HeuristicLab.Algorithms.ParameterlessPopulationPyramid-3.3.dll", PluginFileType.Assembly)] 33 [PluginDependency("HeuristicLab.Analysis", "3.3")] 33 34 [PluginDependency("HeuristicLab.Collections", "3.3")] 34 35 [PluginDependency("HeuristicLab.Common", "3.3")] 35 36 [PluginDependency("HeuristicLab.Common.Resources", "3.3")] 37 [PluginDependency("HeuristicLab.Core", "3.3")] 38 [PluginDependency("HeuristicLab.Data", "3.3")] 39 [PluginDependency("HeuristicLab.Encodings.BinaryVectorEncoding", "3.3")] 40 [PluginDependency("HeuristicLab.Optimization", "3.3")] 41 [PluginDependency("HeuristicLab.Parameters", "3.3")] 36 42 [PluginDependency("HeuristicLab.Persistence", "3.3")] 43 [PluginDependency("HeuristicLab.Random", "3.3")] 37 44 public class Plugin : PluginBase { 38 45 }
Note: See TracChangeset
for help on using the changeset viewer.