Changeset 12422 for trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDeleter.cs
- Timestamp:
- 06/10/15 11:29:34 (9 years ago)
- Location:
- trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding
-
trunk/sources/HeuristicLab.Encodings.SymbolicExpressionTreeEncoding/3.4/ArchitectureManipulators/ArgumentDeleter.cs
r12012 r12422 25 25 using HeuristicLab.Data; 26 26 using HeuristicLab.Persistence.Default.CompositeSerializers.Storable; 27 using HeuristicLab.Random; 27 28 28 29 namespace HeuristicLab.Encodings.SymbolicExpressionTreeEncoding { … … 54 55 int maxFunctionDefinitions, int maxFunctionArguments) { 55 56 56 var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>() ;57 if ( functionDefiningBranches.Count() == 0)57 var functionDefiningBranches = symbolicExpressionTree.IterateNodesPrefix().OfType<DefunTreeNode>().ToList(); 58 if (!functionDefiningBranches.Any()) 58 59 // no function defining branch => abort 59 60 return false; 60 var selectedDefunBranch = functionDefiningBranches.SelectRandom(random); 61 62 var selectedDefunBranch = functionDefiningBranches.SampleRandom(random); 61 63 if (selectedDefunBranch.NumberOfArguments <= 1) 62 64 // argument deletion by consolidation is not possible => abort … … 77 79 78 80 // delete the dynamic argument symbol that matches the argument to be removed 79 var matchingSymbol = selectedDefunBranch.Grammar.Symbols.OfType<Argument>(). Where(s => s.ArgumentIndex == removedArgument).Single();81 var matchingSymbol = selectedDefunBranch.Grammar.Symbols.OfType<Argument>().Single(s => s.ArgumentIndex == removedArgument); 80 82 selectedDefunBranch.Grammar.RemoveSymbol(matchingSymbol); 81 83 selectedDefunBranch.NumberOfArguments--; 82 84 // reduce arity in known functions of all root branches 83 85 foreach (var subtree in symbolicExpressionTree.Root.Subtrees) { 84 var matchingInvokeSymbol = subtree.Grammar.Symbols.OfType<InvokeFunction>(). Where(s => s.FunctionName == selectedDefunBranch.FunctionName).SingleOrDefault();86 var matchingInvokeSymbol = subtree.Grammar.Symbols.OfType<InvokeFunction>().SingleOrDefault(s => s.FunctionName == selectedDefunBranch.FunctionName); 85 87 if (matchingInvokeSymbol != null) { 86 88 subtree.Grammar.SetSubtreeCount(matchingInvokeSymbol, selectedDefunBranch.NumberOfArguments, selectedDefunBranch.NumberOfArguments); … … 99 101 select node; 100 102 foreach (var argNode in argNodes) { 101 var replacementSymbol = possibleArgumentSymbols.S electRandom(random);103 var replacementSymbol = possibleArgumentSymbols.SampleRandom(random); 102 104 argNode.Symbol = replacementSymbol; 103 105 }
Note: See TracChangeset
for help on using the changeset viewer.