def run_experiment(self): """ @brief Run the whole experiment. Does num_ga_iters genetic algorithm runs each containing num_atr iterations of ATR. """ #Run through a bunch of iterations generations = ([1]*self.config['atr_iterations'] + [2])*self.config['ga_iterations'] print "%s generations: {%s}"%(len(generations),', '.join(str(generation) for generation in generations)) #Start it up print "Running vanilla generation 0" self.run_remote_dispatcher_tasks() print "Generation %i complete"%self.gm.generation for generation,gen_type in enumerate(generations,1): #Get the resulting grasps for the latest generation of hands grasp_list = self.gm.get_all_grasps() #self.output_current_status() #Every num_atr_iters+1th iteration is a genetic swap if gen_type == 1: #Run atr on the existing hand for the latest generation of grasps new_hand_list = atr.ATR_generation(grasp_list, self.gm.hands) print "New hands generated through ATR on the results of generation %i"%self.gm.generation elif gen_type == 2: #Generate new hands based on these grasps, scaling the variance of the mutations down linearly as the #generations progress. new_hand_list = eigenhand_genetic_algorithm.GA_generation(grasp_list, self.gm.hands, self.eval_functor, .5-.4/(self.config['ga_iterations']*generation/(1+self.config['atr_iterations']))) print "New hands generated through genetic algorithm on the results of generation %i"%self.gm.generation #Put the new hands in to the database. eigenhand_db_tools.insert_unique_hand_list(new_hand_list, self.interface) #Backup results and then remove everything from the grasp table self.backup_results() self.interface.clear_tables(['grasp','job']) print "Backed up and reset for new generation" #Run the planner to get grasps for the last set of hands self.gm.next_generation(gen_type=gen_type) print "Starting generation %i"%self.gm.generation #Run the planning jobs self.run_remote_dispatcher_tasks() print "Finished generation %i"%self.gm.generation #Output the newest set of results thread.start_new_thread(output_results,[self.config['name']]) self.backup_results() print "Backed up final results" self.rd.kill_all_servers() print "Killed all servers"
def run_experiment(self): """ @brief Run the whole experiment. Does num_ga_iters genetic algorithm runs each containing num_atr iterations of ATR. """ #initialize new generation manager to configure the database to start running. self.initialize_generation_manager() self.gm.start_generation() for ga_gen_num in range(self.starting_ga_iter, self.num_ga_iters): for atr_gen_num in range(self.num_atr_iters): #Doing ATR #Run the planning jobs self.run_remote_dispatcher_tasks() #Get the resulting grasps for the latest generation of hands grasp_list = self.gm.get_all_grasps() self.output_current_status() #Run atr on the existing hand for the latest generation of grasps new_hand_list = atr.ATR_generation(grasp_list, self.gm.hands) #Update database with new hands eigenhand_db_tools.insert_unique_hand_list(new_hand_list, self.db_interface) #[hand.generation.append(self.gm.generation + 1) for hand in self.gm.hands] #[self.db_interface.update_hand_generation(hand) for hand in self.gm.hands] # Get the database ready to perform jobs for the next generation self.gm.next_generation() #DOING GA #run the planning jobs self.run_remote_dispatcher_tasks() #Get the resulting grasps for the latest generation of hands grasp_list = self.gm.get_all_grasps() self.output_current_status() #Generate new hands based on these grasps, scaling the variance of the mutations down linearly as the #generations progress. new_hand_list = eigenhand_genetic_algorithm.GA_generation(grasp_list, self.gm.hands, self.eval_functor, .5-.4/self.num_ga_iters*ga_gen_num) #Put the new hands in to the database. eigenhand_db_tools.insert_unique_hand_list(new_hand_list, self.db_interface) #[hand.generation.append(self.gm.generation + 1) for hand in self.gm.hands] #[self.db_interface.update_hand_generation(hand) for hand in self.gm.hands] #Backup old grasps and remove them from the grasp table self.backup_grasps(self.gm.generation) #Run the planner to get grasps for the last set of hands self.gm.next_generation() #Plan grasps for the final set of hands. self.run_remote_dispatcher_tasks() self.backup_grasps(self.gm.generation) self.backup_hands()
def load_up_robot(hand, interface): hand_list = [hand] eigenhand_db_tools.insert_unique_hand_list(hand_list, interface) print "New Hand ID: %d"%hand_list[0].hand_id s = socket.socket() s.connect(('localhost', 4765)) s.send('loadEigenhand %i \n'%(hand_list[0].hand_id)) output = s.recv(2048) if int(output.split(" ")[0]) == 0: raise ValueError("Could not load hand")
def load_up_robot(hand, interface): hand_list = [hand] eigenhand_db_tools.insert_unique_hand_list(hand_list, interface) print "New Hand ID: %d" % hand_list[0].hand_id s = socket.socket() s.connect(('localhost', 4765)) s.send('loadEigenhand %i \n' % (hand_list[0].hand_id)) output = s.recv(2048) if int(output.split(" ")[0]) == 0: raise ValueError("Could not load hand")
def DB_test_split_phalange(hand = None, test_load = True): interface = eigenhand_db_interface.EGHandDBaseInterface() hands = interface.load_hands_for_generation(0) if hand is None: test_hand = hands[0] else: test_hand = hand new_finger = eigenhand_genetic_algorithm.split_phalange(test_hand.fingers[0], 1) new_hand = copy.deepcopy(test_hand) new_hand.fingers[0] = new_finger hand_list = [new_hand] hand_list = eigenhand_db_tools.insert_unique_hand_list(hand_list, interface) if test_load: s = socket.socket() s.connect(('localhost', 4765)) s.send('loadEigenhand %i \n'%(hand_list[0].hand_id)) output = s.recv(2048) if int(output.split(" ")[0]) == 0: raise ValueError("could not load hand") return new_hand