Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/13/15 15:00:15 (10 years ago)
Author:
abeham
Message:

#2174, #2282: merged revisions r11961,r11963,r11967,r11970,r11971,r11982,r11984,r11998,r12001,r12002,r12003,r12004,r11939,r11945,r11956,r11958,r11959,r11960,r11983,r11987,r11988,r11990,r11993,r11994,r11996,r11999,r12000 to stable

Location:
stable
Files:
1 deleted
8 edited
2 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/EvaluationTracker.cs

    r11956 r12005  
    2222
    2323using System;
    24 using HeuristicLab.Problems.BinaryVector;
     24using HeuristicLab.Common;
     25using HeuristicLab.Core;
     26using HeuristicLab.Data;
     27using HeuristicLab.Encodings.BinaryVectorEncoding;
     28using HeuristicLab.Parameters;
     29using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     30using HeuristicLab.Problems.Binary;
    2531
    2632namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid {
     
    2834  // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014
    2935  // 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;
    3238
    3339    private int maxEvaluations;
     
    4955    }
    5056
    51     public bool[] BestSolution {
     57    public BinaryVector BestSolution {
    5258      get;
    5359      private set;
     
    5561    #endregion
    5662
    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) {
    5878      this.problem = problem;
    5979      this.maxEvaluations = maxEvaluations;
    60       BestSolution = new bool[0];
     80      BestSolution = new BinaryVector(Length);
    6181      BestQuality = double.NaN;
    6282      Evaluations = 0;
    6383      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 });
    6487    }
    6588
    66     public double Evaluate(bool[] individual) {
     89    public override double Evaluate(BinaryVector vector, IRandom random) {
    6790      if (Evaluations >= maxEvaluations) throw new OperationCanceledException("Maximum Evaluation Limit Reached");
    6891      Evaluations++;
    69       double fitness = problem.Evaluate(individual);
     92      double fitness = problem.Evaluate(vector, random);
    7093      if (double.IsNaN(BestQuality) || problem.IsBetter(fitness, BestQuality)) {
    7194        BestQuality = fitness;
    72         BestSolution = (bool[])individual.Clone();
     95        BestSolution = (BinaryVector)vector.Clone();
    7396        BestFoundOnEvaluation = Evaluations;
    7497      }
     
    7699    }
    77100
    78     #region ForwardedInteraface
    79     public int Length {
     101    public override int Length {
    80102      get { return problem.Length; }
     103      set { problem.Length = value; }
    81104    }
    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      }
    84111    }
     112
    85113    public bool IsBetter(double quality, double bestQuality) {
    86114      return problem.IsBetter(quality, bestQuality);
    87115    }
    88     #endregion
     116
    89117  }
    90118}
  • stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HeuristicLab.Algorithms.ParameterlessPopulationPyramid-3.3.csproj

    r11939 r12005  
    1717    <DebugType>full</DebugType>
    1818    <Optimize>false</Optimize>
    19     <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
     19    <OutputPath>$(SolutionDir)\bin\</OutputPath>
    2020    <DefineConstants>DEBUG;TRACE</DefineConstants>
    2121    <ErrorReport>prompt</ErrorReport>
     
    2525    <DebugType>pdbonly</DebugType>
    2626    <Optimize>true</Optimize>
    27     <OutputPath>..\..\..\..\trunk\sources\bin\</OutputPath>
     27    <OutputPath>$(SolutionDir)\bin\</OutputPath>
    2828    <DefineConstants>TRACE</DefineConstants>
    2929    <ErrorReport>prompt</ErrorReport>
     
    3535  <PropertyGroup>
    3636    <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>
    3773  </PropertyGroup>
    3874  <ItemGroup>
     
    4783  <ItemGroup>
    4884    <Compile Include="EnumerableBoolEqualityComparer.cs" />
     85    <Compile Include="EvaluationTracker.cs" />
    4986    <Compile Include="LinkageCrossover.cs" />
    5087    <Compile Include="Plugin.cs" />
    51     <Compile Include="Problems\DeceptiveStepTrapProblem.cs" />
    52     <Compile Include="Problems\DeceptiveTrapProblem.cs" />
    5388    <Compile Include="HillClimber.cs" />
    5489    <Compile Include="LinkageTree.cs" />
    5590    <Compile Include="ParameterlessPopulationPyramid.cs" />
    5691    <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" />
    6292    <Compile Include="Properties\AssemblyInfo.cs" />
    6393  </ItemGroup>
     
    118148      <Private>False</Private>
    119149    </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>
    120155    <ProjectReference Include="..\..\HeuristicLab.Random\3.3\HeuristicLab.Random-3.3.csproj">
    121156      <Project>{f4539fb6-4708-40c9-be64-0a1390aea197}</Project>
     
    124159    </ProjectReference>
    125160  </ItemGroup>
     161  <ItemGroup />
    126162  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    127163  <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)
    132169
    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>
    134178  </PropertyGroup>
    135179  <!-- 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  
    2828using HeuristicLab.Core;
    2929using HeuristicLab.Data;
     30using HeuristicLab.Encodings.BinaryVectorEncoding;
    3031using HeuristicLab.Optimization;
    3132using HeuristicLab.Parameters;
    3233using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     34using HeuristicLab.Problems.Binary;
    3335using HeuristicLab.Random;
    3436
     
    3840  // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014
    3941  // 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.")]
    4143  [StorableClass]
    42   [Creatable("Parameterless Population Pyramid")]
     44  [Creatable("Algorithms")]
    4345  public class HillClimber : BasicAlgorithm {
    4446    [Storable]
     
    4850
    4951    public override Type ProblemType {
    50       get { return typeof(BinaryVectorProblem); }
     52      get { return typeof(BinaryProblem); }
    5153    }
    52     public new BinaryVectorProblem Problem {
    53       get { return (BinaryVectorProblem)base.Problem; }
     54    public new BinaryProblem Problem {
     55      get { return (BinaryProblem)base.Problem; }
    5456      set { base.Problem = value; }
    5557    }
     
    8284      Results.Add(new Result("Best quality", BestQuality));
    8385      for (int iteration = 0; iteration < Iterations; iteration++) {
    84         bool[] solution = new bool[Problem.Length];
     86        var solution = new BinaryVector(Problem.Length);
    8587        for (int i = 0; i < solution.Length; i++) {
    8688          solution[i] = random.Next(2) == 1;
    8789        }
    8890
    89         var fitness = Problem.Evaluate(solution);
     91        var fitness = Problem.Evaluate(solution, random);
    9092
    9193        fitness = ImproveToLocalOptimum(Problem, solution, fitness, random);
     
    9698    }
    9799    // 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) {
    99101      var tried = new HashSet<int>();
    100102      do {
     
    103105          if (tried.Contains(option)) continue;
    104106          solution[option] = !solution[option];
    105           double newFitness = problem.Evaluate(solution);
     107          double newFitness = problem.Evaluate(solution, rand);
    106108          if (problem.IsBetter(newFitness, fitness)) {
    107109            fitness = newFitness;
  • stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/LinkageCrossover.cs

    r11838 r12005  
    2020 */
    2121#endregion
    22 using System;
    2322using System.Collections.Generic;
    2423using System.Linq;
    25 using System.Text;
    26 using System.Threading.Tasks;
    2724using HeuristicLab.Core;
     25using HeuristicLab.Encodings.BinaryVectorEncoding;
     26using HeuristicLab.Problems.Binary;
    2827using HeuristicLab.Random;
    2928
     
    3433  public static class LinkageCrossover {
    3534    // 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) {
    3736      var options = Enumerable.Range(0, donors.Count).ToArray();
    3837      foreach (var cluster in tree.Clusters) {
     
    4241        foreach (var donorIndex in options.ShuffleList(rand)) {
    4342          // 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);
    4544          if (donorFound) break;
    4645        }
     
    4948    }
    5049
    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) {
    5251      // keep track of which bits flipped to make the donation
    5352      List<int> flipped = new List<int>();
     
    6059      changed = flipped.Count > 0;
    6160      if (changed) {
    62         double newFitness = problem.Evaluate(solution);
     61        double newFitness = problem.Evaluate(solution, rand);
    6362        // if the original is strictly better, revert the change
    6463        if (problem.IsBetter(fitness, newFitness)) {
  • stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/LinkageTree.cs

    r11939 r12005  
    2626using HeuristicLab.Common;
    2727using HeuristicLab.Core;
     28using HeuristicLab.Encodings.BinaryVectorEncoding;
    2829using HeuristicLab.Random;
    2930
     
    6465    }
    6566
    66     public void Add(bool[] solution) {
     67    public void Add(BinaryVector solution) {
    6768      if (solution.Length != length) throw new ArgumentException("The individual has not the correct length.");
    6869      for (int i = 1; i < solution.Length; i++) {
  • stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs

    r11939 r12005  
    3232using HeuristicLab.Parameters;
    3333using HeuristicLab.Persistence.Default.CompositeSerializers.Storable;
     34using HeuristicLab.Problems.Binary;
    3435using HeuristicLab.Random;
    3536
     
    3839  // B. W. Goldman and W. F. Punch, "Parameter-less Population Pyramid," GECCO, pp. 785–792, 2014
    3940  // 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")]
    4142  [StorableClass]
    42   [Creatable("Parameterless Population Pyramid")]
     43  [Creatable("Algorithms")]
    4344  public class ParameterlessPopulationPyramid : BasicAlgorithm {
    4445    public override Type ProblemType {
    45       get { return typeof(BinaryVectorProblem); }
    46     }
    47     public new BinaryVectorProblem Problem {
    48       get { return (BinaryVectorProblem)base.Problem; }
     46      get { return typeof(BinaryProblem); }
     47    }
     48    public new BinaryProblem Problem {
     49      get { return (BinaryProblem)base.Problem; }
    4950      set { base.Problem = value; }
    5051    }
     
    5556
    5657    // 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());
    5859
    5960    #region ParameterNames
     
    178179    }
    179180
    180     private void AddIfUnique(bool[] solution, int level) {
     181    private void AddIfUnique(BinaryVector solution, int level) {
    181182      // Don't add things you have seen
    182183      if (seen.Contains(solution)) return;
     
    184185        pyramid.Add(new Population(tracker.Length, random));
    185186      }
    186       var copied = (bool[])solution.Clone();
     187      var copied = (BinaryVector)solution.Clone();
    187188      pyramid[level].Add(copied);
    188189      seen.Add(copied);
     
    192193    private double iterate() {
    193194      // Create a random solution
    194       bool[] solution = new bool[tracker.Length];
     195      BinaryVector solution = new BinaryVector(tracker.Length);
    195196      for (int i = 0; i < solution.Length; i++) {
    196197        solution[i] = random.Next(2) == 1;
    197198      }
    198       double fitness = tracker.Evaluate(solution);
     199      double fitness = tracker.Evaluate(solution, random);
    199200      fitness = HillClimber.ImproveToLocalOptimum(tracker, solution, fitness, random);
    200201      AddIfUnique(solution, 0);
     
    248249          fitness = iterate();
    249250          cancellationToken.ThrowIfCancellationRequested();
    250         }
    251         finally {
     251        } finally {
    252252          ResultsEvaluations = tracker.Evaluations;
    253253          ResultsBestSolution = new BinaryVector(tracker.BestSolution);
  • stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Plugin.cs.frame

    r11939 r12005  
    4040  [PluginDependency("HeuristicLab.Parameters", "3.3")]
    4141  [PluginDependency("HeuristicLab.Persistence", "3.3")]
     42  [PluginDependency("HeuristicLab.Problems.Binary", "3.3")]
    4243  [PluginDependency("HeuristicLab.Random", "3.3")]
    4344  public class Plugin : PluginBase {
  • stable/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/Population.cs

    r11838 r12005  
    2323using System.Collections.Generic;
    2424using HeuristicLab.Core;
     25using HeuristicLab.Encodings.BinaryVectorEncoding;
    2526
    2627namespace HeuristicLab.Algorithms.ParameterlessPopulationPyramid {
     
    2930  // and the original source code in C++11 available from: https://github.com/brianwgoldman/Parameter-less_Population_Pyramid
    3031  public class Population {
    31     public List<bool[]> Solutions {
     32    public List<BinaryVector> Solutions {
    3233      get;
    3334      private set;
     
    4041
    4142    public Population(int length, IRandom rand) {
    42       Solutions = new List<bool[]>();
     43      Solutions = new List<BinaryVector>();
    4344      Tree = new LinkageTree(length, rand);
    4445    }
    45     public void Add(bool[] solution) {
     46    public void Add(BinaryVector solution) {
    4647      Solutions.Add(solution);
    4748      Tree.Add(solution);
Note: See TracChangeset for help on using the changeset viewer.