def read_from_file(self, filename): input_file = open(filename, 'r') lines = input_file.readlines() for line in lines: cell_type = line.split("(")[0] parenthesis = line.split('(', 1)[1].split(')')[0] values = list(map(int, parenthesis.split(","))) if cell_type == "GRID": self.cols = values[0] self.rows = values[1] elif cell_type == "P": self.elements['P'].append(Pedestrian((values[0], values[1]))) elif cell_type == "T": self.elements['T'] = Target((values[0], values[1])) elif cell_type == "O": self.elements['O'].append(Obstacle((values[0], values[1]))) elif cell_type == "CM1": self.elements['M'].append( Measure((values[0], values[1]), 'CM', 1, self.rows)) elif cell_type == "CM2": self.elements['M'].append( Measure((values[0], values[1]), 'CM', 2, self.rows)) elif cell_type == "MM": self.elements['M'].append( Measure((values[0], values[1]), 'MM', 0, self.rows))
def main(): screen = pygame.display.set_mode(size) pygame.display.set_caption('Smart Rocket') obs = np.empty(3, dtype=object) obs[0] = Obstacle(obsPosition1[0], obsPosition1[1]) obs[1] = Obstacle(obsPosition2[0], obsPosition2[1]) obs[2] = Obstacle(obsPosition3[0], obsPosition3[1]) target = Target(targetPosition) pop = Population(screen, amountOfRockets, lifeSpan, mutationRate, target) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.display.quit() sys.exit() ## evolving code pop.run(obs, target) obs[0].draw(screen) obs[1].draw(screen) obs[2].draw(screen) target.draw(screen) ## pygame.display.update() screen.fill((0, 0, 0))
def __init__(self): pygame.init() size = (WIDTH, HEIGHT) if FULLSCREEN: self.displaySurf = pygame.display.set_mode( size, pygame.HWSURFACE | pygame.FULLSCREEN) else: self.displaySurf = pygame.display.set_mode(size, pygame.HWSURFACE) self.population = Population() self.clock = pygame.time.Clock() self.target = Target() self.target.set_center(TARGETPOS) self.text = Text() self.obstacles = [Obstacle()]
def main(): t = Target(1) t.start()
root = tk.Tk() root.title("Genetic Algorithm in Heightmaps") canvas = tk.Canvas(master=root, width=width, height=height) photo = PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(cv_img)) canvas.create_image(0, 0, image=photo, anchor=tk.NW) target_radius = 5 target_x = width / 2 target_y = 25 target = Target( canvas.create_oval(target_x - target_radius, target_y - target_radius, target_x + target_radius, target_y + target_radius, width=0, fill=('red')), [target_x, 25], target_radius) canvas.pack() new_generation = '' previous_generation = '' generation = 1 n = 0 while generation <= 150: previous_generation = new_generation dots_number = dots_number_init