def __init__(self, team_type): NeroTeam.__init__(self, team_type) self.pop = OpenNero.Population() self.rtneat = OpenNero.RTNEAT("data/ai/neat-params.dat", self.pop, constants.DEFAULT_LIFETIME_MIN, constants.DEFAULT_EVOLVE_RATE) self.generation = 1
def __init__(self): """ Create the environment """ OpenNero.Environment.__init__(self) self.curr_id = 0 self.max_steps = 20 self.MAX_DIST = math.hypot(constants.XDIM, constants.YDIM) self.states = {} self.teams = {} self.script = 'Hw5/menu.py' abound = OpenNero.FeatureVectorInfo() # actions sbound = OpenNero.FeatureVectorInfo() # sensors rbound = OpenNero.FeatureVectorInfo() # rewards # actions abound.add_continuous( -1, 1 ) # forward/backward speed (gets multiplied by constants.MAX_MOVEMENT_SPEED) abound.add_continuous( -constants.MAX_TURN_RADIANS, constants.MAX_TURN_RADIANS) # left/right turn (in radians) # sensor dimensions for a in range(constants.N_SENSORS): sbound.add_continuous(0, 1) # Rewards # the enviroment returns the raw multiple dimensions of the fitness as # they get each step. This then gets combined into, e.g. Z-score, by # the ScoreHelper in order to calculate the final rtNEAT-fitness for f in constants.FITNESS_DIMENSIONS: # we don't care about the bounds of the individual dimensions rbound.add_continuous(-sys.float_info.max, sys.float_info.max) # range for reward # initialize the rtNEAT algorithm parameters # input layer has enough nodes for all the observations plus a bias # output layer has enough values for all the actions # population size matches ours # 1.0 is the weight initialization noise rtneat = OpenNero.RTNEAT("data/ai/neat-params.dat", OpenNero.Population(), constants.pop_size, 1) key = "rtneat-%s" % constants.OBJECT_TYPE_TEAM_0 OpenNero.set_ai(key, rtneat) print "get_ai(%s): %s" % (key, OpenNero.get_ai(key)) # set the initial lifetime lifetime = module.getMod().lt rtneat.set_lifetime(lifetime) print 'rtNEAT lifetime:', lifetime self.agent_info = OpenNero.AgentInitInfo(sbound, abound, rbound)