コード例 #1
0
ファイル: salabim_test.py プロジェクト: navneet-nmk/salabim
def test21():
#    d=sim.Pdf((sim.Uniform(10,20),10,sim.Uniform(20,30),80,sim.Uniform(30,40),10))
    d=sim.Pdf((sim.Uniform(10,20),sim.Uniform(20,30),sim.Uniform(30,40)),(10,80,10))


    for i in range(20):
        print (d.sample())
コード例 #2
0
 def process(self):
     while True:
         yield self.hold(thinkingtime_mean * sim.Uniform(0.5, 1.5)(),
                         mode='thinking')
         yield self.request(self.leftfork, self.rightfork, mode='waiting')
         yield self.hold(eatingtime_mean * sim.Uniform(0.5, 1.5)(),
                         mode='eating')
         self.release()
コード例 #3
0
ファイル: Dining philosophers.py プロジェクト: eebart/salabim
    def process(self):
        while True:
            thinkingtime = sim.Uniform(0.5, 1.5).sample() * thinkingtime_mean
            eatingtime = sim.Uniform(0.5, 1.5).sample() * eatingtime_mean

            yield self.hold(thinkingtime, mode='thinking')
            yield self.request(self.leftfork, self.rightfork, mode='waiting')
            yield self.hold(eatingtime, mode='eating')
            self.release()
コード例 #4
0
 def process(self):
     global status
     while (status=="active"):
         for _ in range(n_placas_dia):
             Placa()
             yield self.hold(sim.Uniform(5, 15).sample())
         for _ in range(n_rodas_dia):
             Roda()
             yield self.hold(sim.Uniform(5,15).sample())
         for _ in range(n_produtos_dia):    
             Finish()
             yield self.hold(sim.Uniform(5, 15).sample())
コード例 #5
0
 def process(self):
     # Attendo un tempo casuale tra oggi e il giorno dell'appuntamento per cancellarlo
     yield self.hold(
         sim.Uniform(
             0,
             int(self.appointment.info['relative_visit_day'] - env.now())))
     self.appointment.activate()
コード例 #6
0
ファイル: projeto.py プロジェクト: D4rkSilver911/SCC
    def process(self):
        global horario
        while (horario == "aberta"):
            
           
           

            for _ in range(n_placas_por_dia):
                Prancha()
                yield self.hold(sim.Uniform(5, 15).sample())
            for _ in range(n_rodas_por_dia):
                Roda()
                yield self.hold(sim.Uniform(5,15).sample())
            for _ in range(n_produtos_por_dia):
                Finish()
                yield self.hold(sim.Uniform(5, 15).sample())
コード例 #7
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()
コード例 #8
0
 def process(self):
     while True:
         yield self.hold(sim.Uniform(1, 5)())
         res = sim.Pdf(resources, 1)()
         yield self.request(res)
         yield self.hold(res.sequence_number() * 1 +
                         (env.now() % 24) * 0.01)
         self.release()
コード例 #9
0
 def process(self):
     while True:  # Continuous loop
         discharge_ports = ["Teeside", "Stenungsund", "Nynashamn", "Huelva"]
         Cargo(load_port="Rotterdam",
               discharge_port=random.choice(discharge_ports))
         yield self.hold(
             sim.Uniform(CARGO_INTERVAL_LOWER,
                         CARGO_INTERVAL_UPPER).sample())
コード例 #10
0
 def process(self):
     while True:
         Customer().enter(waitingline)
         for clerk in clerks:
             if clerk.ispassive():
                 clerk.activate()
                 break  # activate only one clerk
         yield self.hold(sim.Uniform(5, 15).sample())
コード例 #11
0
    def process(self):
        yield self.request(washers)
        duration = sim.Uniform(0, 5)()
        self.duration_anim = sim.AnimateRectangle((0, 0, duration * 10, 20), fillcolor='',
            linecolor='yellow', x=100, y=self.my_y, arg=self, parent=self)
        self.wait_anim.fillcolor = 'yellow'
        self.wait_anim.x = 100

        yield self.hold(duration)
コード例 #12
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()
コード例 #13
0
 def process(self):
     while True:  # Continuous loop
         while len(cargo_queue) == 0:
             yield self.passivate()
         print("Departure ballast to load port")
         yield self.hold(
             sim.Uniform(BALLAST_TRAVEL_TIME_MIN,
                         BALLAST_TRAVEL_TIME_MAX).sample())
         print("Arrive ballast at load port")
         self.cargo = cargo_queue.pop()
         print("Cargo loaded")
         print("Departure laden load port")
         yield self.hold(
             sim.Uniform(LADEN_TRAVEL_TIME_MIN,
                         LADEN_TRAVEL_TIME_MAX).sample())
         print("Arrive laden discharge port")
         self.cargo.activate()
         print("Cargo discharged")
コード例 #14
0
ファイル: salabim_test.py プロジェクト: navneet-nmk/salabim
def test39():
    class C(sim.Component):
        def process(self):
            yield self.request(r,s='y')

    env=sim.Environment(trace=True)
    x=sim.Uniform(4)
    r = sim.Resource()
    C()
    env.run(4)
コード例 #15
0
 def execute_voyage(self):
     print("{:.2f} - {}: Departure ballast to {}".format(
         env.now(), self.name(), self.cargo.load_port))
     yield self.hold(
         sim.Uniform(BALLAST_TRAVEL_TIME_MIN,
                     BALLAST_TRAVEL_TIME_MAX).sample())
     print("{:.2f} - {}: Arrive ballast at {}".format(
         env.now(), self.name(), self.cargo.load_port))
     yield self.hold(LOAD_DISCHARGE_TIME)
     print("{:.2f} - {}: Cargo loaded at {}".format(env.now(), self.name(),
                                                    self.cargo.load_port))
     print("{:.2f} - {}: Departure laden to {}".format(
         env.now(), self.name(), self.cargo.discharge_port))
     yield self.hold(
         sim.Uniform(LADEN_TRAVEL_TIME_MIN, LADEN_TRAVEL_TIME_MAX).sample())
     print("{:.2f} - {}: Arrive laden at {}".format(
         env.now(), self.name(), self.cargo.discharge_port))
     self.cargo.activate()
     print("{:.2f} - {}: Cargo discharged".format(env.now(), self.name()))
コード例 #16
0
 def execute_voyage(self):
     print("{:.2f} - {}: Departure ballast to {}".format(env.now(), self.name(), self.cargo.load_port))
     yield self.hold(sim.Uniform(BALLAST_TRAVEL_TIME_MIN, BALLAST_TRAVEL_TIME_MAX).sample())
     print("{:.2f} - {}: Arrive ballast at {}".format(env.now(), self.name(), self.cargo.load_port))
     yield self.hold(LOAD_DISCHARGE_TIME)
     print("{:.2f} - {}: Cargo loaded at {}".format(env.now(), self.name(), self.cargo.load_port))
     travel_time_laden = self.cargo.distance/CRUISE_SPEED/24
     print("{:.2f} - {}: Departure laden to {} (Distance: {} NM, Travel time: {:.2f} days)".format(env.now(), self.name(), self.cargo.discharge_port, self.cargo.distance, travel_time_laden))
     yield self.hold(travel_time_laden)
     print("{:.2f} - {}: Arrive laden at {}".format(env.now(), self.name(), self.cargo.discharge_port))
     self.cargo.activate()
     print("{:.2f} - {}: Cargo discharged".format(env.now(), self.name()))
コード例 #17
0
    def process(self):
        yield self.request(washers)
        duration = sim.Uniform(0, 5)()
        self.duration_anim = sim.AnimateRectangle(
            spec=(0, 0, duration * 10, 20),
            x=100,
            y=lambda arg, t: arg.index(self.queues()[0]) * 30 + 50,
            fillcolor='',
            linecolor='yellow',
            arg=self,
            parent=self)
        self.wait_anim.fillcolor = 'yellow'
        self.wait_anim.x = 100

        yield self.hold(duration)
コード例 #18
0
ファイル: salabim_test.py プロジェクト: antlaw0/salabim
def test3():
    print('test3')

    sim.Environment(random_seed=1234567)
    print('string')
    d = sim.Distribution('Exponential (1000)')
    sample_and_print(d, 5)
    sim.random_seed(1234567)
    sample_and_print(d, 5)
    sim.random_seed(None)
    sample_and_print(d, 5)

    print('triangular')
    tr = sim.Triangular(1, 5, 3)
    sample_and_print(tr, 5)

    print('uniform')
    u = sim.Uniform(1, 1.1)
    sample_and_print(u, 5)
    print('constant')
    c = sim.Constant(10)
    sample_and_print(c, 5)

    print('normal')
    n = sim.Normal(1, 2)
    sample_and_print(n, 5)
    sample_and_print(n, 5)

    print('cdf')
    cdf = sim.Cdf((1, 0, 2, 25, 2, 75, 3, 100))
    sample_and_print(cdf, 5)
    sample_and_print(cdf, 5)

    print('pdf')
    pdf = sim.Pdf((1, 2), 1)
    sample_and_print(pdf, 5)

    print('pdf 1')
    pdf = sim.Pdf((sim.Uniform(10, 20), 10, sim.Uniform(20, 30), 80,
                   sim.Uniform(30, 40), 10))
    sample_and_print(pdf, 5)

    print('pdf 2')
    pdf = sim.Pdf(
        (sim.Uniform(10, 20), sim.Uniform(20, 30), sim.Uniform(30, 40)),
        (10, 80, 10))
    sample_and_print(pdf, 5)

    print('pdf 3')
    pdf = sim.Pdf(('red', 'green', 1000), (10, 1, 10))
    sample_and_print(pdf, 5)
コード例 #19
0
ファイル: Bank Renege.py プロジェクト: oxinabox/salabim
    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')
コード例 #20
0
ファイル: demo wait.py プロジェクト: oxinabox/salabim
 def process(self):
     self.live_till = env.now() + int(sim.Uniform(60, 90).sample())
     env.print_trace('', '', 'going to live till',
                     '{:13.3f}'.format(self.live_till))
     if env.king is None:  # there is no king, so this prince will become king, immediately
         kings.append(('no king', env.lastkingdied, env.now(),
                       env.now() - env.lastkingdied))
         env.king = self
     else:
         yield self.wait((king_died, True, -env.now()),
                         fail_at=self.live_till)
         if self.failed():  # the prince dies before getting to the throne
             env.print_trace('', '', 'dies before getting to the throne')
             return
         env.king = self
     env.print_trace('', '', 'vive le roi!', env.king.name())
     kings.append((self.name(), env.now(), self.live_till,
                   self.live_till - env.now()))
     yield self.hold(till=self.live_till)
     env.print_trace('', '', 'Le roi est mort.')
     env.king = None
     king_died.trigger(max=1)
     if env.king is None:
         env.lastkingdied = env.now()
コード例 #21
0
    def process(self):
        while True:  # Infinite loop
            # Selects randomly the origin floor of that visitor
            fromfloor = floors[sim.IntUniform(self.from_[0], self.from_[1]).sample()]
            # Selects randomly the destination floor of that visitor
            while True:
                tofloor = floors[sim.IntUniform(self.to[0], self.to[1]).sample()]
                if fromfloor != tofloor:  # The selection is valid if origin and destination are different
                    break

            Visitor(fromfloor=fromfloor, tofloor=tofloor)  # Generates an instance of Visitor
            if self.id == "0_n":
                load = load_0_n
            elif self.id == "n_0":
                load = load_n_0
            else:
                load = load_n_n

            if load == 0:  # If there is no load then passivate the VisitorGenerator
                yield self.passivate()
            else:
                iat = 3600 / load
                r = sim.Uniform(0.5, 1.5).sample()
                yield self.hold(r * iat)  # Holds during interarrival time
コード例 #22
0
ファイル: Gas station.py プロジェクト: zixzeus/salabim
#  Gas station.py
import salabim as sim

#  based on SimPy example model

GAS_STATION_SIZE = 200.0  # liters
THRESHOLD = 25.0  # Threshold for calling the tank truck (in %)
FUEL_TANK_SIZE = 50.0  # liters
# Min/max levels of fuel tanks (in liters)
FUEL_TANK_LEVEL = sim.Uniform(5, 25)
REFUELING_SPEED = 2.0  # liters / second
TANK_TRUCK_TIME = 300.0  # Seconds it takes the tank truck to arrive
T_INTER = sim.Uniform(10, 100)  # Create a car every [min, max] seconds
SIM_TIME = 200000  # Simulation time in seconds


class Car(sim.Component):
    """
    A car arrives at the gas station for refueling.

    It requests one of the gas station's fuel pumps and tries to get the
    desired amount of gas from it. If the stations reservoir is
    depleted, the car has to wait for the tank truck to arrive.

    """
    def process(self):
        fuel_tank_level = int(FUEL_TANK_LEVEL.sample())
        yield self.request(gas_station)
        liters_required = FUEL_TANK_SIZE - fuel_tank_level
        if (fuel_pump.available_quantity() -
                liters_required) / fuel_pump.capacity() * 100 < THRESHOLD:
コード例 #23
0
 def process(self):
     while True:
         yield self.hold(sim.Uniform(0, 2)())
         Car()
コード例 #24
0
 def process(self):
     while True:
         yield self.hold(sim.Uniform(2,4).sample())
         dir=sim.Pdf(directions,1).sample()
         Car(dir=dir)
コード例 #25
0
ファイル: salabim_test.py プロジェクト: navneet-nmk/salabim
 def process(self):
     while True:
         yield self.wait((light.green,True,1),(light.green,True,1),fail_delay=8,all=True)
         yield self.hold(sim.Uniform(1,3).sample())
コード例 #26
0
ファイル: salabim_test.py プロジェクト: navneet-nmk/salabim
 def process(self):
     yield self.request(r)
     yield self.hold(sim.Uniform(0,2)())
コード例 #27
0
 def process(self):
     while True:
         yield self.hold(sim.Uniform(0, 20)())
         self.enter(q)
         yield self.hold(sim.Uniform(0, 20)())
         self.leave()
コード例 #28
0
ファイル: salabim_test.py プロジェクト: navneet-nmk/salabim
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)'))
コード例 #29
0
    def process(self):
        while True:
            yield self.request(res)
            yield self.hold(5)
            self.release(res)


class Part(sim.Component):
    def setup(self, machine):
        self.machine = machine

    def process(self):
        while True:
            yield self.hold(ttf())
            self.machine.interrupt()
            yield self.hold(ttr())
            self.machine.resume()


env = sim.Environment(trace=True)
ttf = sim.Uniform(10, 20)  # time to failure distribution
ttr = sim.Uniform(3, 6)  # time to repair distribution

res = sim.Resource()

for _ in range(2):
    Machine()

env.run(400)
コード例 #30
0
 def process(self):
     while True:
         Customer()
         yield self.hold(sim.Uniform(5, 15).sample())