- Timestamp:
- 02/13/15 15:00:15 (10 years ago)
- Location:
- stable
- Files:
-
- 2 edited
- 1 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 }
Note: See TracChangeset
for help on using the changeset viewer.