File: car.py

package info (click to toggle)
python-simpy 2.3.1%2Bdfsg-6
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 11,864 kB
  • sloc: python: 11,171; makefile: 143
file content (21 lines) | stat: -rw-r--r-- 680 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
from SimPy.Simulation import Process, activate, hold, initialize, now, simulate


class Car(Process):
    def __init__(self, name, cc):
        Process.__init__(self, name=name)
        self.cc = cc

    def go(self):
        print('%s %s %s' % (now(), self.name, 'Starting'))
        yield hold, self, 100.0
        print('%s %s %s' % (now(), self.name, 'Arrived'))


initialize()
c1 = Car('Car1', 2000)                # a new car
activate(c1, c1.go(), at=6.0)    # activate at time 6.0
c2 = Car('Car2', 1600)                # another new car
activate(c2, c2.go())                # activate at time 0
simulate(until=200)
print('Current time is %s' % now())    # will print 106.0