@@ -98,8 +98,6 @@ class MutationType:
9898 _maxdepthfirst = None
9999
100100 def __init__ (self , value , formal = None , complexity = None ):
101- self ._config = Config .get_instance ()
102-
103101 # Tree expression initialized using lazing initialization through
104102 # _tree property. Use self._tree instead of self._lazy_tree to
105103 # obtain the tree expression.
@@ -114,8 +112,8 @@ def __init__(self, value, formal=None, complexity=None):
114112 self ._complexity = self ._tree .complexity ()
115113 self ._value = self ._tree .get_expanded_tree_as_string ()
116114
117- self . _range = self . _config . getint ( "POPULATION" , "range" )
118- self . _precision = self . _config . getint ( "POPULATION" , "precision" )
115+ def get_config ():
116+ return Config . get_instance ( )
119117
120118 @property
121119 def _tree (self ):
@@ -188,9 +186,9 @@ def __crossover_tree(self, other_individual):
188186
189187 :return: (first new tree, second new tree) as strings
190188 """
191- maxtries = self . _config .getint ("GP" , "maxtries" )
192- mutmindepth = self . _config .getint ("GP" , "mutmindepth" )
193- maxdepth = self . _config .getint ("GP" , "maxdepth" )
189+ maxtries = Config . get_instance () .getint ("GP" , "maxtries" )
190+ mutmindepth = Config . get_instance () .getint ("GP" , "mutmindepth" )
191+ maxdepth = Config . get_instance () .getint ("GP" , "maxdepth" )
194192
195193 correct = False
196194 count = 0
@@ -218,11 +216,11 @@ def __crossover_tree(self, other_individual):
218216 return value_1 , value_2
219217
220218 def __mutate_tree (self , mutation_type ):
221- mutmindepth = self . _config .getint ("GP" , "mutmindepth" )
222- maxdepth = self . _config .getint ("GP" , "maxdepth" )
223- sensor_spec = self . _config .getboolean ("POPULATION" , "sensor_spec" )
224- sensors = self . _config .getint ("POPULATION" , 'sensors' )
225- mutation_types = self . _config .get_list ("GP" , 'mutation_types' )
219+ mutmindepth = Config . get_instance () .getint ("GP" , "mutmindepth" )
220+ maxdepth = Config . get_instance () .getint ("GP" , "maxdepth" )
221+ sensor_spec = Config . get_instance () .getboolean ("POPULATION" , "sensor_spec" )
222+ sensors = Config . get_instance () .getint ("POPULATION" , 'sensors' )
223+ mutation_types = Config . get_instance () .get_list ("GP" , 'mutation_types' )
226224
227225 # equi probability for each mutation type selected.
228226 if mutation_type == Individual .MutationType .ANY :
@@ -241,11 +239,12 @@ def __mutate_tree(self, mutation_type):
241239 else :
242240 next_individual_type = 4
243241
244- new_individual_value = Individual .__generate_indiv_regressive_tree (subtree , self ._config , next_individual_type )
242+ new_individual_value = Individual .__generate_indiv_regressive_tree (
243+ subtree , Config .get_instance (), next_individual_type )
245244
246245 if new_individual_value :
247246 if sensor_spec :
248- config_sensor_list = sorted (self . _config .get_list ('POPULATION' , 'sensor_list' ))
247+ config_sensor_list = sorted (Config . get_instance () .get_list ('POPULATION' , 'sensor_list' ))
249248 else :
250249 config_sensor_list = range (sensors - 1 , - 1 , - 1 )
251250
@@ -275,11 +274,11 @@ def __mutate_tree(self, mutation_type):
275274 elif mutation_type == Individual .MutationType .HOIST :
276275 preevok = False
277276 counter = 0
278- maxtries = self . _config .getint ("GP" , "maxtries" )
277+ maxtries = Config . get_instance () .getint ("GP" , "maxtries" )
279278
280279 while not preevok and counter < maxtries :
281280 counter += 1
282- controls = self . _config .getint ("POPULATION" , "controls" )
281+ controls = Config . get_instance () .getint ("POPULATION" , "controls" )
283282 prob_threshold = 1 / float (controls )
284283
285284 cl = [stree .to_string () for stree in self .get_tree ().get_root_node ()._nodes ]
@@ -336,8 +335,8 @@ def __extract_subtree(self, expression_tree, mindepth, subtreedepthmax, maxdepth
336335
337336 def __reparam_tree (self , tree_expression ):
338337 def leaf_value_generator ():
339- leaf_value = (RandomManager .rand () - 0.5 ) * 2 * self . _range
340- return "%0.*f" % (self . _precision , leaf_value )
338+ leaf_value = (RandomManager .rand () - 0.5 ) * 2 * Config . get_instance (). getint ( "POPULATION" , "range" )
339+ return "%0.*f" % (Config . get_instance (). getint ( "POPULATION" , "precision" ) , leaf_value )
341340
342341 return self .__change_const_tree (tree_expression , leaf_value_generator )
343342
0 commit comments