Changeset 11791 for branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3
- Timestamp:
- 01/16/15 14:39:15 (10 years ago)
- Location:
- branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3
- Files:
-
- 1 deleted
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HeuristicLab.Algorithms.ParameterlessPopulationPyramid-3.3.csproj
r11669 r11791 103 103 </ItemGroup> 104 104 <ItemGroup> 105 <Compile Include="AlgorithmBase.cs" />106 105 <Compile Include="EnumerableBoolEqualityComparer.cs" /> 107 106 <Compile Include="LinkageCrossover.cs" /> -
branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/HillClimber.cs
r11672 r11791 20 20 #endregion 21 21 22 using System; 22 23 using System.Collections.Generic; 23 24 using System.Linq; 25 using System.Threading; 24 26 using HeuristicLab.Common; 25 27 using HeuristicLab.Core; 26 28 using HeuristicLab.Data; 27 using HeuristicLab.Encodings.BinaryVectorEncoding;28 29 using HeuristicLab.Optimization; 29 30 using HeuristicLab.Parameters; … … 37 38 [Creatable("Parameterless Population Pyramid")] 38 39 // In the GECCO paper, Section 2.1 39 public class HillClimber : AlgorithmBase{40 public class HillClimber : BasicAlgorithm { 40 41 [Storable] 41 42 private IRandom random; 42 43 43 44 private const string IterationsParameterName = "Iterations"; 45 46 public override Type ProblemType { 47 get { return typeof(BinaryVectorProblem); } 48 } 49 public new BinaryVectorProblem Problem { 50 get { return (BinaryVectorProblem)base.Problem; } 51 set { base.Problem = value; } 52 } 44 53 45 54 public IFixedValueParameter<IntValue> IterationsParameter { … … 66 75 Parameters.Add(new FixedValueParameter<IntValue>(IterationsParameterName, "", new IntValue(100))); 67 76 } 68 protected override void Run( ) {77 protected override void Run(CancellationToken cancellationToken) { 69 78 var BestQuality = new DoubleValue(double.NaN); 70 79 Results.Add(new Result("Best quality", BestQuality)); -
branches/Parameter-less Population Pyramid/HeuristicLab.Algorithms.ParameterlessPopulationPyramid/3.3/ParameterlessPopulationPyramid.cs
r11681 r11791 22 22 using System; 23 23 using System.Collections.Generic; 24 using System.Linq; 25 using System.Text; 26 using System.Threading.Tasks; 24 using System.Threading; 27 25 using HeuristicLab.Analysis; 28 26 using HeuristicLab.Common; … … 39 37 [StorableClass] 40 38 [Creatable("Parameterless Population Pyramid")] 41 42 public class ParameterlessPopulationPyramid : AlgorithmBase { 39 public class ParameterlessPopulationPyramid : BasicAlgorithm { 40 public override Type ProblemType { 41 get { return typeof(BinaryVectorProblem); } 42 } 43 public new BinaryVectorProblem Problem { 44 get { return (BinaryVectorProblem)base.Problem; } 45 set { base.Problem = value; } 46 } 47 43 48 private readonly IRandom random = new MersenneTwister(); 44 49 private List<Population> pyramid; … … 51 56 private const string MaximumIterationsParameterName = "Maximum Iterations"; 52 57 private const string MaximumEvaluationsParameterName = "Maximum Evaluations"; 58 private const string MaximumRuntimeParameterName = "Maximum Runtime"; 53 59 private const string SeedParameterName = "Seed"; 54 60 private const string SetSeedRandomlyParameterName = "SetSeedRandomly"; … … 61 67 public IFixedValueParameter<IntValue> MaximumEvaluationsParameter { 62 68 get { return (IFixedValueParameter<IntValue>)Parameters[MaximumEvaluationsParameterName]; } 69 } 70 public IFixedValueParameter<IntValue> MaximumRuntimeParameter { 71 get { return (IFixedValueParameter<IntValue>)Parameters[MaximumRuntimeParameterName]; } 63 72 } 64 73 public IFixedValueParameter<IntValue> SeedParameter { … … 75 84 set { MaximumIterationsParameter.Value.Value = value; } 76 85 } 77 78 86 public int MaximumEvaluations { 79 87 get { return MaximumEvaluationsParameter.Value.Value; } 80 88 set { MaximumEvaluationsParameter.Value.Value = value; } 81 89 } 82 90 public int MaximumRuntime { 91 get { return MaximumRuntimeParameter.Value.Value; } 92 set { MaximumRuntimeParameter.Value.Value = value; } 93 } 83 94 public int Seed { 84 95 get { return SeedParameter.Value.Value; } 85 96 set { SeedParameter.Value.Value = value; } 86 97 } 87 88 98 public bool SetSeedRandomly { 89 99 get { return SetSeedRandomlyParameter.Value.Value; } … … 151 161 public ParameterlessPopulationPyramid() { 152 162 Parameters.Add(new FixedValueParameter<IntValue>(MaximumIterationsParameterName, "", new IntValue(Int32.MaxValue))); 153 Parameters.Add(new FixedValueParameter<IntValue>(MaximumEvaluationsParameterName, "", new IntValue(10000))); 163 Parameters.Add(new FixedValueParameter<IntValue>(MaximumEvaluationsParameterName, "", new IntValue(Int32.MaxValue))); 164 Parameters.Add(new FixedValueParameter<IntValue>(MaximumRuntimeParameterName, "The maximum runtime in seconds after which the algorithm stops. Use -1 to specify no limit for the runtime", new IntValue(3600))); 154 165 Parameters.Add(new FixedValueParameter<IntValue>(SeedParameterName, "The random seed used to initialize the new pseudo random number generator.", new IntValue(0))); 155 166 Parameters.Add(new FixedValueParameter<BoolValue>(SetSeedRandomlyParameterName, "True if the random seed should be set to a random value, otherwise false.", new BoolValue(true))); 167 } 168 169 protected override void OnExecutionTimeChanged() { 170 base.OnExecutionTimeChanged(); 171 if (CancellationTokenSource == null) return; 172 if (MaximumRuntime == -1) return; 173 if (ExecutionTime.TotalSeconds > MaximumRuntime) CancellationTokenSource.Cancel(); 156 174 } 157 175 … … 190 208 } 191 209 192 protected override void Run( ) {210 protected override void Run(CancellationToken cancellationToken) { 193 211 // Set up the algorithm 194 212 if (SetSeedRandomly) Seed = new System.Random().Next(); … … 225 243 try { 226 244 fitness = iterate(); 227 } 228 catch (OperationCanceledException) { 229 throw; 245 cancellationToken.ThrowIfCancellationRequested(); 230 246 } 231 247 finally {
Note: See TracChangeset
for help on using the changeset viewer.