本文整理汇总了Python中Simulator.Simulator.run方法的典型用法代码示例。如果您正苦于以下问题:Python Simulator.run方法的具体用法?Python Simulator.run怎么用?Python Simulator.run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Simulator.Simulator
的用法示例。
在下文中一共展示了Simulator.run方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: simulationLoop
# 需要导入模块: from Simulator import Simulator [as 别名]
# 或者: from Simulator.Simulator import run [as 别名]
def simulationLoop(server, capacity, period, scaled, ex_time, int_time):
name = server + ".csv"
s = Simulator(stats = name)
# Set the server
if server == 'polling':
s.server = PollingServer(capacity, period)
elif server == 'deferrable':
s.server = DeferrableServer(capacity, period)
else:
s.server = BackgroundServer()
# Load the taskset
for t in scaled:
s.tasks.append(t)
# Create the aperiodic task
ap = AperiodicTask("Soft", ex_time, int_time)
s.tasks.append(ap)
# RUUUUUUUUN !!!
s.init(until)
s.run()
return computeAverage(name)
示例2: oneRoundDelay
# 需要导入模块: from Simulator import Simulator [as 别名]
# 或者: from Simulator.Simulator import run [as 别名]
def oneRoundDelay(step = 10000):
injectRate = 0.9
factory = GridNetworkFactory(makeSimpleNode(),Queues)
factory.constructNetwork(6,6)\
.setFlow(Flow((0,0),(0,5),injectRate))\
.setFlow(Flow((5,0),(5,5),injectRate))\
.setFlow(Flow((2,0),(3,5),injectRate))
network = factory.getNetwork()
packetFactory = PacketFactory()
simulator = \
Simulator(network,step,ConstLinkRateGenerator(1),packetFactory)
simulator.run()
#simulator.printNetwork()
stat = simulator.getStaticsInfo()
print stat['aveDelay']
packetPool = sorted(stat['packetPool'],key=lambda p: p.getID)
py.subplot(211)
py.vlines([p.getCreateTime() for p in packetPool],[1],[p.getDelay() for p in packetPool],'r')
py.xlabel('Packet create time(bp with $\lambda$ = 0.9)')
py.ylabel('delay')
py.grid(True)
injectRate = 0.9
factory = GridNetworkFactory(makeMNode(2),Queues)
factory.constructNetwork(6,6)\
.setFlow(Flow((0,0),(0,5),injectRate))\
.setFlow(Flow((5,0),(5,5),injectRate))\
.setFlow(Flow((2,0),(3,5),injectRate))
network = factory.getNetwork()
packetFactory = PacketFactory()
simulator = \
Simulator(network,step,ConstLinkRateGenerator(1),packetFactory)
simulator.run()
#simulator.printNetwork()
stat = simulator.getStaticsInfo()
print stat['aveDelay']
packetPool = sorted(stat['packetPool'],key=lambda p: p.getID)
py.subplot(212)
py.vlines([p.getCreateTime() for p in packetPool],[1],[p.getDelay() for p in packetPool],'b')
py.xlabel('Packet create time (m=2 with $\lambda$ = 0.9)')
py.ylabel('delay')
py.grid(True)
py.savefig('packetDelayInOneRound_09')
py.show()
示例3: main
# 需要导入模块: from Simulator import Simulator [as 别名]
# 或者: from Simulator.Simulator import run [as 别名]
def main():
NUM_INITIAL_MOBILES = 150
SIMULATION_ITERATIONS = 3600
print("callAttempts, blkSig, blkCap, dropSig, HOfail, HO, complSuc, talkTime, GOS, HOFR, intensity")
for iteration in range(10):
simulator = Simulator(NUM_INITIAL_MOBILES, 1.0/3600)
simulator.run(SIMULATION_ITERATIONS, iteration)
示例4: main
# 需要导入模块: from Simulator import Simulator [as 别名]
# 或者: from Simulator.Simulator import run [as 别名]
def main():
NUM_INITIAL_MOBILES = 150
SIMULATION_ITERATIONS = 3600
print("callAttempts, blkSig, blkCap, dropSig, HOfail, HO, complSuc, talkTime, GOS, HOFR, intensity")
for iteration in range(10):
simulator = Simulator(NUM_INITIAL_MOBILES, 1.0/3600)
# simulator.basestations[0].ANTENNA_GAIN = 10
# simulator.basestations[1].ANTENNA_GAIN = 10
simulator.basestations[0].NUM_CHANNELS = 20
simulator.basestations[1].NUM_CHANNELS = 20
simulator.run(SIMULATION_ITERATIONS, iteration)
示例5: CounterTest
# 需要导入模块: from Simulator import Simulator [as 别名]
# 或者: from Simulator.Simulator import run [as 别名]
def CounterTest(step = 10000):
injectRate = 1
factory = GridNetworkFactory(makeCNode(0),Queues)
factory.constructNetwork(8,8)\
.setFlow(Flow((0,0),(0,7),injectRate))\
.setFlow(Flow((7,0),(7,7),injectRate))
network = factory.getNetwork()
packetFactory = PacketFactory()
simulator = \
Simulator(network,step,ConstLinkRateGenerator(1),packetFactory)
simulator.run()
#simulator.printNetwork()
stat = simulator.getStaticsInfo()
print stat
示例6: OrdTest
# 需要导入模块: from Simulator import Simulator [as 别名]
# 或者: from Simulator.Simulator import run [as 别名]
def OrdTest():
injectRate = 0.5
factory = GridNetworkFactory(makeMNode(1),ShadowQueues)
factory.constructNetwork(8,8)\
.setFlow(Flow((2,0),(2,7),injectRate),Flow((4,0),(4,7),injectRate),\
Flow((0,2),(7,2),injectRate),Flow((0,4),(7,4),injectRate),\
Flow((1,1),(5,1),injectRate),Flow((6,1),(6,6),injectRate),\
Flow((5,6),(1,6),injectRate),Flow((1,5),(1,2),injectRate))
network = factory.getNetwork()
packetFactory = PacketFactory()
simulator = \
Simulator(network,gobalMaxStep,ConstLinkRateGenerator(1),packetFactory)
simulator.run()
stat = simulator.getStaticsInfo()
print stat
示例7: _run_simulation
# 需要导入模块: from Simulator import Simulator [as 别名]
# 或者: from Simulator.Simulator import run [as 别名]
def _run_simulation(self, num_investments):
'''Run a single simulation with a given number of investments
For each position, the number of investments is the number of rows.
For each investment, we run num_trial trials, where each trial is
a column in that row.
We multiply all the trials for each investment by the value of that
investment, which is simply the intial budget divided by the number
of investments.
For each trial (column), we sum up the returns from all the investments
(rows), producing a 1xnum_trials array with the cumulative returns from
each day.'''
position_value = self.initial_budget / num_investments
# Create the simulator object
simulator = Simulator({(0, .51): 1.0, (.51, 1): -1.0},
nrows=num_investments,
ncols=self.num_trials)
# Run the simulator, and multiply each of the results by the value
# of a share for this position
trial_returns = simulator.run() * position_value
# Collapse all investments on each day into cumulative return
cumu_ret = self.initial_budget + trial_returns.sum(axis=0)
# The daily rate of return, which is the final result
daily_ret = (cumu_ret / float(self.initial_budget)) - 1.
return daily_ret
示例8: __init__
# 需要导入模块: from Simulator import Simulator [as 别名]
# 或者: from Simulator.Simulator import run [as 别名]
class DifferentInjectRateTest:
def __init__(self,linkRate=1,maxStep=gobalMaxStep,injectRate=0.5,\
factory=gobalGridNetworkFactory):
factory.constructNetwork(8,8)\
.setFlow(Flow((2,0),(2,7),injectRate),Flow((4,0),(4,7),injectRate),
Flow((0,2),(7,2),injectRate),Flow((0,4),(7,4),injectRate),
Flow((1,1),(5,1),injectRate),Flow((6,1),(6,6),injectRate)
,Flow((5,6),(1,6),injectRate),Flow((1,5),(1,2),injectRate))
network = factory.getNetwork()
self.packetFactory = PacketFactory()
self.simulator = \
Simulator(network,maxStep,ConstLinkRateGenerator(linkRate),self.packetFactory)
def run(self):
self.simulator.run(flag = False)
def getStaticsInfo(self):
return self.simulator.getStaticsInfo()
示例9: SoS
# 需要导入模块: from Simulator import Simulator [as 别名]
# 或者: from Simulator.Simulator import run [as 别名]
MCISoS = SoS(CSs, MCIMap)
MCIEvents = []
numOfPatients = 20
for i in range(numOfPatients):
MCIEvents.append(Event(PatientOccurrence('patient +1', MCIMap), ConstantTimeBound(0)))
MCIScenario = Scenario(MCIEvents)
'''Simulation'''
simulationTime = 15
MCISim = Simulator(simulationTime, MCISoS, MCIScenario)
repeatSim = 2000
MCILogs = []
for i in range(repeatSim):
MCILog = MCISim.run()
MCILogs.append(MCILog)
'''
print('log print (only last log)')
for log in MCILogs:
print(log[-1], sum(log[-1][0]), sum(log[-1][1]))
'''
'''
print()
for CS in CSs:
print(CS.name, 'rescued:', CS.rescued)
print('final map:', MCIMap)
print()
'''
示例10: Simulator
# 需要导入模块: from Simulator import Simulator [as 别名]
# 或者: from Simulator.Simulator import run [as 别名]
from Simulator import Simulator
from States import S_Start, S_DeadCancer, S_DeadAge, S_DeadChemo
from numpy import average
import ConundrumModel as Model
s= Simulator(iters=10000, age=60, ca125=True, model=Model)
s.run()
print average([len(p.states) for p in s.patients])
s.clear_survival_curves()
s.add_survival_curve(start_states=[S_Start],
end_states=[S_DeadCancer])
s.add_survival_curve(start_states=[S_Start],
end_states=[S_DeadChemo])
s.add_survival_curve(start_states=[S_Start],
end_states=[S_DeadAge])
s.draw_survival_curves(name="conundrum.png")
示例11: Simulator
# 需要导入模块: from Simulator import Simulator [as 别名]
# 或者: from Simulator.Simulator import run [as 别名]
lb = Simulator(initial_slots=64, simulations=2000, min_tags=100, max_tags=1000,
step=100, estimator=lower_bound)
lee = Simulator(initial_slots=64, simulations=2000, min_tags=100, max_tags=1000,
step=100, estimator=eom_lee)
chen = Simulator(initial_slots=64, simulations=2000, min_tags=100, max_tags=1000,
step=100, estimator=chen)
# Use this to generate graphics
start_time = time.time()
lb_result = lb.run()
print("Tempo para execucao do lower bound: " + str(time.time() - start_time))
start_time = time.time()
lee_result = lee.run()
print("Tempo de execucao do eom lee: " + str(time.time() - start_time))
start_time = time.time()
chen_result = chen.run()
print("Tempo de execucao do chen: " + str(time.time() - start_time))
print(lb_result)
print(lee_result)
print(chen_result)
示例12: range
# 需要导入模块: from Simulator import Simulator [as 别名]
# 或者: from Simulator.Simulator import run [as 别名]
age = 60
smonths_with = {}
smonths_without = {}
icer = []
CostEvaluator.bProbabilistic = True
iters = 100
avg = []
for k in range(100):
CostEvaluator.cache = {}
for i in range(1):
s2 = Simulator(iters=iters, age=age, ca125=False, model=Model)
s2.run()
s1 = Simulator(iters=iters, age=age, ca125=True, model=Model)
s1.run()
c1 = sum([CostEvaluator.EvaluatePatient(p)['cost'] for p in s1.patients]) * 1./iters
q1 = sum([CostEvaluator.EvaluatePatient(p)['quality'] for p in s1.patients]) * 1./iters
c2 = sum([CostEvaluator.EvaluatePatient(p)['cost'] for p in s2.patients]) * 1./iters
q2 = sum([CostEvaluator.EvaluatePatient(p)['quality'] for p in s2.patients]) * 1./iters
print np.average([len(x.states) for x in s1.patients])
print np.average([len(x.states) for x in s2.patients])
avg.append((q1-q2, c1-c2))
print avg[-1]
示例13: Simulator
# 需要导入模块: from Simulator import Simulator [as 别名]
# 或者: from Simulator.Simulator import run [as 别名]
from Simulator import Simulator
from Estimators import *
import matplotlib.pyplot as plt
if __name__ == '__main__':
simulator = Simulator(initial_slots=64, simulations=1, min_tags=100, max_tags=1000,
step=100, estimator=eom_lee)
# Use this to generate graphics
result = simulator.run()
print(result)
# Generating Collisions vs Tags
plt.figure(1)
plt.title('Collisions vs Tags')
plt.plot([x['tags'] for x in result], [x['collisions'] for x in result], 'r--')
plt.ylabel('Collisions')
plt.xlabel('Tags')
# Generating Empty vs Tags
plt.figure(2)
plt.title('Empty vs Tags')
plt.plot([x['tags'] for x in result], [x['empty'] for x in result], 'r--')
plt.ylabel('Empty')
plt.xlabel('Tags')
# Generating Slots vs Tags
plt.figure(3)
示例14: Simulator
# 需要导入模块: from Simulator import Simulator [as 别名]
# 或者: from Simulator.Simulator import run [as 别名]
from States import *
import MultiExponentialModel as Model
Model.bProbabilistic = False
age = 60
cost_bins = np.arange(0,50000,1000)
quality_bins = np.arange(0,30,1./12)
for x in np.arange(.001, 1, .01):
Model.vProbabilistic[Model.pFirstRecurrence][2] = x
idstr = ".pFirstRecurrence.%04f"%x
# print idstr
s1 = Simulator(iters=5000, age=age, ca125=True, model=Model)
s1.run()
c = np.array([CostEvaluator.EvaluatePatient(p)['cost'] for p in s1.patients])
print x, "\t",np.average(c)
print "Quality: ", np.average([x[0] for x in icer])
print "Cost: ", np.average([x[1] for x in icer])
f = py.figure(0)
f.clear()
ax = f.add_subplot(2,1,1)
n, bins, patches = ax.hist([x[0] for x in icer], normed=1, alpha=.75, bins=75)
ax.set_xlabel("$\Delta$Quality")