本文整理汇总了Python中history.History.logAttempt方法的典型用法代码示例。如果您正苦于以下问题:Python History.logAttempt方法的具体用法?Python History.logAttempt怎么用?Python History.logAttempt使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类history.History
的用法示例。
在下文中一共展示了History.logAttempt方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Simulator
# 需要导入模块: from history import History [as 别名]
# 或者: from history.History import logAttempt [as 别名]
#.........这里部分代码省略.........
ret = []
for jobId in self.jobs:
job = self.jobs[jobId]
ret.append(job.getQuality())
return sum(ret)/len(ret) if len(ret)>0 else 0.0
def isTimeLimit(self):
return not (self.maxTime==None or self.t < self.maxTime)
# Run simulation
def run(self):
self.energy = 0.0
# Log initial node status
for nodeId in self.nodes:
node = self.nodes[nodeId]
self.history.logNodeStatus(self.t, node)
# Iterate every X seconds
while len(self.jobsQueue) > 0 and not self.isTimeLimit():
# Run running tasks
# =====================================================
completedAttempts = []
for node in self.nodes.values():
completedAttempts += node.progress(self.STEP) # progress 1 second at a time
# Mark completed maps
completedJobs = []
for attempt in completedAttempts:
attempt.finish = self.t
# Check if we finish the jobs
completedJobs += attempt.getJob().completeAttempt(attempt)
# Log
self.history.logAttempt(attempt)
for job in completedJobs:
job.finish = self.t
job.status = Job.Status.SUCCEEDED
# Update queues
self.jobsQueue.remove(job.jobId)
self.jobsDone.append(job.jobId)
# Log
self.history.logJob(job)
# Check which nodes are available to run tasks
# =====================================================
# Maps
while self.mapQueued()>0 and self.getIdleNodeMap() != None:
# Get a map that needs to be executed and assign it to a node
idleNode = self.getIdleNodeMap()
# TODO policy to decide when to approximate
#mapAttempt = self.getMapTask(approx=True if self.getNodesUtilization() > 1.8 else False)
mapAttempt = self.getMapTask()
mapAttempt.start = self.t
if mapAttempt.getJob().isMapDropping():
mapAttempt.drop()
mapAttempt.finish = self.t
mapAttempt.approx = False
completedJobs += mapAttempt.getJob().dropAttempt(mapAttempt)
# Log
self.history.logAttempt(mapAttempt)
else:
# Start running in a node
idleNode.assignMap(mapAttempt)
# Reduces
while self.redQueued()>0 and self.getIdleNodeRed() != None: