@@ -42,7 +42,7 @@ class Neighborhood:
4242 TRANSLATION_LIST = [0.09 , 0.3 , 1.0 ]
4343
4444 def __init__ (self , neighborhood_config : NeighborhoodConfig ,
45- home_coordinate : Coordinate ):
45+ home_coordinate : Coordinate , coordinate_data : CoordinateData ):
4646 """
4747 Parameters
4848 ----------
@@ -55,17 +55,13 @@ def __init__(self, neighborhood_config: NeighborhoodConfig,
5555
5656 self ._config = neighborhood_config
5757 self ._home_coordinate = home_coordinate
58- self ._coordinate_data = CoordinateData ()
58+ self ._coordinate_data = coordinate_data
5959
6060 self ._radius = self ._config .get_radius ()
6161 self ._neighborhood = self ._create_neighborhood ()
6262
6363 self ._force_slow_mode = False
6464
65- @property
66- def coordinate_data (self ):
67- return self ._coordinate_data
68-
6965 @classmethod
7066 def calc_distance (cls , coordinate1 : Coordinate ,
7167 coordinate2 : Coordinate ) -> float :
@@ -83,16 +79,17 @@ def calc_distance(cls, coordinate1: Coordinate,
8379 def enough_coordinates_initialized (self ) -> bool :
8480 """
8581 Returns true if enough coordinates inside of the neighborhood
86- have been initialized. Else false
82+ have been initialized with valid measurements . Else false
8783
8884 If the neighborhood is in slow mode, this means all adjacent neighbors
8985 must be visited
9086 """
9187 if self ._is_slow_mode ():
92- return self ._are_all_adjacent_neighbors_visited ()
88+ return self ._are_all_adjacent_neighbors_measured ()
9389 else :
9490 min_initialized = self ._config .get_min_initialized ()
95- num_initialized = len (self ._get_initialized_coordinates ())
91+ num_initialized = len (
92+ self ._get_coordinates_with_valid_measurements ())
9693 return num_initialized >= min_initialized
9794
9895 def force_slow_mode (self ):
@@ -178,7 +175,7 @@ def pick_coordinate_to_initialize(self) -> Optional[Coordinate]:
178175
179176 def _pick_slow_mode_coordinate_to_initialize (self ):
180177 for neighbor in self ._get_all_adjacent_neighbors ():
181- if not self ._is_coordinate_visited (neighbor ):
178+ if not self ._is_coordinate_measured (neighbor ):
182179 return neighbor
183180
184181 raise Exception ("Picking slow mode coordinate, but none are unvisited" )
@@ -189,7 +186,7 @@ def _pick_fast_mode_coordinate_to_initialize(self):
189186 max_num_uncovered = - 1
190187 best_coordinate = None
191188 for coordinate in self ._neighborhood :
192- if not self ._is_coordinate_visited (coordinate ):
189+ if not self ._is_coordinate_measured (coordinate ):
193190 num_uncovered = self ._get_num_uncovered_values (
194191 coordinate , covered_values_per_dimension )
195192
@@ -257,23 +254,11 @@ def _enumerate_all_values_in_bounds(
257254 tuples = list (product (* possible_index_values ))
258255 return [list (x ) for x in tuples ]
259256
260- def _get_visited_coordinates (self ) -> List [Coordinate ]:
261- """
262- Returns the list of coordinates in the neighborhood that have been
263- visited (except the home coordinate).
264- """
265- visited_coordinates = []
266- for coordinate in self ._neighborhood :
267- if coordinate != self ._home_coordinate \
268- and self ._is_coordinate_visited (coordinate ):
269- visited_coordinates .append (deepcopy (coordinate ))
270- return visited_coordinates
271-
272- def _get_initialized_coordinates (self ) -> List [Coordinate ]:
257+ def _get_coordinates_with_valid_measurements (self ) -> List [Coordinate ]:
273258 initialized_coordinates = []
274259 for coordinate in self ._neighborhood :
275- if coordinate != self ._home_coordinate \
276- and self . _is_coordinate_initialized ( coordinate ):
260+ if coordinate != self ._home_coordinate and self . _coordinate_data . has_valid_measurement (
261+ coordinate ):
277262 initialized_coordinates .append (deepcopy (coordinate ))
278263 return initialized_coordinates
279264
@@ -296,7 +281,7 @@ def _calculate_step_vector_from_measurements(
296281 self , compare_constraints : bool ) -> Coordinate :
297282
298283 home_measurement = self ._get_home_measurement ()
299- vectors , measurements = self ._get_all_visited_measurements ()
284+ vectors , measurements = self ._get_all_measurements ()
300285
301286 # This function should only ever be called if all are passing or none are passing
302287 _ , p = self ._get_measurements_passing_constraints ()
@@ -340,7 +325,7 @@ def _calculate_step_vector_from_vectors_and_weights(self, vectors, weights):
340325
341326 return step_vector
342327
343- def _get_all_visited_measurements (
328+ def _get_all_measurements (
344329 self ) -> Tuple [List [Coordinate ], List [RunConfigMeasurement ]]:
345330 """
346331 Gather all the visited vectors (directions from the home coordinate)
@@ -351,10 +336,11 @@ def _get_all_visited_measurements(
351336 (vectors, measurements)
352337 collection of vectors and their measurements.
353338 """
354- visited_coordinates = self ._get_visited_coordinates ()
339+ coordinates = self ._get_coordinates_with_valid_measurements ()
340+
355341 vectors = []
356342 measurements = []
357- for coordinate in visited_coordinates :
343+ for coordinate in coordinates :
358344 measurement = self ._coordinate_data .get_measurement (coordinate )
359345 if measurement :
360346 vectors .append (coordinate - self ._home_coordinate )
@@ -372,22 +358,19 @@ def _get_measurements_passing_constraints(
372358 (vectors, measurements)
373359 collection of vectors and their measurements.
374360 """
375- visited_coordinates = self ._get_visited_coordinates ()
361+ coordinates = self ._get_coordinates_with_valid_measurements ()
376362
377363 vectors = []
378364 measurements = []
379- for coordinate in visited_coordinates :
365+ for coordinate in coordinates :
380366 measurement = self ._coordinate_data .get_measurement (coordinate )
381367 if measurement and measurement .is_passing_constraints ():
382368 vectors .append (coordinate - self ._home_coordinate )
383369 measurements .append (measurement )
384370 return vectors , measurements
385371
386- def _is_coordinate_visited (self , coordinate : Coordinate ) -> bool :
387- return self ._coordinate_data .get_visit_count (coordinate ) > 0
388-
389- def _is_coordinate_initialized (self , coordinate : Coordinate ) -> bool :
390- return self ._coordinate_data .get_measurement (coordinate ) is not None
372+ def _is_coordinate_measured (self , coordinate : Coordinate ) -> bool :
373+ return self ._coordinate_data .is_measured (coordinate )
391374
392375 def _clamp_coordinate_to_bounds (self , coordinate : Coordinate ) -> Coordinate :
393376
@@ -409,13 +392,13 @@ def _get_covered_values_per_dimension(self) -> List[Dict[Coordinate, bool]]:
409392 (e.g.)
410393 covered_values_per_dimension[dimension][value] = bool
411394 """
412- visited_coordinates = self ._get_visited_coordinates ()
395+ measured_coordinates = self ._get_coordinates_with_valid_measurements ()
413396
414397 covered_values_per_dimension : List [Dict [Coordinate , bool ]] = [
415398 {} for _ in range (self ._config .get_num_dimensions ())
416399 ]
417400
418- for coordinate in visited_coordinates :
401+ for coordinate in measured_coordinates :
419402 for i , v in enumerate (coordinate ):
420403 covered_values_per_dimension [i ][v ] = True
421404
@@ -444,7 +427,7 @@ def _is_slow_mode(self):
444427 return False
445428
446429 passing_vectors , _ = self ._get_measurements_passing_constraints ()
447- all_vectors , _ = self ._get_all_visited_measurements ()
430+ all_vectors , _ = self ._get_all_measurements ()
448431
449432 any_failing = len (all_vectors ) != len (passing_vectors )
450433 any_passing = len (passing_vectors ) != 0
@@ -453,9 +436,9 @@ def _is_slow_mode(self):
453436 return (home_passing and any_failing ) or (not home_passing and
454437 any_passing )
455438
456- def _are_all_adjacent_neighbors_visited (self ):
439+ def _are_all_adjacent_neighbors_measured (self ):
457440 for neighbor in self ._get_all_adjacent_neighbors ():
458- if not self ._is_coordinate_visited (neighbor ):
441+ if not self ._is_coordinate_measured (neighbor ):
459442 return False
460443 return True
461444
0 commit comments