本文整理汇总了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
示例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