def reset(self): self.fitnesses = np.full((1, self.pop_size), -100.0) # init to -100 # array of population indexes self.net_ids = np.arange(self.pop_size).reshape(1, self.pop_size) # initialize robot angles (1, pop_size) self.robot_angles = np.full( (1, self.pop_size), utils.to_minus_pi_pi(self.conf.init_rotation)) # initialize sensor angles of robots self.sensor_angles = np.zeros( (len(self.robot.sensor_angles), self.pop_size)) + utils.to_minus_pi_pi(self.robot.sensor_angles) # initialize robot positions (1, pop_size, 2) self.robot_positions = np.full((1, self.pop_size, 2), self.map.start_point) self.robot_bodies = np.add(self.robot.body, np.rint(self.robot_positions)).astype(int) self.sensor_lines = self.__update_sensor_lines() # calculate angle errors and then normalize them self.angle_errors = self.__update_angle_errors() self.normalized_angle_errors = self.__normalize_angle_errors() # calculate target distances and then normalize them self.target_distances = self.__update_target_distances() self.normalized_target_distances = self.__normalize_target_distances() self.max_distance_from_start = np.zeros((1, self.pop_size))
def reset(self, pop_size=None): if pop_size is not None: self.pop_size = pop_size self.fits = np.full((1, self.pop_size), -100000.0) # init fitness to -100000 # initialize robot angles (1, pop_size) self.robot_angles = np.full((1, self.pop_size), utils.to_minus_pi_pi(self.init_rotation)) # initialize sensor angles of robots self.sensor_angles = np.zeros( (len(self.robot.sensor_angles), self.pop_size)) + utils.to_minus_pi_pi(self.robot.sensor_angles) # initialize robot positions (1, pop_size, 2) self.robot_positions = np.full((1, self.pop_size, 2), self.sim_map.start_point) self.robot_bodies = np.add(self.robot.body, np.rint(self.robot_positions)).astype(int) self.sensor_lines = self.__update_sensor_lines() # calculate angle errors and then normalize them self.angle_errors = self.__update_angle_errors() self.normalized_angle_errors = self.__normalize_angle_errors() # calculate target distances and then normalize them self.target_distances = self.__update_target_distances() self.normalized_target_distances = self.__normalize_target_distances() self.max_distance_from_start = np.zeros((1, self.pop_size)) self.collision_counters = np.zeros((1, self.pop_size)) self.cumulative_angle_errs = np.zeros((1, self.pop_size)) self.fig = None self.img = None
def __rotate(self, delta_angles): self.robot_angles = utils.to_minus_pi_pi( np.add(self.robot_angles, delta_angles)) self.sensor_angles = utils.to_minus_pi_pi( np.add(self.sensor_angles, delta_angles)) return self.robot_angles, self.sensor_angles
def __update_angle_errors(self): self.angle_errors = utils.calc_angle_error(self.robot_positions, self.map.end_point, self.robot_angles) self.angle_errors = utils.to_minus_pi_pi(self.angle_errors) return self.angle_errors