当前位置: 首页>>代码示例>>Python>>正文


Python Map.get方法代码示例

本文整理汇总了Python中map.Map.get方法的典型用法代码示例。如果您正苦于以下问题:Python Map.get方法的具体用法?Python Map.get怎么用?Python Map.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在map.Map的用法示例。


在下文中一共展示了Map.get方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import get [as 别名]
 def get(self):
   try:
     name = re.sub("/get/", "", self.request.path)
     key = db.Key(name)
     map = Map()
     map = map.get(key)
     result = urllib.urlencode([('result', str(map.text)),
                                ('key', str(map.key()))])
   except Exception, error:
     message = 'Could not find map: ' + str(error)
     result = urllib.urlencode([('error', message)])
开发者ID:Shattered-Colony-Unbound,项目名称:sc-unbound,代码行数:13,代码来源:download.py

示例2: __init__

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import get [as 别名]
class Simulation:
    def __init__(self, config):
        self.config = config
        self.map = Map(self.config)
        self.algorithm = GeneticAlgorithm(self.config)
        self.generate_initial_population()

    def generate_initial_population(self):
        """
        Generate random population of n chromosomes (suitable solutions for the problem)
        Creates a random genome
        """
        random.seed()
        self.population = []
        for chromosome in range(self.config['population_size']):
            # create a random chromosome with a random gain value
            self.population.append(Chromosome(
                random.random() * self.config['max_gain_value'],
                random.random() * self.config['max_gain_value'],
                random.random() * self.config['max_gain_value']
                ))

    def generate_new_population(self):
        """
        Generate a new population by repeating following steps until the new population is complete
        """
        new_population = []
        self.fitness_values = []

        # find fitness values of the entire population
        for chromosomeIndex in range(self.config['population_size']):
            self.fitness_values.append(self.run_simulation_for_chromosome(chromosomeIndex))

        # generate a new population based on fitness values
        for chromosomeIndex in range(self.config['population_size']):
            # selection - find two parents of new chromosome
            parentIndices = self.algorithm.selection(self.fitness_values)

            # crossover - generate a child based on
            chromosome = self.algorithm.crossover(self.population[parentIndices[0]], self.population[parentIndices[1]])

            # mutation
            chromosome = self.algorithm.mutation(chromosome)
            new_population.append(chromosome)

        self.population = new_population

    def run_simulation_for_chromosome(self, chromosomeIndex):
        """
        Run simulation for a specific chromosome c.

        Returns the fitness function value of the simulation
        """

        distance_list = []
        current_position = 0
        last_distance = 0
        current_summation = 0
        current_distance = 0

        for time in range(self.config['max_timesteps']):
            distance_list.append(time)
            current_distance = self.map.get(time) - current_position

            # note: God integrates empirically
            current_summation = current_summation + current_distance

            new_velocity = (self.population[chromosomeIndex].kp * current_distance +
                self.population[chromosomeIndex].kd * (current_distance-last_distance) +
                self.population[chromosomeIndex].ki * current_summation
                )
            #x = x + dx/dt * dt (dt = 1)

            current_position = current_position + new_velocity

            distance_list[time] = current_distance

            # for the derivative
            last_distance = current_distance

        return self.algorithm.fitness(distance_list)
开发者ID:FlavioFalcao,项目名称:Genetic-Algorithm-PID-Controller-Tuner,代码行数:83,代码来源:simulation.py

示例3: Level

# 需要导入模块: from map import Map [as 别名]
# 或者: from map.Map import get [as 别名]
class Level(Completable, Inputable):
    def __init__(self, surface, level, **kwargs):
        super().__init__(**kwargs)
        self._surface = surface
        self.map = Map(level[0], level[1])

    def start(self):
        self.map.load()
        self._entity_map = {}
        self._position_map = {}
        self._entities = {}
        self._registered = {}
        self._enemySpawns = {}
        for x, y in self.map.getMap().keys():
            self._position_map[(x, y)] = []

        self._total_surface = Surface((self.map.w, self.map.h))
        tid = self.addEntity(register=True,
                             entity=MChar(self,
                                          self.map.getType(Tiles.Start)[0],
                                          inputStream=self.getInputStream()))
        self._camera = Viewport(tuple([s * const.res for s in const.screenSize]),
                                lambda: self.map.getAttr("scale"),
                                self.get(tid),
                                (150, 200, 150, 200),
                                self.map)
        self._background = Parallax(const.backgrounds)
        self.editor = Editor(self.map,
                             self._surface,
                             enabled=False,
                             inputStream=self.getInputStream())

        self._input = Input(inputStream=self.getInputStream())
        self._input.set(KEYDOWN, self.editor.toggleEnabled, K_e)
        self._input.set(KEYDOWN, self.start, K_r)

        # self._sound = Sound("assets\\music.ogg")
        # self._sound.play(-1)

        try:
            self._healthBar = HealthBar(10, 10, self.get(tid))
        except AssertionError:
            pass

        for (x, y), val in self.map.enemies.items():
            block = self.map.get(x, y)
            self._enemySpawns[block] = EnemySpawn(level=self,
                                                  anchor=Object(pos=(block.x, block.y)),
                                                  maxEmitted=val,
                                                  timeBetween=2)

        self._countdown = CountdownTimer(const.screenSize[0] * const.res - 50, 10,
                                         self.map.getAttr("timeLim"))

    def addEntity(self, register=False, entity=None):
        if not entity:
            raise Exception("Entity must not be None.")

        tid = entity.getId()

        self._entities[tid] = entity
        if register:
            self._registered[tid] = entity

        self._entity_map[tid] = set()
        return tid

    def removeEntity(self, entity):
        del self._entities[entity.id]

    def get(self, entityId):
        return self._entities.get(entityId)

    def process(self):
        for entity in self._entities.values():
            result = entity.tick()

            if not entity.isAlive():
                self._entities.pop(entity.getId())

            # This should generally only apply to playable characters.
            if entity in self._registered.values():
                if Tiles.End in result.keys():
                    self.setFinished()
                if not entity.isAlive():
                    self.setLost()

        for s in self._enemySpawns.values():
            s.tick()

        self._camera.tick()
        self._countdown.tick()
        if self._countdown.isFinished():
            self.setLost()

        if self.editor.enabled():
            self.editor.tick(self._camera)

        if self.isComplete():
            pass
#.........这里部分代码省略.........
开发者ID:DanCardin,项目名称:PyPlatformer,代码行数:103,代码来源:level.py


注:本文中的map.Map.get方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。