PonyGE / PonyGE2

PonyGE2: grammatical evolution and variants in Python
GNU General Public License v3.0
155 stars 92 forks source link

target in tree.get_target_nodes() #126

Closed mfjoneill closed 3 years ago

mfjoneill commented 3 years ago

def get_target_nodes(self, array, target=None)

get_target_nodes() could be generalised for any target symbol.

At present it is called, for example, during a tree mutation, and passed in the non-terminal symbols from the grammar as the target. From mutation.py...

targets = ind_tree.get_target_nodes([], target=params[ 'BNF_GRAMMAR'].non_terminals)

Of course it could be used differently to search for a specific node (e.g., a specific NT) to mutate by passing in a different target. The current implementation needlessly prevents this however by hard-coding a search for non-terminal symbols in the child nodes...

    NT_kids = [kid for kid in self.children if kid.root in
               params['BNF_GRAMMAR'].non_terminals]

...instead of simply specifying the input target.... NT_kids = [kid for kid in self.children if kid.root in target]