- Timestamp:
- 02/13/15 15:00:15 (10 years ago)
- Location:
- stable
- Files:
-
- 1 deleted
- 8 edited
- 2 copied
Legend:
- Unmodified
- Added
- Removed
-
stable
- Property svn:mergeinfo changed
/trunk/sources merged: 11939,11945,11956,11958-11961,11963,11967,11970-11971,11982-11984,11987-11988,11990,11993-11994,11996,11998-12004
- Property svn:mergeinfo changed
-
stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EvaluationTracker.cs
r11956 r12005 22 22 23 23 using System; 24 using HeuristicLab.Problems.BinaryVector; 24 using HeuristicLab.Common; 25 using HeuristicLab.Core; 26 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.BinaryVectorEncoding; 28 using HeuristicLab.Parameters; 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Problems.Binary; 25 31 26 32 namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid { … … 28 34 // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014 29 35 // and the original source code in C++11 available from: https://github.com/brianwgoldman/Parameter-less_Population_Pyramid 30 public class EvaluationTracker : IBinaryVectorProblem {31 private readonly IBinaryVectorProblem problem;36 internal sealed class EvaluationTracker : BinaryProblem { 37 private readonly BinaryProblem problem; 32 38 33 39 private int maxEvaluations; … … 49 55 } 50 56 51 public bool[]BestSolution {57 public BinaryVector BestSolution { 52 58 get; 53 59 private set; … … 55 61 #endregion 56 62 57 public EvaluationTracker(IBinaryVectorProblem problem, int maxEvaluations) { 63 [StorableConstructor] 64 private EvaluationTracker(bool deserializing) : base(deserializing) { } 65 private EvaluationTracker(EvaluationTracker original, Cloner cloner) 66 : base(original, cloner) { 67 problem = cloner.Clone(original.problem); 68 maxEvaluations = original.maxEvaluations; 69 BestQuality = original.BestQuality; 70 Evaluations = original.Evaluations; 71 BestFoundOnEvaluation = original.BestFoundOnEvaluation; 72 BestSolution = cloner.Clone(BestSolution); 73 } 74 public override IDeepCloneable Clone(Cloner cloner) { 75 return new EvaluationTracker(this, cloner); 76 } 77 public EvaluationTracker(BinaryProblem problem, int maxEvaluations) { 58 78 this.problem = problem; 59 79 this.maxEvaluations = maxEvaluations; 60 BestSolution = new bool[0];80 BestSolution = new BinaryVector(Length); 61 81 BestQuality = double.NaN; 62 82 Evaluations = 0; 63 83 BestFoundOnEvaluation = 0; 84 85 if (Parameters.ContainsKey("Maximization")) Parameters.Remove("Maximization"); 86 Parameters.Add(new FixedValueParameter<BoolValue>("Maximization", "Set to false if the problem should be minimized.", (BoolValue)new BoolValue(Maximization).AsReadOnly()) { Hidden = true }); 64 87 } 65 88 66 public double Evaluate(bool[] individual) {89 public override double Evaluate(BinaryVector vector, IRandom random) { 67 90 if (Evaluations >= maxEvaluations) throw new OperationCanceledException("Maximum Evaluation Limit Reached"); 68 91 Evaluations++; 69 double fitness = problem.Evaluate( individual);92 double fitness = problem.Evaluate(vector, random); 70 93 if (double.IsNaN(BestQuality) || problem.IsBetter(fitness, BestQuality)) { 71 94 BestQuality = fitness; 72 BestSolution = ( bool[])individual.Clone();95 BestSolution = (BinaryVector)vector.Clone(); 73 96 BestFoundOnEvaluation = Evaluations; 74 97 } … … 76 99 } 77 100 78 #region ForwardedInteraface 79 public int Length { 101 public override int Length { 80 102 get { return problem.Length; } 103 set { problem.Length = value; } 81 104 } 82 public bool Maximization { 83 get { return problem.Maximization; } 105 106 public override bool Maximization { 107 get { 108 if (problem == null) return false; 109 return problem.Maximization; 110 } 84 111 } 112 85 113 public bool IsBetter(double quality, double bestQuality) { 86 114 return problem.IsBetter(quality, bestQuality); 87 115 } 88 #endregion 116 89 117 } 90 118 } -
stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HeuristicLab.Algorithms.ParameterlessPopulationPyramid-3.3.csproj
r11939 r12005 17 17 <DebugType>full</DebugType> 18 18 <Optimize>false</Optimize> 19 <OutputPath> ..\..\..\..\trunk\sources\bin\</OutputPath>19 <OutputPath>$(SolutionDir)\bin\</OutputPath> 20 20 <DefineConstants>DEBUG;TRACE</DefineConstants> 21 21 <ErrorReport>prompt</ErrorReport> … … 25 25 <DebugType>pdbonly</DebugType> 26 26 <Optimize>true</Optimize> 27 <OutputPath> ..\..\..\..\trunk\sources\bin\</OutputPath>27 <OutputPath>$(SolutionDir)\bin\</OutputPath> 28 28 <DefineConstants>TRACE</DefineConstants> 29 29 <ErrorReport>prompt</ErrorReport> … … 35 35 <PropertyGroup> 36 36 <AssemblyOriginatorKeyFile>HeuristicLab.snk</AssemblyOriginatorKeyFile> 37 </PropertyGroup> 38 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> 39 <DebugSymbols>true</DebugSymbols> 40 <OutputPath>$(SolutionDir)\bin\</OutputPath> 41 <DefineConstants>DEBUG;TRACE</DefineConstants> 42 <DebugType>full</DebugType> 43 <PlatformTarget>x64</PlatformTarget> 44 <ErrorReport>prompt</ErrorReport> 45 <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> 46 </PropertyGroup> 47 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> 48 <OutputPath>$(SolutionDir)\bin\</OutputPath> 49 <DefineConstants>TRACE</DefineConstants> 50 <Optimize>true</Optimize> 51 <DebugType>pdbonly</DebugType> 52 <PlatformTarget>x64</PlatformTarget> 53 <ErrorReport>prompt</ErrorReport> 54 <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> 55 </PropertyGroup> 56 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> 57 <DebugSymbols>true</DebugSymbols> 58 <OutputPath>$(SolutionDir)\bin\</OutputPath> 59 <DefineConstants>DEBUG;TRACE</DefineConstants> 60 <DebugType>full</DebugType> 61 <PlatformTarget>x86</PlatformTarget> 62 <ErrorReport>prompt</ErrorReport> 63 <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> 64 </PropertyGroup> 65 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> 66 <OutputPath>$(SolutionDir)\bin\</OutputPath> 67 <DefineConstants>TRACE</DefineConstants> 68 <Optimize>true</Optimize> 69 <DebugType>pdbonly</DebugType> 70 <PlatformTarget>x86</PlatformTarget> 71 <ErrorReport>prompt</ErrorReport> 72 <CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet> 37 73 </PropertyGroup> 38 74 <ItemGroup> … … 47 83 <ItemGroup> 48 84 <Compile Include="EnumerableBoolEqualityComparer.cs" /> 85 <Compile Include="EvaluationTracker.cs" /> 49 86 <Compile Include="LinkageCrossover.cs" /> 50 87 <Compile Include="Plugin.cs" /> 51 <Compile Include="Problems\DeceptiveStepTrapProblem.cs" />52 <Compile Include="Problems\DeceptiveTrapProblem.cs" />53 88 <Compile Include="HillClimber.cs" /> 54 89 <Compile Include="LinkageTree.cs" /> 55 90 <Compile Include="ParameterlessPopulationPyramid.cs" /> 56 91 <Compile Include="Population.cs" /> 57 <Compile Include="Problems\BinaryVectorProblem.cs" />58 <Compile Include="Problems\EvaluationTracker.cs" />59 <Compile Include="Problems\HIFFProblem.cs" />60 <Compile Include="Problems\IBinaryVectorProblem.cs" />61 <Compile Include="Problems\OneMaxProblem.cs" />62 92 <Compile Include="Properties\AssemblyInfo.cs" /> 63 93 </ItemGroup> … … 118 148 <Private>False</Private> 119 149 </ProjectReference> 150 <ProjectReference Include="..\..\HeuristicLab.Problems.Binary\3.3\HeuristicLab.Problems.Binary-3.3.csproj"> 151 <Project>{fc627be5-0f93-47d8-bd2e-530ea2b8aa5f}</Project> 152 <Name>HeuristicLab.Problems.Binary-3.3</Name> 153 <Private>False</Private> 154 </ProjectReference> 120 155 <ProjectReference Include="..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj"> 121 156 <Project>{f4539fb6-4708-40c9-be64-0a1390aea197}</Project> … … 124 159 </ProjectReference> 125 160 </ItemGroup> 161 <ItemGroup /> 126 162 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 127 163 <PropertyGroup> 128 <PreBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir) 129 set ProjectDir=$(ProjectDir) 130 set SolutionDir=$(SolutionDir) 131 set Outdir=$(Outdir) 164 <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' "> 165 set Path=%25Path%25;$(ProjectDir);$(SolutionDir) 166 set ProjectDir=$(ProjectDir) 167 set SolutionDir=$(SolutionDir) 168 set Outdir=$(Outdir) 132 169 133 call PreBuildEvent.cmd</PreBuildEvent> 170 call PreBuildEvent.cmd 171 </PreBuildEvent> 172 <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' "> 173 export ProjectDir=$(ProjectDir) 174 export SolutionDir=$(SolutionDir) 175 176 $SolutionDir/PreBuildEvent.sh 177 </PreBuildEvent> 134 178 </PropertyGroup> 135 179 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. -
stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
r11838 r12005 28 28 using HeuristicLab.Core; 29 29 using HeuristicLab.Data; 30 using HeuristicLab.Encodings.BinaryVectorEncoding; 30 31 using HeuristicLab.Optimization; 31 32 using HeuristicLab.Parameters; 32 33 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 34 using HeuristicLab.Problems.Binary; 33 35 using HeuristicLab.Random; 34 36 … … 38 40 // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014 39 41 // and the original source code in C++11 available from: https://github.com/brianwgoldman/Parameter-less_Population_Pyramid 40 [Item("Hill Climber", " Test algorithm.")]42 [Item("Hill Climber", "Binary Hill Climber.")] 41 43 [StorableClass] 42 [Creatable(" Parameterless Population Pyramid")]44 [Creatable("Algorithms")] 43 45 public class HillClimber : BasicAlgorithm { 44 46 [Storable] … … 48 50 49 51 public override Type ProblemType { 50 get { return typeof(Binary VectorProblem); }52 get { return typeof(BinaryProblem); } 51 53 } 52 public new Binary VectorProblem Problem {53 get { return (Binary VectorProblem)base.Problem; }54 public new BinaryProblem Problem { 55 get { return (BinaryProblem)base.Problem; } 54 56 set { base.Problem = value; } 55 57 } … … 82 84 Results.Add(new Result("Best quality", BestQuality)); 83 85 for (int iteration = 0; iteration < Iterations; iteration++) { 84 bool[] solution = new bool[Problem.Length];86 var solution = new BinaryVector(Problem.Length); 85 87 for (int i = 0; i < solution.Length; i++) { 86 88 solution[i] = random.Next(2) == 1; 87 89 } 88 90 89 var fitness = Problem.Evaluate(solution );91 var fitness = Problem.Evaluate(solution, random); 90 92 91 93 fitness = ImproveToLocalOptimum(Problem, solution, fitness, random); … … 96 98 } 97 99 // In the GECCO paper, Section 2.1 98 public static double ImproveToLocalOptimum( IBinaryVectorProblem problem, bool[]solution, double fitness, IRandom rand) {100 public static double ImproveToLocalOptimum(BinaryProblem problem, BinaryVector solution, double fitness, IRandom rand) { 99 101 var tried = new HashSet<int>(); 100 102 do { … … 103 105 if (tried.Contains(option)) continue; 104 106 solution[option] = !solution[option]; 105 double newFitness = problem.Evaluate(solution );107 double newFitness = problem.Evaluate(solution, rand); 106 108 if (problem.IsBetter(newFitness, fitness)) { 107 109 fitness = newFitness; -
stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/LinkageCrossover.cs
r11838 r12005 20 20 */ 21 21 #endregion 22 using System;23 22 using System.Collections.Generic; 24 23 using System.Linq; 25 using System.Text;26 using System.Threading.Tasks;27 24 using HeuristicLab.Core; 25 using HeuristicLab.Encodings.BinaryVectorEncoding; 26 using HeuristicLab.Problems.Binary; 28 27 using HeuristicLab.Random; 29 28 … … 34 33 public static class LinkageCrossover { 35 34 // In the GECCO paper, Figure 3 36 public static double ImproveUsingTree(LinkageTree tree, IList< bool[]> donors, bool[] solution, double fitness, IBinaryVectorProblem problem, IRandom rand) {35 public static double ImproveUsingTree(LinkageTree tree, IList<BinaryVector> donors, BinaryVector solution, double fitness, BinaryProblem problem, IRandom rand) { 37 36 var options = Enumerable.Range(0, donors.Count).ToArray(); 38 37 foreach (var cluster in tree.Clusters) { … … 42 41 foreach (var donorIndex in options.ShuffleList(rand)) { 43 42 // Attempt the donation 44 fitness = Donate(solution, fitness, donors[donorIndex], cluster, problem, out donorFound);43 fitness = Donate(solution, fitness, donors[donorIndex], cluster, problem, rand, out donorFound); 45 44 if (donorFound) break; 46 45 } … … 49 48 } 50 49 51 private static double Donate( bool[] solution, double fitness, bool[] source, IEnumerable<int> cluster, IBinaryVectorProblem problem, out bool changed) {50 private static double Donate(BinaryVector solution, double fitness, BinaryVector source, IEnumerable<int> cluster, BinaryProblem problem, IRandom rand, out bool changed) { 52 51 // keep track of which bits flipped to make the donation 53 52 List<int> flipped = new List<int>(); … … 60 59 changed = flipped.Count > 0; 61 60 if (changed) { 62 double newFitness = problem.Evaluate(solution );61 double newFitness = problem.Evaluate(solution, rand); 63 62 // if the original is strictly better, revert the change 64 63 if (problem.IsBetter(fitness, newFitness)) { -
stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/LinkageTree.cs
r11939 r12005 26 26 using HeuristicLab.Common; 27 27 using HeuristicLab.Core; 28 using HeuristicLab.Encodings.BinaryVectorEncoding; 28 29 using HeuristicLab.Random; 29 30 … … 64 65 } 65 66 66 public void Add( bool[]solution) {67 public void Add(BinaryVector solution) { 67 68 if (solution.Length != length) throw new ArgumentException("The individual has not the correct length."); 68 69 for (int i = 1; i < solution.Length; i++) { -
stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs
r11939 r12005 32 32 using HeuristicLab.Parameters; 33 33 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 34 using HeuristicLab.Problems.Binary; 34 35 using HeuristicLab.Random; 35 36 … … 38 39 // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014 39 40 // and the original source code in C++11 available from: https://github.com/brianwgoldman/Parameter-less_Population_Pyramid 40 [Item("Parameter-less Population Pyramid", "Binary value optimization algorithm which requires no configuration. ")]41 [Item("Parameter-less Population Pyramid", "Binary value optimization algorithm which requires no configuration. B. W. Goldman and W. F. Punch, Parameter-less Population Pyramid, GECCO, pp. 785–792, 2014")] 41 42 [StorableClass] 42 [Creatable(" Parameterless Population Pyramid")]43 [Creatable("Algorithms")] 43 44 public class ParameterlessPopulationPyramid : BasicAlgorithm { 44 45 public override Type ProblemType { 45 get { return typeof(Binary VectorProblem); }46 } 47 public new Binary VectorProblem Problem {48 get { return (Binary VectorProblem)base.Problem; }46 get { return typeof(BinaryProblem); } 47 } 48 public new BinaryProblem Problem { 49 get { return (BinaryProblem)base.Problem; } 49 50 set { base.Problem = value; } 50 51 } … … 55 56 56 57 // Tracks all solutions in Pyramid for quick membership checks 57 private HashSet< bool[]> seen = new HashSet<bool[]>(new EnumerableBoolEqualityComparer());58 private HashSet<BinaryVector> seen = new HashSet<BinaryVector>(new EnumerableBoolEqualityComparer()); 58 59 59 60 #region ParameterNames … … 178 179 } 179 180 180 private void AddIfUnique( bool[]solution, int level) {181 private void AddIfUnique(BinaryVector solution, int level) { 181 182 // Don't add things you have seen 182 183 if (seen.Contains(solution)) return; … … 184 185 pyramid.Add(new Population(tracker.Length, random)); 185 186 } 186 var copied = ( bool[])solution.Clone();187 var copied = (BinaryVector)solution.Clone(); 187 188 pyramid[level].Add(copied); 188 189 seen.Add(copied); … … 192 193 private double iterate() { 193 194 // Create a random solution 194 bool[] solution = new bool[tracker.Length];195 BinaryVector solution = new BinaryVector(tracker.Length); 195 196 for (int i = 0; i < solution.Length; i++) { 196 197 solution[i] = random.Next(2) == 1; 197 198 } 198 double fitness = tracker.Evaluate(solution );199 double fitness = tracker.Evaluate(solution, random); 199 200 fitness = HillClimber.ImproveToLocalOptimum(tracker, solution, fitness, random); 200 201 AddIfUnique(solution, 0); … … 248 249 fitness = iterate(); 249 250 cancellationToken.ThrowIfCancellationRequested(); 250 } 251 finally { 251 } finally { 252 252 ResultsEvaluations = tracker.Evaluations; 253 253 ResultsBestSolution = new BinaryVector(tracker.BestSolution); -
stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Plugin.cs.frame
r11939 r12005 40 40 [PluginDependency("HeuristicLab.Parameters", "3.3")] 41 41 [PluginDependency("HeuristicLab.Persistence", "3.3")] 42 [PluginDependency("HeuristicLab.Problems.Binary", "3.3")] 42 43 [PluginDependency("HeuristicLab.Random", "3.3")] 43 44 public class Plugin : PluginBase { -
stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Population.cs
r11838 r12005 23 23 using System.Collections.Generic; 24 24 using HeuristicLab.Core; 25 using HeuristicLab.Encodings.BinaryVectorEncoding; 25 26 26 27 namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid { … … 29 30 // and the original source code in C++11 available from: https://github.com/brianwgoldman/Parameter-less_Population_Pyramid 30 31 public class Population { 31 public List< bool[]> Solutions {32 public List<BinaryVector> Solutions { 32 33 get; 33 34 private set; … … 40 41 41 42 public Population(int length, IRandom rand) { 42 Solutions = new List< bool[]>();43 Solutions = new List<BinaryVector>(); 43 44 Tree = new LinkageTree(length, rand); 44 45 } 45 public void Add( bool[]solution) {46 public void Add(BinaryVector solution) { 46 47 Solutions.Add(solution); 47 48 Tree.Add(solution);
Note: See TracChangeset
for help on using the changeset viewer.