Changeset 12005 for stable/HeuristicLab.Problems.Binary/3.3
- Timestamp:
- 02/13/15 15:00:15 (9 years ago)
- Location:
- stable
- Files:
-
- 5 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.Problems.Binary/3.3/BinaryProblem.cs
r11987 r12005 22 22 #endregion 23 23 24 using System; 25 using System.Linq; 24 26 using HeuristicLab.Common; 25 27 using HeuristicLab.Core; … … 33 35 [StorableClass] 34 36 public abstract class BinaryProblem : SingleObjectiveBasicProblem<BinaryVectorEncoding> { 35 36 37 public virtual int Length { 37 38 get { return Encoding.Length; } … … 39 40 } 40 41 42 private IFixedValueParameter<IntValue> LengthParameter { 43 get { return (IFixedValueParameter<IntValue>)Parameters["Length"]; } 44 } 45 41 46 [StorableConstructor] 42 47 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 } 45 65 46 66 public virtual bool IsBetter(double quality, double bestQuality) { … … 48 68 } 49 69 70 public abstract double Evaluate(BinaryVector vector, IRandom random); 50 71 public sealed override double Evaluate(Individual individual, IRandom random) { 51 72 return Evaluate(individual.BinaryVector(), random); 52 73 } 53 74 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) { } 55 97 } 56 98 } -
stable/HeuristicLab.Problems.Binary/3.3/DeceptiveTrapProblem.cs
r11987 r12005 66 66 : base() { 67 67 Parameters.Add(new FixedValueParameter<IntValue>(TrapSizeParameterName, "", new IntValue(7))); 68 Length = 49;68 Encoding.Length = 49; 69 69 } 70 70 -
stable/HeuristicLab.Problems.Binary/3.3/HIFFProblem.cs
r11987 r12005 48 48 public HIFFProblem() 49 49 : base() { 50 Length = 64;50 Encoding.Length = 64; 51 51 } 52 52 // In the GECCO paper, Section 4.1 -
stable/HeuristicLab.Problems.Binary/3.3/HeuristicLab.Problems.Binary-3.3.csproj
r11987 r12005 17 17 <DebugType>full</DebugType> 18 18 <Optimize>false</Optimize> 19 <OutputPath> ..\..\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> ..\..\bin\</OutputPath>27 <OutputPath>$(SolutionDir)\bin\</OutputPath> 28 28 <DefineConstants>TRACE</DefineConstants> 29 29 <ErrorReport>prompt</ErrorReport> … … 38 38 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'"> 39 39 <DebugSymbols>true</DebugSymbols> 40 <OutputPath> bin\x64\Debug\</OutputPath>40 <OutputPath>$(SolutionDir)\bin\</OutputPath> 41 41 <DefineConstants>DEBUG;TRACE</DefineConstants> 42 42 <DebugType>full</DebugType> … … 46 46 </PropertyGroup> 47 47 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'"> 48 <OutputPath> bin\x64\Release\</OutputPath>48 <OutputPath>$(SolutionDir)\bin\</OutputPath> 49 49 <DefineConstants>TRACE</DefineConstants> 50 50 <Optimize>true</Optimize> … … 56 56 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'"> 57 57 <DebugSymbols>true</DebugSymbols> 58 <OutputPath> bin\x86\Debug\</OutputPath>58 <OutputPath>$(SolutionDir)\bin\</OutputPath> 59 59 <DefineConstants>DEBUG;TRACE</DefineConstants> 60 60 <DebugType>full</DebugType> … … 64 64 </PropertyGroup> 65 65 <PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'"> 66 <OutputPath> bin\x86\Release\</OutputPath>66 <OutputPath>$(SolutionDir)\bin\</OutputPath> 67 67 <DefineConstants>TRACE</DefineConstants> 68 68 <Optimize>true</Optimize> … … 86 86 <Compile Include="DeceptiveTrapProblem.cs" /> 87 87 <Compile Include="HIFFProblem.cs" /> 88 <Compile Include="OneMaxProblem.cs" /> 88 89 <Compile Include="Plugin.cs" /> 89 90 <Compile Include="Properties\AssemblyInfo.cs" /> … … 148 149 <Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" /> 149 150 <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) 154 156 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> 158 166 <!-- To modify your build process, add your task inside one of the targets below and uncomment it. 159 167 Other similar extension points exist, see Microsoft.Common.targets. -
stable/HeuristicLab.Problems.Binary/3.3/OneMaxProblem.cs
r11990 r12005 39 39 public OneMaxProblem() 40 40 : base() { 41 Encoding = new BinaryVectorEncoding("BinaryVector", 10);42 BestKnownQuality = Length;41 Encoding.Length = 10; 42 BestKnownQuality = Encoding.Length; 43 43 } 44 44 … … 49 49 public override IDeepCloneable Clone(Cloner cloner) { 50 50 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();60 51 } 61 52
Note: See TracChangeset
for help on using the changeset viewer.