Exemplo n.º 1
0
def test18():
    for j in range(2):
        print('---')
        r=random.Random(-1)
        r1=random.Random(-1)
        d=sim.Exponential(3,r1)
        sim.Environment(random_seed=-1)
        for i in range(3):
            print(sim.Exponential(3,r).sample())
            print(sim.Exponential(3).sample())
            print(d.sample())
Exemplo n.º 2
0
 def process(self):
     timeStart = self.model.env.now()
     yield self.hold(sim.Exponential(self.model.procTime).sample())
     self.release()
     timeEnd = self.model.env.now()
     self.model.procTimeList.append(timeEnd-timeStart)
     self.model.numDep += 1
Exemplo n.º 3
0
 def process(self):
     while True:
         if not waiting_clients:
             yield self.wait(work_to_do)
         this_client = waiting_clients.pop()
         yield self.hold(sim.Exponential(server_time).sample())
         this_client.activate()
Exemplo n.º 4
0
    def process(self):
        while True:
            passive_condition = True
            for i in self.wline_idx:
                passive_condition = passive_condition and len(
                    WaitingLines[i].queue) == 0

            if passive_condition == True:
                yield self.passivate()

            # Pick the call waiting for the longest time:
            wlines = []
            for i in self.wline_idx:
                if len(WaitingLines[i].queue) != 0:
                    wlines.append(WaitingLines[i])

            min_wline = min(wlines, key=lambda x: x.queue[0].arrival_time)
            self.job = min_wline.queue.pop()

            processing_time = sim.Exponential(1).sample() + truncated_normal(
                proc_mean, proc_sd)

            # Update the active time:
            if processing_time + env.now() <= run_time:
                self.active_time += processing_time
            else:
                self.active_time += run_time - env.now()

            yield self.hold(processing_time)

            self.calls_completed[self.job.language] += 1
            self.job.activate()
Exemplo n.º 5
0
 def process(self):
     while True:
         yield self.hold(sim.Exponential(iat).sample())
         ship = Ship(name=sidename(self.side) + 'ship.')
         ship.side = self.side
         ship.length = meanlength * sim.Uniform(2 / 3, 4 / 3).sample()
         if lock.mode() == 'Idle':
             lock.activate()
Exemplo n.º 6
0
 def process(self):
     while True:
         if not waiting_clients:
             self.atwork.set('gray')
             yield self.wait(work_to_do)
         this_client = waiting_clients.pop()
         self.atwork.set(this_client.sequence_number())
         yield self.hold(sim.Exponential(server_time).sample())
         this_client.activate()
Exemplo n.º 7
0
 def process(self):
     while True:  # Infinite loop to generate ships
         yield self.hold(sim.Exponential(iat).sample())
         ship = Ship(name=sidename(self.side) +
                     "ship.")  # The name os the ship is lship.# of rship.#
         ship.side = self.side
         ship.length = meanlength * sim.Uniform(2.0 / 3, 4.0 / 3).sample()
         if lock.mode() == "Idle":  # If lock is idle then activate it
             lock.activate()
Exemplo n.º 8
0
    def process(self, waitTime):

        for i in range(1,2*BULKFLOWS,2):
            bulkPacketGenerator(pid=i,interTime=((QUANTUM/BANDWIDTH)-(1.0/BANDWIDTH)),distribution="uniform")
        
        yield self.hold((BULKFLOWS*QUANTUM)/BANDWIDTH)

        for i in range(0,2*SPARSEFLOWS,2):               
            sparsePacketGenerator(pid=i,interTime=waitTime*INTERARRIVALMULTIPLIER, distribution="uniform")
            yield self.hold(sim.Exponential(waitTime/SPARSEFLOWS).sample())
Exemplo n.º 9
0
 def process(self):
     while True:
         timeStart = self.model.env.now()
         yield self.hold(sim.Exponential(self.model.intArrTime).sample())
         timeEnd = self.model.env.now()
         self.model.arrTimeList.append(timeEnd-timeStart)
         customer = self.model.createEntity()
         customer.model = self.model
         customer.queue = self.model.queue
         customer.server = self.model.server
         self.model.customerArrList.append(customer)
         self.model.numArr += 1
Exemplo n.º 10
0
        def process(self):
            if self.model.maxLen > 0:
                if len(self.model.server.requesters()) >= self.model.maxLen:
                    self.model.number_balked += 1
                    self.model.env.print_trace("", "", "balked")
                    yield self.cancel()

            yield self.request(self.model.server)
            timeStart = self.model.env.now()
            yield self.hold(sim.Exponential(self.model.procTime).sample())
            self.release()

            timeEnd = self.model.env.now()
            self.model.procTimeList.append(timeEnd-timeStart)
            self.model.numDep += 1
Exemplo n.º 11
0
    def process(self,pid, interTime, distribution="uniform"):
       
        if distribution is "uniform":
            while True:
                packet(name='bpacket-' + str(pid), pid=pid, size=QUANTUM)
                yield self.hold(interTime)

        elif distribution is "exponential":
            while True:
                packet(name='bpacket-' + str(pid), pid=pid, size=QUANTUM)
                yield self.hold(sim.Exponential(interTime).sample())
        
        else:
            print("INVALID DISTRIBUTION")
            yield self.cancel
Exemplo n.º 12
0
    def process(self):
        env.print_trace('', self.name(), 'arrrived')

        patience = sim.Uniform(MIN_PATIENCE, MAX_PATIENCE).sample()
        yield self.request(counter, fail_delay=patience)
        wait = env.now() - self.creation_time()

        if self.failed():
            # We reneged
            env.print_trace('', self.name(),
                            'RENEGED after {:6.3f}'.format(wait))
        else:
            # We got to the counter
            env.print_trace('', self.name(), 'waited for {:6.3f}'.format(wait))
            yield self.hold(sim.Exponential(TIME_IN_BANK).sample())
            env.print_trace('', self.name(), 'finished')
Exemplo n.º 13
0
    def process(self,pid, interTime, distribution="uniform"):
        spSize = 0
        
        if int(SPARSESIZE) == -1 * 8:
            spSize = QUANTUM/2
        else:
            spSize = SPARSESIZE

        if distribution is "uniform":
            while True:
                packet(name='spacket-' + str(pid), pid=pid, size = spSize )
                yield self.hold(interTime)

        elif distribution is "exponential":
            while True:
                packet(name='spacket-' + str(pid), pid=pid, size = spSize)
                yield self.hold(sim.Exponential(interTime).sample())
        
        else:
            print("INVALID DISTRIBUTION")
            yield self.cancel
    def process(self):
        i = lang_idx[self.language]
        self.enter(WaitingLines[i].queue)

        # The call will be taken by the employee who is available, speaks the same language and has the least active time:
        avl_employees = []

        for Employee in Employees:
            if self.language in Employee.languages and Employee.ispassive():
                avl_employees.append(Employee)

        if len(avl_employees) > 0:
            min_employee = min(avl_employees, key=lambda x: x.active_time)
            min_employee.activate()

        # The patient hangs up after waiting for some time:
        yield self.hold(7 + sim.Exponential(2).sample())
        if self in WaitingLines[i].queue:
            self.leave(WaitingLines[i].queue)
            num_reneged[i] += 1
        else:
            yield self.passivate()
Exemplo n.º 15
0
def test43():
    def test(d):
        d.print_info()
        print('mean=', d.mean())
        l=[d() for i in range(10000)]
        print('one sample', d())
        print('mean sampled =', sum(l)/(len(l)+1))
        print('-'  * 79)

    env=sim.Environment()

    test(sim.IntUniform(1,6))
    test(sim.Weibull(2,1))
    test(sim.Gamma(5,9))
    test(sim.Erlang(2,scale=3))
    test(sim.Exponential(rate=2))
    test(sim.Beta(32,300))
    test(sim.Normal(5,7))
    test(sim.Normal(5,7,use_gauss=True))

    test(sim.Distribution('Exponential(rate=2)'))
    test(sim.Normal(5,5))
Exemplo n.º 16
0
 def setup(self, inter_arrival_time_dist, number_of_tasks_dist, group_dist, duration_dist):
     self.inter_arrival_time_dist = sim.Exponential(8)
     self.number_of_tasks_dist = sim.IntUniform(1, 9)
     self.group_dist = group_dist
     self.duration_dist = duration_dist
 def process(self):
     while True:
         yield self.hold(sim.Exponential(1)())
         Car()
Exemplo n.º 18
0
 def process(self):
     while True:
         yield self.hold(sim.Exponential(rate=0.83)())
         env.count += 1
Exemplo n.º 19
0
 def __init__(self, **kwargs):
     super().__init__(**kwargs)
     self.distr = sim.Bounded(sim.Exponential(30.9012), upperbound=200)
Exemplo n.º 20
0
def test7():
    print('test7')

    class X1(sim.Component):
        def process(self):
            yield self.request(r1,5,r2,2,greedy=True,fail_at=5)
            yield self.passivate()


    class X2(sim.Component):
        def process(self):
            yield self.request(r1,8,r2)
            yield self.passivate()

    class X3(sim.Component):
        def process(self):
            yield self.request(r1,7)
            yield self.passivate()


    de=sim.Environment(trace=True)

    x1=X1()
    x2=X2()
    x3=X3()

    X4=sim.Component()

    r1=sim.Resource(capacity=10,anonymous=True)
    r2=sim.Resource()
    r3=sim.Resource()

    q={}
    for i in range(1,5):
        q[i]=sim.Queue()

    x1.enter(q[1])
    x1.enter(q[2])
    x1.enter(q[3])

    x2.enter(q[1])
    x3.enter(q[1])



    env.run(10)
    r2.capacity(2)
    env.run(20)

    print(sim.default_env)

    print(x1)
    print(x2)
    print(x3)

    print (q[1])
    print (q[2])
    print (q[3])
    print (q[4])

    print(r1)
    print(r2)
    print(r3)

    d=sim.Exponential(10)
    print(d)
    print(sim.Uniform(1,2))
    print(sim.Triangular(40,150,55))
    print(sim.Distribution('Constant(5)'))
Exemplo n.º 21
0
            yield self.hold(driving_duration)
            self.x = order.customer.x
            self.y = order.customer.y
            order.leave()  # leave all (two) queues the order is in


env = sim.Environment(trace=True, random_seed=1021021)

x_min = 25
y_min = 25
x_max = 1000
y_max = 550

n_drivers = 3
n_restaurants = 5
n_customers = 25
v = 10
inter_arrival_time = sim.Exponential(1000)

env.x_dis = sim.Uniform(x_min, x_max)
env.y_dis = sim.Uniform(y_min, y_max)

env.customers = [Customer(inter_arrival_time=inter_arrival_time) for _ in range(n_customers)]
env.drivers = [Driver(v=v) for _ in range(n_drivers)]
env.restaurants = [Restaurant() for _ in range(n_restaurants)]

env.orders=sim.Queue('all orders')
env.run(100)
env.trace(False)
env.run(till=100000)
env.orders.print_histograms()
Exemplo n.º 22
0
 def process(self):
     while True:
         i = np.random.choice(len(self.languages), 1, p=self.lang_dist)[0]
         Call(self.languages[i])
         self.calls_generated += 1
         yield self.hold(sim.Exponential(arr_mean).sample())
Exemplo n.º 23
0
 def process(self):
     while True:
         yield self.hold(int(sim.Exponential(40).sample(
         )))  # every 10-20 years there's a new heir of the throne
         Prince()
Exemplo n.º 24
0
import salabim as sim


class ClientGenerator(sim.Component):
    def process(self):
        while True:
            yield self.hold(inter_arrival_time_dis.sample())
            Client()


class Client(sim.Component):
    def process(self):
        yield self.request(clerks)
        yield self.hold(service_duration_dis.sample())


env = sim.Environment(trace=True)
number_of_clerks = 5
inter_arrival_time_dis = sim.Exponential(1)
service_duration_dis = sim.Exponential(4)

clerks = sim.Resource(name="clerks", capacity=number_of_clerks)

ClientGenerator()
env.run()
Exemplo n.º 25
0
 def process(self):
     while True:
         yield self.hold(sim.Exponential(iat).sample())
         Client()
Exemplo n.º 26
0
 def process(self):
     self.enter(system)
     yield self.request(servers)
     yield self.hold(sim.Exponential(server_time).sample())
     self.leave()
Exemplo n.º 27
0
 def process(self):
     yield self.request(servers)
     yield self.hold(sim.Exponential(server_time).sample())
Exemplo n.º 28
0
 def process(self):
     for i in range(NEW_CUSTOMERS):
         Customer()
         yield self.hold(sim.Exponential(INTERVAL_CUSTOMERS).sample())
Exemplo n.º 29
0
        # OK, now wait to get out onto the street; every time a new car
        # arrives in cross traffic, it will signal us to check the new
        # next arrival time
        while env.now() + time_to_exit >= street.nextarrival:
            yield self.wait(wakeup, mode='wait for wakeup')
        yield self.hold(time_to_exit, mode='exit')
        self.release(bufferfront)
        self.release(buffer)


class CarWash(sim.Component):
    def process(self):
        while True:
            yield self.hold(wash_iat.sample())
            Car()


env = sim.Environment(trace=True)
wakeup = sim.State(name='wakeup')
wash_time = sim.Pdf((1.0, 0.7, 2.0, 0.3))
street_iat = sim.Exponential(1)
wash_iat = sim.Exponential(1)
buffer = sim.Resource(capacity=4)
bufferfront = sim.Resource()
bay = sim.Resource()
time_to_exit = 1
CarWash()
street = Street()

env.run(500)