Free cookie consent management tool by TermsFeed Policy Generator

Ignore:
Timestamp:
02/13/15 15:00:15 (9 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:
5 edited
2 copied

Legend:

Unmodified
Added
Removed
  • stable

  • stable/HeuristicLab.Problems.Binary/3.3/BinaryProblem.cs

    r11987 r12005  
    2222#endregion
    2323
     24using System;
     25using System.Linq;
    2426using HeuristicLab.Common;
    2527using HeuristicLab.Core;
     
    3335  [StorableClass]
    3436  public abstract class BinaryProblem : SingleObjectiveBasicProblem<BinaryVectorEncoding> {
    35 
    3637    public virtual int Length {
    3738      get { return Encoding.Length; }
     
    3940    }
    4041
     42    private IFixedValueParameter<IntValue> LengthParameter {
     43      get { return (IFixedValueParameter<IntValue>)Parameters["Length"]; }
     44    }
     45
    4146    [StorableConstructor]
    4247    protected BinaryProblem(bool deserializing) : base(deserializing) { }
    43     protected BinaryProblem(BinaryProblem original, Cloner cloner) : base(original, cloner) { }
    44     protected BinaryProblem() : base() { }
     48    [StorableHook(HookType.AfterDeserialization)]
     49    private void AfterDeserialization() {
     50      RegisterEventHandlers();
     51    }
     52
     53    protected BinaryProblem(BinaryProblem original, Cloner cloner)
     54      : base(original, cloner) {
     55      RegisterEventHandlers();
     56    }
     57
     58    protected BinaryProblem()
     59      : base() {
     60      var lengthParameter = new FixedValueParameter<IntValue>("Length", "The length of the BinaryVector.", new IntValue(10));
     61      Parameters.Add(lengthParameter);
     62      Encoding.LengthParameter = lengthParameter;
     63      RegisterEventHandlers();
     64    }
    4565
    4666    public virtual bool IsBetter(double quality, double bestQuality) {
     
    4868    }
    4969
     70    public abstract double Evaluate(BinaryVector vector, IRandom random);
    5071    public sealed override double Evaluate(Individual individual, IRandom random) {
    5172      return Evaluate(individual.BinaryVector(), random);
    5273    }
    5374
    54     public abstract double Evaluate(BinaryVector vector, IRandom random);
     75    public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
     76      base.Analyze(individuals, qualities, results, random);
     77      var orderedIndividuals = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q }).OrderBy(z => z.Quality);
     78      var best = Maximization ? orderedIndividuals.Last().Individual : orderedIndividuals.First().Individual;
     79
     80      if (!results.ContainsKey("Best Solution")) {
     81        results.Add(new Result("Best Solution", typeof(BinaryVector)));
     82      }
     83      results["Best Solution"].Value = (IItem)best.BinaryVector().Clone();
     84    }
     85
     86    protected override void OnEncodingChanged() {
     87      base.OnEncodingChanged();
     88      Encoding.LengthParameter = LengthParameter;
     89    }
     90
     91
     92    private void RegisterEventHandlers() {
     93      LengthParameter.Value.ValueChanged += LengthParameter_ValueChanged;
     94    }
     95
     96    protected virtual void LengthParameter_ValueChanged(object sender, EventArgs e) { }
    5597  }
    5698}
  • stable/HeuristicLab.Problems.Binary/3.3/DeceptiveTrapProblem.cs

    r11987 r12005  
    6666      : base() {
    6767      Parameters.Add(new FixedValueParameter<IntValue>(TrapSizeParameterName, "", new IntValue(7)));
    68       Length = 49;
     68      Encoding.Length = 49;
    6969    }
    7070
  • stable/HeuristicLab.Problems.Binary/3.3/HIFFProblem.cs

    r11987 r12005  
    4848    public HIFFProblem()
    4949      : base() {
    50       Length = 64;
     50        Encoding.Length = 64;
    5151    }
    5252    // In the GECCO paper, Section 4.1
  • stable/HeuristicLab.Problems.Binary/3.3/HeuristicLab.Problems.Binary-3.3.csproj

    r11987 r12005  
    1717    <DebugType>full</DebugType>
    1818    <Optimize>false</Optimize>
    19     <OutputPath>..\..\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>..\..\bin\</OutputPath>
     27    <OutputPath>$(SolutionDir)\bin\</OutputPath>
    2828    <DefineConstants>TRACE</DefineConstants>
    2929    <ErrorReport>prompt</ErrorReport>
     
    3838  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
    3939    <DebugSymbols>true</DebugSymbols>
    40     <OutputPath>bin\x64\Debug\</OutputPath>
     40    <OutputPath>$(SolutionDir)\bin\</OutputPath>
    4141    <DefineConstants>DEBUG;TRACE</DefineConstants>
    4242    <DebugType>full</DebugType>
     
    4646  </PropertyGroup>
    4747  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
    48     <OutputPath>bin\x64\Release\</OutputPath>
     48    <OutputPath>$(SolutionDir)\bin\</OutputPath>
    4949    <DefineConstants>TRACE</DefineConstants>
    5050    <Optimize>true</Optimize>
     
    5656  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
    5757    <DebugSymbols>true</DebugSymbols>
    58     <OutputPath>bin\x86\Debug\</OutputPath>
     58    <OutputPath>$(SolutionDir)\bin\</OutputPath>
    5959    <DefineConstants>DEBUG;TRACE</DefineConstants>
    6060    <DebugType>full</DebugType>
     
    6464  </PropertyGroup>
    6565  <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
    66     <OutputPath>bin\x86\Release\</OutputPath>
     66    <OutputPath>$(SolutionDir)\bin\</OutputPath>
    6767    <DefineConstants>TRACE</DefineConstants>
    6868    <Optimize>true</Optimize>
     
    8686    <Compile Include="DeceptiveTrapProblem.cs" />
    8787    <Compile Include="HIFFProblem.cs" />
     88    <Compile Include="OneMaxProblem.cs" />
    8889    <Compile Include="Plugin.cs" />
    8990    <Compile Include="Properties\AssemblyInfo.cs" />
     
    148149  <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
    149150  <PropertyGroup>
    150     <PreBuildEvent>set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
    151 set ProjectDir=$(ProjectDir)
    152 set SolutionDir=$(SolutionDir)
    153 set Outdir=$(Outdir)
     151    <PreBuildEvent Condition=" '$(OS)' == 'Windows_NT' ">
     152      set Path=%25Path%25;$(ProjectDir);$(SolutionDir)
     153      set ProjectDir=$(ProjectDir)
     154      set SolutionDir=$(SolutionDir)
     155      set Outdir=$(Outdir)
    154156
    155 call PreBuildEvent.cmd
    156 </PreBuildEvent>
    157   </PropertyGroup>
     157      call PreBuildEvent.cmd
     158    </PreBuildEvent>
     159    <PreBuildEvent Condition=" '$(OS)' != 'Windows_NT' ">
     160      export ProjectDir=$(ProjectDir)
     161      export SolutionDir=$(SolutionDir)
     162
     163      $SolutionDir/PreBuildEvent.sh
     164    </PreBuildEvent>
     165  </PropertyGroup> 
    158166  <!-- To modify your build process, add your task inside one of the targets below and uncomment it.
    159167       Other similar extension points exist, see Microsoft.Common.targets.
  • stable/HeuristicLab.Problems.Binary/3.3/OneMaxProblem.cs

    r11990 r12005  
    3939    public OneMaxProblem()
    4040      : base() {
    41       Encoding = new BinaryVectorEncoding("BinaryVector", 10);
    42       BestKnownQuality = Length;
     41      Encoding.Length = 10;
     42      BestKnownQuality = Encoding.Length;
    4343    }
    4444
     
    4949    public override IDeepCloneable Clone(Cloner cloner) {
    5050      return new OneMaxProblem(this, cloner);
    51     }
    52 
    53     public override void Analyze(Individual[] individuals, double[] qualities, ResultCollection results, IRandom random) {
    54       base.Analyze(individuals, qualities, results, random);
    55       var best = individuals.Zip(qualities, (i, q) => new { Individual = i, Quality = q }).OrderByDescending(z => z.Quality).First();
    56       if (!results.ContainsKey("Best Solution")) {
    57         results.Add(new Result("Best Solution", typeof(BinaryVector)));
    58       }
    59       results["Best Solution"].Value = best.Individual.BinaryVector();
    6051    }
    6152
Note: See TracChangeset for help on using the changeset viewer.