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


Python Clock.has_run方法代码示例

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


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

示例1: System

# 需要导入模块: from clock import Clock [as 别名]
# 或者: from clock.Clock import has_run [as 别名]
class System(object):
    def reset(self, seed=None):
        self.feq = FutureEventsQueue()
        self.clock = Clock()
        self.stats = Stats()
        if seed is not None:
            random.seed(seed)
        self.initialize()
        
    def update_averages(self, overall_stats):
        for stat in self.stats:
            overall_stats.add(stat, self.stats.get(stat))

    def run(self, trials, duration, seed=None):
        overall_stats = Stats()
        for i in range(trials):
            self.reset(seed)
            while self.feq.has_events():
                event = self.feq.next_event()
                self.clock.update(event.time)
                if self.clock.has_run(duration):
                    break
                self.update()
                self.handle(event)
            self.finalize()
            self.update_averages(overall_stats)
            print "Completed trial %d/%d" % (i+1, trials)
        print
        return overall_stats
        
    def schedule_event(self, event):
        """ Convenience function """
        self.feq.schedule_event(event)
        
    def initialize(self):
        """ System-specific variables are initialized here and the
            first event is scheduled """
        pass
        
    def update(self):
        """ Anything that must be updated every single iteration
            regardless of event type goes here
        """
        pass
        
    def handle(self, event):
        """ Updating of system state and stats, and scheduling of next event
            should go here """
        pass

    def finalize(self):
        """ All final calculations go here before the stats object is
            returned """
        pass
开发者ID:griffy,项目名称:ElevatorSim,代码行数:56,代码来源:system.py

示例2: System

# 需要导入模块: from clock import Clock [as 别名]
# 或者: from clock.Clock import has_run [as 别名]
class System(object):
    def reset(self, seed=None):
        self.feq = FutureEventsQueue()
        self.clock = Clock()
        self.stats = Stats()
        if seed is not None:
            random.seed(seed)
        self.initialize()
        
    def run(self, duration, seed=None):
        self.reset(seed)
        while self.feq.has_events():
            event = self.feq.next_event()
            self.clock.update(event.time)
            if self.clock.has_run(duration):
                break
            self.update()
            self.handle(event)
        return self.stats
        
    def schedule_event(self, event):
        """ Convenience function """
        self.feq.schedule_event(event)
        
    def initialize(self):
        """ System-specific variables are initialized here and the
            first event is scheduled """
        pass
        
    def update(self):
        """ Anything that must be updated every single iteration
            regardless of event type goes here
        """
        pass
        
    def handle(self, event):
        """ Updating of system state and stats, and scheduling of next event
            should go here """
        pass
开发者ID:spooty89,项目名称:ElevatorSim,代码行数:41,代码来源:system.py


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