本文整理汇总了Python中Model.Model.fromFile方法的典型用法代码示例。如果您正苦于以下问题:Python Model.fromFile方法的具体用法?Python Model.fromFile怎么用?Python Model.fromFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Model.Model
的用法示例。
在下文中一共展示了Model.fromFile方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: len
# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import fromFile [as 别名]
#!/usr/bin/env python3
# should be locate in main directory
import sys
if len(sys.argv) != 3:
print("{} <model-file> <events-file>".format(sys.argv[0]))
sys.exit(1)
from matplotlib import pyplot
pyplot.rcParams["figure.figsize"] = [5.75, 2.5]
from Model import Model
from Events import Events
model, events = Model.fromFile(sys.argv[1]), Events.fromFile(sys.argv[2])
count = dict((p, 0) for p in model.packets)
trace = dict((p, []) for p in model.packets)
cumTrace = []
events.next()
while events.hasNext():
event = events.next()
time, packet = event.time, event.packet
count[packet] += 1
tcount = model.rate * model.probability(packet) * time
trace[packet].append((time, count[packet], tcount, count[packet] / tcount))
cumTrace.append((time, sum(count[p] for p in model.packets) / model.rate / time))
lr, = pyplot.plot(list(map(lambda e: e[0], cumTrace)), [1] * len(cumTrace))
示例2: test_createModelFromFile
# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import fromFile [as 别名]
def test_createModelFromFile(self):
model = Model.fromFile('tests/example/model.in')
self.assertModelEqual(model, 5, {3.0: 0.33, 5.0: 0.17, 7.0: 0.5}, 1.5)
示例3: test_createModelFromFile_noFile
# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import fromFile [as 别名]
def test_createModelFromFile_noFile(self):
with self.assertRaises(FileNotFoundError):
model = Model.fromFile('tests/example/modelXXX.in')
示例4: WaitEvent
# 需要导入模块: from Model import Model [as 别名]
# 或者: from Model.Model import fromFile [as 别名]
if error:
events.schedule(ErrorEvent(time + error) if error >= 0 else WaitEvent())
while events.hasNext():
event = events.next()
time = event.time
log(event)
algorithm.notify(event)
adversary.notify(event)
if events.hasNextNow(time): continue
if not algorithm.sending:
packet = schedule(algorithm)
packet = packet / speedup if packet else None
error = adversary.algorithmSchedules(packet)
scheduleError(time, error)
if not adversary.sending:
advpacket = schedule(adversary)
error = adversary.adversarySchedules(advpacket)
scheduleError(time, error)
model = Model.fromFile(sys.argv[4])
algorithm = getattr(Algorithm, sys.argv[1])(model)
adversary = getattr(Adversary, sys.argv[2])(model)
events = Events.fromFile(sys.argv[3])
play(algorithm, adversary, events, model.speedup)