Changeset 5499 for branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SymbolicExpressionTreeCrossover.cs
- Timestamp:
- 02/16/11 19:01:00 (14 years ago)
- Location:
- branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4
- Property svn:ignore
-
old new 2 2 obj 3 3 HeuristicLabEncodingsSymbolicExpressionTreeEncodingPlugin.cs 4 *.user
-
- Property svn:ignore
-
branches/DataAnalysis Refactoring/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SymbolicExpressionTreeCrossover.cs
r5445 r5499 24 24 using HeuristicLab.Core; 25 25 using HeuristicLab.Data; 26 using HeuristicLab.Encodings.SymbolicExpressionTreeEncoding.Interfaces;27 26 using HeuristicLab.Parameters; 28 27 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 28 30 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding .Crossovers{29 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { 31 30 /// <summary> 32 31 /// A base class for operators that perform a crossover of symbolic expression trees. … … 37 36 private const string ParentsParameterName = "Parents"; 38 37 private const string ChildParameterName = "Child"; 39 private const string FailedCrossoverEventsParameterName = "FailedCrossoverEvents";38 #region Parameter Properties 40 39 public ILookupParameter<ItemArray<SymbolicExpressionTree>> ParentsParameter { 41 40 get { return (ScopeTreeLookupParameter<SymbolicExpressionTree>)Parameters[ParentsParameterName]; } … … 44 43 get { return (ILookupParameter<SymbolicExpressionTree>)Parameters[ChildParameterName]; } 45 44 } 46 public IValueParameter<IntValue> FailedCrossoverEventsParameter { 47 get { return (ValueParameter<IntValue>)Parameters[FailedCrossoverEventsParameterName]; } 45 #endregion 46 #region Properties 47 public ItemArray<SymbolicExpressionTree> Parents { 48 get { return ParentsParameter.ActualValue; } 48 49 } 49 50 public IntValue FailedCrossoverEvents {51 get { return FailedCrossoverEventsParameter.Value; }50 public SymbolicExpressionTree Child { 51 get { return ChildParameter.ActualValue; } 52 set { ChildParameter.ActualValue = value; } 52 53 } 54 #endregion 53 55 [StorableConstructor] 54 56 protected SymbolicExpressionTreeCrossover(bool deserializing) : base(deserializing) { } … … 58 60 Parameters.Add(new ScopeTreeLookupParameter<SymbolicExpressionTree>(ParentsParameterName, "The parent symbolic expression trees which should be crossed.")); 59 61 Parameters.Add(new LookupParameter<SymbolicExpressionTree>(ChildParameterName, "The child symbolic expression tree resulting from the crossover.")); 60 Parameters.Add(new ValueParameter<IntValue>(FailedCrossoverEventsParameterName, "The number of failed crossover events (child is an exact copy of a parent)", new IntValue()));61 62 } 62 63 63 64 public sealed override IOperation Apply() { 64 if (Parents Parameter.ActualValue.Length != 2)65 if (Parents.Length != 2) 65 66 throw new ArgumentException("Number of parents must be exactly two for symbolic expression tree crossover operators."); 66 67 67 SymbolicExpressionTree parent0 = ParentsParameter.ActualValue[0]; 68 SymbolicExpressionTree parent1 = ParentsParameter.ActualValue[1]; 68 SymbolicExpressionTree result = Cross(Random, Parents[0], Parents[1]); 69 69 70 IRandom random = RandomParameter.ActualValue; 71 72 bool success; 73 SymbolicExpressionTree result = Cross(random, parent0, parent1, 74 MaxTreeSizeParameter.ActualValue, MaxTreeHeightParameter.ActualValue, out success); 75 76 if (!success) FailedCrossoverEvents.Value++; 77 78 ChildParameter.ActualValue = result; 70 Child = result; 79 71 return base.Apply(); 80 72 } 81 73 82 74 protected abstract SymbolicExpressionTree Cross(IRandom random, 83 SymbolicExpressionTree parent0, SymbolicExpressionTree parent1, 84 IntValue maxTreeSize, IntValue maxTreeHeight, out bool success); 75 SymbolicExpressionTree parent0, SymbolicExpressionTree parent1); 85 76 } 86 77 }
Note: See TracChangeset
for help on using the changeset viewer.