def test56(): env = sim.Environment() mon = sim.Monitor('number per second') for i in range(100): sample = sim.Normal(0.083,0.00166)() mon.tally(sample) mon = sim.Monitor('number per second') env.run(100) mon.print_histogram()
def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.usedlength = 0 self.side = left self.monitor_usedlength = sim.MonitorTimestamp( name='used length', getter=self.get_usedlength) self.monitor_time_in_complex = sim.Monitor(name='time in complex')
def test51(): env = sim.Environment() d = sim.Poisson(2) x = [] m = sim.Monitor(name='samples') for i in range(10000): m.tally(d()) m.print_histogram(15, 0, 1)
def test30(): env=sim.Environment() m=sim.Monitor('m') print (m.x(ex0=True)) m.tally(1) m.tally(2) m.tally(3) m.tally(0) m.tally('0') m.tally('12') m.tally('abc') print (m.x(ex0=True))
def test37(): env=sim.Environment() s = sim.Monitor('s') s.tally(1) s.tally(2) s.tally(3) s.tally(0) s.tally(4) s.tally('a') print(s.x(ex0=False,force_numeric=True))
def test45(): def test(d, lowerbound=-sim.inf, upperbound=sim.inf): d.print_info() print('mean=', d.mean()) l=[d(lowerbound, upperbound) for i in range(10000)] print('one sample', d()) print('mean sampled =', sum(l)/(len(l)+1)) print('-' * 79) env=sim.Environment() mon = sim.Monitor() d = sim.Cdf((5, 0, 10, 50, 15, 90, 30, 95, 60, 100)) for _ in range(10000): mon.tally(d.bounded_sample(lowerbound=5, upperbound=sim.inf, number_of_retries=300)) mon.print_histogram(30,-5,1)
def test55(): class X(sim.Component): def process(self): while True: yield self.hold(sim.Exponential(rate=0.83)()) env.count += 1 class Y(sim.Component): def process(self): while True: env.count=0 yield self.hold(1) print(env.count) mon.tally(env.count) env = sim.Environment() env.count = 0 X() Y() mon = sim.Monitor('number per second') env.run(100) mon.print_histogram()
def test26(): global de class X(sim.Component): def _get_a(self): return self.a def _now(self): return self.env._now def process(self): m2.tally() yield self.hold(1) self.a=4 m2.tally() m2.monitor(True) print('3',m2.xt()) yield self.hold(1) self.a=20 m2.tally() yield self.hold(1) self.a=0 m2.tally() yield self.hold(1) m3.tally() m2.monitor(True) de=sim.Environment() m1=sim.Monitor('m1',type='uint8') print (m1.mean()) m1.tally(10) m1.tally(15) m1.tally(20) m1.tally(92) m1.tally(0) m1.tally(12) m1.tally(0) print ('m1.x()',m1.x(force_numeric=False)) print ('m1',m1.mean(),m1.std(),m1.percentile(50)) print ('m1 ex0',m1.mean(ex0=True),m1.std(ex0=True),m1.percentile(50,ex0=True)) x=X() x.a=10 m2=sim.MonitorTimestamp('m2',getter=x._get_a,type='int8') print('1',m2.xt()) m2.monitor(True) m2.tally() print('a',m2.xt()) # m2.monitor(True) m2.tally() print('2',m2.xt()) m3=sim.MonitorTimestamp('m3',getter=x._now) print(m3()) de.run(10) print('4',m2.xt()) print('5',m2.xduration()) print(m2.mean(),m2.std(),m2.percentile(50)) m1.print_histogram(10,0,10) m2.print_histogram(10,0,10) print(m3.xduration()) m3.print_histogram(10,0,10) print('done') # for i in range(101): # print(i,m1.percentile(i),m2.percentile(i)) m3=sim.Monitor('m3') m3.tally(1) m3.tally(3) print('xx')
def test27(): m1=sim.Monitor('m1') print (m1.mean(),m1.std(),m1.percentile(50),m1.histogram()) m1.tally(10) print (m1.mean(),m1.std(),m1.percentile(50),m1.histogram())
def setup(self): self.usedlength = 0 self.side = left self.monitor_usedlength = sim.MonitorTimestamp(name='used length') self.monitor_time_in_complex = sim.Monitor(name='time in complex')
import salabim as sim env = sim.Environment() monitor_names = sim.Monitor(name="names") for _ in range(10000): name = sim.Pdf(("John", 30, "Peter", 20, "Mike", 20, "Andrew", 20, "Ruud", 5, "Jan", 5)).sample() monitor_names.tally(name) monitor_names.print_histograms(values=True)