def simulate_cruise_control(controller, hill=False): # Setup car = Car(constants.CAR_MASS) traj = Reference(CRUISE_CONTROL_TEST, offset=car.length/2) if hill: world = World(constants.HILL_SLOPE, hill=True) else: world = World(constants.GROUND_HEIGHT) # Simulate and animate results = simulate(car, world, traj, controller, slope=hill) animate(world, [results]) return results
def main(args): with tf.Session() as sess: env = World() np.random.seed(int(args['random_seed'])) tf.set_random_seed(int(args['random_seed'])) state_dim = env.observation_space.shape[0] action_dim = env.action_space.shape[0] action_bound = env.action_space.high # Ensure action bound is symmetric assert (env.action_space.high == -env.action_space.low) actor = ActorNetwork(sess, state_dim, action_dim, action_bound, float(args['actor_lr']), float(args['tau']), int(args['minibatch_size'])) saver = tf.train.Saver(max_to_keep=5) latest_checkpoint = tf.train.latest_checkpoint('./models/ddpg/') saver.restore(sess, latest_checkpoint) while (True): observation, reward, done = env.reset(), 0, False throw_away_action = actor.predict([observation]) # prime network. while (True): action = actor.predict([observation]) observation, reward, done = env.step(action) if observation == False: # some sort of error communicating w Arduino done = False # prob not needed (already false) but just to be safe break # lets try another rollout if done: break
def test_outofbounds(): env = World(10, 10, 0.2) free_tiles = env.list_available_tiles() new_node = [Node(i, 84, 0, None, env) for i in free_tiles] for elem in new_node: assert (elem.tile_pos >= 0 and elem.tile_pos <= (env.L * env.H))
def generate_world(): length = random.randint(10, 50) height = random.randint(10, 50) w_percentage = random.random() / 4 env = World(length, height, w_percentage) print(str(length) + "x" + str(height) + "x" + str(w_percentage)) return env
def __init__(self, args): self.args = args self.env = World() # Pin Setup: self.buttonPin = 4 GPIO.setmode(GPIO.BCM) GPIO.setup(self.buttonPin, GPIO.IN, pull_up_down=GPIO.PUD_UP)
def test_availability(): env = World(10, 10, 0.2) free_tiles = env.list_available_tiles() new_node = [Node(i, 84, 0, None, env) for i in free_tiles] for elem in new_node: assert (env.w[elem.tile_pos] != 1)
def test_uniqueness(): env = World(10, 10, 0.2) free_tiles = env.list_available_tiles() nodes = [Node(i, 84, 0, None, env) for i in free_tiles] # list of positions pos = [] for elem in nodes: pos.append(elem.tile_pos) # check uniqueness seen = set() uniqueness = not any(k in seen or seen.add(k) for k in pos) assert (uniqueness == True)
def runAll(self, n_times): env = self.env costLists = {} for alg in self.algorithms.keys(): costLists[alg] = [] timeLists = {} for alg in self.algorithms.keys(): timeLists[alg] = [] for i in range(n_times): # Computation for alg in self.algorithms.keys(): path, time = self.algorithms[alg]() costLists[alg].append(path["Costs"][-1]) timeLists[alg].append(time) print(alg + " successfully computed.") self.setEnv(World(env.L, env.H, env.pWalls), self.diagonals) self.plotPaths() return costLists, timeLists
def main(): """ Prepara las ventanas, define modelos, controlador y vista y corre el programa. :return: void """ # Se obtiene el checksum del juego checksum = [ path_checksum('lib', VERBOSE), '8e1fd1c03d2bfe89d7dbdab8b0c4c69a'.upper(), path_checksum('bin', VERBOSE) ] # Se cargan las configuraciones control_config = Configloader(DIR_CONFIG + 'control.ini', verbose=VERBOSE) game_config = Configloader(DIR_CONFIG + 'game.ini', verbose=VERBOSE) map_config = Configloader(DIR_CONFIG + 'map.ini', verbose=VERBOSE) score_config = Configloader(DIR_CONFIG + 'scoreboard.ini', verbose=VERBOSE) user_config = Configloader(DIR_CONFIG + 'user.ini', verbose=VERBOSE) view_config = Configloader(DIR_CONFIG + 'view.ini', verbose=VERBOSE) window_config = Configloader(DIR_CONFIG + 'window.ini', verbose=VERBOSE) world_config = Configloader(DIR_CONFIG + 'world.ini', verbose=VERBOSE) # Se carga el idioma lang = langs.Langloader(game_config.getValue('LANG')) # Se carga la información de la pantalla del cliente display_info = pygame.display.Info() # Se comprueba que el nombre de jugador no sea Player, si no es valido se pide uno nuevo if not username.validate(user_config.getValue('NAME')): new_name = username.request(lang.get(111), lang.get(112)) if new_name is not username.NO_VALID_NAME: user_config.setParameter('NAME', new_name) user_config.export() else: utils.destroy_process() # Creación de ventana window = Window(window_config, lang.get(10), pygame.image.load(getIcons('icon')), display_info) clock = pygame.time.Clock() # Reloj fps = int(game_config.getValue('FPS')) # FPS a dibujar # Se crea el mundo world = World(world_config, map_config, window, checksum, score_config, user_config, lang, game_config, verbose=VERBOSE) # world.load_map(1) # Se crean los menús de inicio y pause menus = Createuimenu(lang, window, world, game_config, user_config, view_config, window_config, world_config, map_config) # Se crea la vista vista = View(window, clock, world, lang, view_config, menus) menus.addView(vista) # Se crea el controlador control = Controller(world, clock, lang, control_config, window, menus, verbose=VERBOSE) menus.addController(control) vista.add_controller(control) # Se lanza el mainloop while True: clock.tick(fps) vista.draw(control.event_loop())
import numpy as np from lib.world import World world = World() world.arduino.give_robot_slack()
pathfinder.plotPaths() def computeAndDisplayDijkstra(pathfinder): path, time = pathfinder.computePathDijkstra() pathfinder.plotPaths() def computeAndDisplayDFS(pathfinder): path, time = pathfinder.computePathDFS() pathfinder.displayEnv() def computeAndDisplayBidirAStar(pathfinder): path, time = pathfinder.computePathBidirAStar() pathfinder.plotPaths() def showComparisonPlots(pathfinder, test_samples): pathfinder_api.benchmark(test_samples, True, True) if __name__ == "__main__": env = World(filename="worlds/colliders.csv") pathfinder_api = PathFinder(env) #pathfinder_api.displayEnvFigure() showComparisonPlots(pathfinder_api, 10) #computeAndDisplayDFS(pathfinder_api) #computeAndDisplayAStar(pathfinder_api) #computeAndDisplayDijkstra(pathfinder_api) #computeAndDisplayBidirAStar(pathfinder_api)
import sys import time if __name__ == '__main__': pygame.init() WIDTH = 800 HEIGHT = 800 SCREEN_SIZE = (WIDTH, HEIGHT) clock = pygame.time.Clock() screen = pygame.display.set_mode(SCREEN_SIZE, 0, 32) pixels_per_sec = 10 world = World(SCREEN_SIZE) gen_h = True gen_c = True # Add Creatures for i in range(50): world.add_creture(Plant(world)) time.sleep(0.01) for i in range(15): world.add_creture(Herbivore(world, gender=gen_h)) time.sleep(0.01) world.add_creture(Carnivore(world, gender=gen_c)) time.sleep(0.01) gen_c = not gen_c
def __init__(self, args): self.args = args self.env = World()