Changeset 12422 for trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers
- Timestamp:
- 06/10/15 11:29:34 (10 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SubtreeCrossover.cs
r12012 r12422 28 28 using HeuristicLab.Parameters; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Random; 30 31 31 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 181 182 select branch).ToList(); 182 183 if (allowedInternalBranches.Count > 0) { 183 return allowedInternalBranches.SelectRandom(random); 184 return allowedInternalBranches.SampleRandom(random); 185 184 186 } else { 185 187 // no internal nodes allowed => select leaf nodes … … 187 189 where branch == null || branch.SubtreeCount == 0 188 190 select branch).ToList(); 189 return allowedLeafBranches.S electRandom(random);191 return allowedLeafBranches.SampleRandom(random); 190 192 } 191 193 } else { … … 195 197 select branch).ToList(); 196 198 if (allowedLeafBranches.Count > 0) { 197 return allowedLeafBranches.S electRandom(random);199 return allowedLeafBranches.SampleRandom(random); 198 200 } else { 199 201 allowedInternalBranches = (from branch in branches 200 202 where branch != null && branch.SubtreeCount > 0 201 203 select branch).ToList(); 202 return allowedInternalBranches.SelectRandom(random); 204 return allowedInternalBranches.SampleRandom(random); 205 203 206 } 204 207 } -
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/Crossovers/SymbolicExpressionTreeCrossover.cs
r12012 r12422 34 34 public abstract class SymbolicExpressionTreeCrossover : SymbolicExpressionTreeOperator, ISymbolicExpressionTreeCrossover { 35 35 private const string ParentsParameterName = "Parents"; 36 private const string ChildParameterName = "Child";37 36 #region Parameter Properties 38 37 public ILookupParameter<ItemArray<ISymbolicExpressionTree>> ParentsParameter { 39 38 get { return (ScopeTreeLookupParameter<ISymbolicExpressionTree>)Parameters[ParentsParameterName]; } 40 39 } 41 public ILookupParameter<ISymbolicExpressionTree> ChildParameter {42 get { return (ILookupParameter<ISymbolicExpressionTree>)Parameters[ChildParameterName]; }43 }44 40 #endregion 45 41 #region Properties 46 p ublicItemArray<ISymbolicExpressionTree> Parents {42 private ItemArray<ISymbolicExpressionTree> Parents { 47 43 get { return ParentsParameter.ActualValue; } 48 44 } 49 p ublicISymbolicExpressionTree Child {50 get { return ChildParameter.ActualValue; }51 set { ChildParameter.ActualValue = value; }45 private ISymbolicExpressionTree Child { 46 get { return SymbolicExpressionTreeParameter.ActualValue; } 47 set { SymbolicExpressionTreeParameter.ActualValue = value; } 52 48 } 53 49 #endregion … … 58 54 : base() { 59 55 Parameters.Add(new ScopeTreeLookupParameter<ISymbolicExpressionTree>(ParentsParameterName, "The parent symbolic expression trees which should be crossed.")); 60 Parameters.Add(new LookupParameter<ISymbolicExpressionTree>(ChildParameterName, "The child symbolic expression tree resulting from the crossover."));61 56 ParentsParameter.ActualName = "SymbolicExpressionTree"; 62 ChildParameter.ActualName = "SymbolicExpressionTree";63 57 } 64 58 … … 67 61 throw new ArgumentException("Number of parents must be exactly two for symbolic expression tree crossover operators."); 68 62 69 ISymbolicExpressionTree result = Crossover(Random , Parents[0], Parents[1]);63 ISymbolicExpressionTree result = Crossover(RandomParameter.ActualValue, Parents[0], Parents[1]); 70 64 71 65 Child = result;
Note: See TracChangeset
for help on using the changeset viewer.