break if g >= 5: diff = np.abs(self.history[-5][1] - self.history[-1][1]) if diff < 1e-2: print('The best fitness does not change for 10 steps.') break self.gtot += 1 if __name__ == '__main__': # World world = World() world.generate_frame([-10, 10], [-10, 10]) world.type = 'cartesian' # Objects in the cartesian space og = ObjectGenerator(world) og.generate_object([[3.5, 6.5], [3.5, 3.5], [6.5, 3.5], [6.5, 6.5]]) # Robot robot2R = RobotArm(base=[0, 0], lengths=[3.0, 5.0]) robot2R.start = np.array([pi / 2, -pi / 7]) robot2R.goal = np.array([pi / 5, -pi / 7]) # C-space cspace = World() cspace.robot = robot2R cspace.generate_frame([-pi, pi], [-pi, pi]) cspace.start = cspace.robot.start
if diff < 1e-2: print('The best fitness does not change for 10 steps.') break self.gtot += 1 if __name__ == '__main__': ''' World setting ''' # World world = World() world.generate_frame([-pi, pi], [-pi, pi]) world.type = 'cartesian' # Objects in the cartesian space og = ObjectGenerator(world) og.generate_object_sample1() # --- Set start/goal point world.start = np.array([-pi / 2, -pi / 2]) * 1.9 world.goal = np.array([pi / 2, pi / 2]) * 1.9 ''' Functions ''' NGEN = 1000 n_ind = 100 n_elite = 10 fitness_thresh = 0.1