Changeset 12891 for branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDuplicater.cs
- Timestamp:
- 08/22/15 14:27:37 (9 years ago)
- Location:
- branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Property svn:mergeinfo changed
-
branches/HeuristicLab.EvolutionTracking/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDuplicater.cs
r12155 r12891 27 27 using HeuristicLab.Data; 28 28 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 29 using HeuristicLab.Random; 29 30 30 31 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 56 57 ISymbolicExpressionTree symbolicExpressionTree, 57 58 int maxFunctionDefinitions, int maxFunctionArguments) { 58 var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>() ;59 var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>().ToList(); 59 60 60 61 var allowedArgumentIndexes = Enumerable.Range(0, maxFunctionArguments); 61 if ( functionDefiningBranches.Count() == 0)62 if (!functionDefiningBranches.Any()) 62 63 // no function defining branches => abort 63 64 return false; 64 65 65 var selectedDefunBranch = functionDefiningBranches.SelectRandom(random); 66 var argumentSymbols = selectedDefunBranch.Grammar.Symbols.OfType<Argument>(); 67 if (argumentSymbols.Count() == 0 || argumentSymbols.Count() >= maxFunctionArguments) 66 var selectedDefunBranch = functionDefiningBranches.SampleRandom(random); 67 68 var argumentSymbols = selectedDefunBranch.Grammar.Symbols.OfType<Argument>().ToList(); 69 if (!argumentSymbols.Any() || argumentSymbols.Count() >= maxFunctionArguments) 68 70 // when no argument or number of arguments is already at max allowed value => abort 69 71 return false; 70 var selectedArgumentSymbol = argumentSymbols.SelectRandom(random); 72 73 var selectedArgumentSymbol = argumentSymbols.SampleRandom(random); 71 74 var takenIndexes = argumentSymbols.Select(s => s.ArgumentIndex); 72 75 var newArgumentIndex = allowedArgumentIndexes.Except(takenIndexes).First();
Note: See TracChangeset
for help on using the changeset viewer.