Changeset 12420 for branches/SymbolicExpressionTreeEncoding/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDuplicater.cs
- Timestamp:
- 06/10/15 10:49:31 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/SymbolicExpressionTreeEncoding/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/SubroutineDuplicater.cs
r12012 r12420 28 28 using HeuristicLab.Data; 29 29 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 30 using HeuristicLab.Random; 30 31 31 32 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 59 60 ISymbolicExpressionTree symbolicExpressionTree, 60 61 int maxFunctionDefinitions, int maxFunctionArguments) { 61 var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>() ;62 if ( functionDefiningBranches.Count() == 0|| functionDefiningBranches.Count() == maxFunctionDefinitions)62 var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>().ToList(); 63 if (!functionDefiningBranches.Any() || functionDefiningBranches.Count() == maxFunctionDefinitions) 63 64 // no function defining branches to duplicate or already reached the max number of ADFs 64 65 return false; … … 67 68 var allowedFunctionNames = from index in Enumerable.Range(0, maxFunctionDefinitions) 68 69 select "ADF" + index.ToString(formatString); 69 var selectedBranch = functionDefiningBranches.SelectRandom(random); 70 71 var selectedBranch = functionDefiningBranches.SampleRandom(random); 70 72 var duplicatedDefunBranch = (DefunTreeNode)selectedBranch.Clone(); 71 73 string newFunctionName = allowedFunctionNames.Except(UsedFunctionNames(symbolicExpressionTree)).First();
Note: See TracChangeset
for help on using the changeset viewer.