本文整理汇总了Python中simulation.Simulation.simulate方法的典型用法代码示例。如果您正苦于以下问题:Python Simulation.simulate方法的具体用法?Python Simulation.simulate怎么用?Python Simulation.simulate使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类simulation.Simulation
的用法示例。
在下文中一共展示了Simulation.simulate方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: main
# 需要导入模块: from simulation import Simulation [as 别名]
# 或者: from simulation.Simulation import simulate [as 别名]
def main():
db = Database("zoo.db")
zoo = Zoo(50, 1000000000, db)
simulation = Simulation(zoo)
print("welcome to our zoo! enter help to get available commands")
while True:
commands = input("what'd you like to do? ").split(' ')
command = commands[0]
args = commands[1:]
if command == 'help':
print(instructions())
elif command == 'simulate':
try:
simulation.simulate(*args)
except AttributeError:
print('\n'.join(["wrong command or wrong arguments entered!",
"maybe enter help again :)"]))
elif command == 'exit':
print('bye')
exit(0)
else:
try:
print(zoo.__getattribute__(command)(*args))
except (TypeError, AttributeError):
print('\n'.join(["wrong command or wrong arguments entered!",
"maybe enter help again :)"]))
sm = Simulation(zoo)
sm.simulation('months', 2)
示例2: testPBAndDIncreaseWithLambda
# 需要导入模块: from simulation import Simulation [as 别名]
# 或者: from simulation.Simulation import simulate [as 别名]
def testPBAndDIncreaseWithLambda(self):
print "======= TEST: PB and D increase when lambda increases ======="
lambdas = [10, 20, 40, 80, 100]
for lamb in lambdas:
print "Lambda = " + str(lamb)
sim = Simulation(0, 3, 1000, 20, 5, 30, "poisson", lamb, 0, 0)
sim.simulate()
print ""
print "============================================================="
示例3: evaluate_controller
# 需要导入模块: from simulation import Simulation [as 别名]
# 或者: from simulation.Simulation import simulate [as 别名]
def evaluate_controller(controller):
"""
Gives a score to the controller based on its landing
performance, determined by the simulation outcome and
the time elapsed.
"""
sim = Simulation(controller)
success, time = sim.simulate()
if success:
return time
else:
return -(time + 100)
示例4: abs
# 需要导入模块: from simulation import Simulation [as 别名]
# 或者: from simulation.Simulation import simulate [as 别名]
return abs(sim.position)
def make_controller(b, h2, falling_speed):
def controller(sim):
if sim.position > h2:
if sim.speed < falling_speed:
return 0.0
else:
return b
else:
return 1.0
return controller
if __name__ == '__main__':
sim = Simulation(None)
falling_speed = 0.95 * sim.max_speed
landing_speed = 0.8 * sim.max_landing_speed
print 'Finding b...'
b = find_holding_thrust()
print 'b = %f\n\nFinding h2...' % b
h2 = find_distance(falling_speed, landing_speed)
print 'h2 = %f\n\nPress enter to start simulation...' % h2
junk = raw_input()
sim.controller = make_controller(b, h2, falling_speed)
print sim.simulate(debug = True)
示例5: range
# 需要导入模块: from simulation import Simulation [as 别名]
# 或者: from simulation.Simulation import simulate [as 别名]
for p in range(3):
pyplot.figure(plot_folders[p])
pyplot.gca().set_color_cycle(['red', 'green', 'blue', 'orange'])
# Simulate against each strategy
for strat1 in range(4):
strategy1 = opponents[strat1]() # Creates second player with appropriate class (strategy type).
print "Strategy {0} v. strategy {1}".format(strat0, strat1)
sim = Simulation(strategy0, strategy1)
stats_wins.append([])
stats_losses.append([])
stats_ties.append([])
for rounds in range(MIN_ROUNDS, MAX_ROUNDS + 1):
# Simulate set number of games and save stats of wins, losses and ties for each
results = sim.simulate(SAMPLES, rounds)
wins = results.count(0)
losses = results.count(1)
ties = results.count(-1)
stats_wins[strat1].append(float(wins)/SAMPLES)
stats_losses[strat1].append(float(losses)/SAMPLES)
stats_ties[strat1].append(float(ties)/SAMPLES)
# Save all stats to a container for easy distribution to plots
stats = [stats_wins, stats_losses, stats_ties]
# Plot results to a plot
for p in range(3):
pyplot.figure(plot_folders[p])
pyplot.plot(range(MIN_ROUNDS, MAX_ROUNDS + 1), stats[p][strat1])