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


Python Emulator.getResults方法代码示例

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


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

示例1: Lifter2

# 需要导入模块: from emulator import Emulator [as 别名]
# 或者: from emulator.Emulator import getResults [as 别名]
class Lifter2():

    # TODO: SIGINT handler

    def __init__(self,map_file):
        self.emu = Emulator(open(map_file, 'r'), '')
        self.emu.suppress_prints = True
        self.MAX_DEPTH = self.emu.command_limit
        self.MAX_LEAVES = 10000000
        self.MAX_SCORE = 75.0*self.emu.total_lambdas
        print 'MAX DEPTH: ' + str(self.MAX_DEPTH)
        print 'MAX LEAVES: ' + str(self.MAX_LEAVES)
        print 'MAX SCORE: ' + str(self.MAX_SCORE)

        self.best_score = 0.0
        self.best_seed = -1
        self.best_path = ''    
        
    def simSAMC(self,seed):
        random.seed = seed
        leafs = deque()
        
        node0 = NState(0.0,0,'')
        leafs.append(node0)
        
        # use SA to expand branch
        while ((len(leafs) > 0) & 
               (len(leafs) <= self.MAX_LEAVES)):
            # pick the node 
            node = leafs.popleft()
            #kT = 1 - node.depth/self.MAX_DEPTH # temprature
            #kT = self.MAX_DEPTH - node.depth
            kT = (self.MAX_DEPTH - node.depth) * self.MAX_SCORE

            if (kT <= 0):
                print 'touch bottom: ' + node.cmds
                break

            # with prob e(score/T) to expand
            #energy = 1 - node.score/self.MAX_SCORE
            energy = self.MAX_SCORE - node.score
            if (random.random() < \
                    math.exp(-energy/kT)):
                #print "to expand: " + \
                #    node.cmds + \
                #    '[depth: '+ str(node.depth) + \
                #    ' score: ' + str(node.score) + \
                #    ' proba: ' + str(math.exp(-energy/kT)) + ']'
                for cmd in VALID_COMMANDS:
                    if cmd != COMMAND_SHAVE:
                        cmds = node.cmds + cmd
                        #print cmds
                        isdead, isquit, score = \
                            self.emu.getResults(cmds)
                        #print isdead
                        #print isquit
                        #print score
                        if not isdead:
                            if not isquit:
                                # use MC to cut branch
                                denergy = \
                                    (score - node.score)
                                if ((denergy > 0) | \
                                    (random.random() < \
                                          math.exp(denergy/kT))):
                                    #print '\taccept ' + cmd + ' with '\
                                    #    + 'proba: ' + \
                                    #    str(math.exp(denergy/kT))
                                    
                                    newnode = NState(score, \
                                                     node.depth+1, \
                                                     cmds)
                                    leafs.append(newnode)
                            else: # end of game
                                if (self.best_score < score):
                                    self.best_score = score
                                    print cmds + ': ' + str(score)
# ("DDDLLUURDLDL")

    def startExplore(self):
        # simulate a bunche of rand seeds
        random.seed = 100
        idx = 0
        while 1: 
            seed = random.randint(1,10000)
            print 'SEED: ' + str(seed)
            self.simSAMC(seed)
            idx = idx + 1
            if (idx > 100): break

        
    def endExplore(self):
        # produce final results on SIGINT
        print "TODO"
开发者ID:chris-hudson,项目名称:ICFP,代码行数:96,代码来源:lifter2.py


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