Debian Codegraph @

docs/examples/Machineshop.py

raw symbols SCIP
1 from SimPy.Simulation import *
2 import random
3 """
4 Machineshop Model
5
6 An example showing interrupts and priority queuing.
7
8 Scenario:
9
10 A workshop has n identical machines. A stream of jobs (enough to keep
11 the machines busy) arrives. Each machine breaks down
12 periodically. Repairs are carried out by one repairman. The repairman
13 has other, less important tasks to perform, too. Once he starts one of
14 those, he completes it before starting with the machine repair. The
15 workshop works continously. """
16
17 ## Model components ------------------------
18
19 class Machine(Process):
20 def __init__(self,name):
21 Process.__init__(self,name)
22 myBreaker=Breakdown(self)
23 activate(myBreaker,myBreaker.breakmachine())
24 self.partsMade=0
25
26 def working(self):
27 while True:
28 yield hold,self,timePerPart()
29 if self.interrupted():
30 # broken down
31 parttimeleft=self.interruptLeft
32 yield request,self,repairman,1
33 yield hold,self,repairtime
34 #repaired
35 yield release,self,repairman
36 yield hold,self,parttimeleft
37 # part completed
38 self.partsMade += 1
39 else:
40 #part made
41 self.partsMade += 1
42
43 class Breakdown(Process):
44 def __init__(self,myMachine):
45 Process.__init__(self)
46 self.myMachine=myMachine
47
48 def breakmachine(self):
49 while True:
50 yield hold,self,timeToFailure()
51 self.interrupt(self.myMachine)
52
53 class OtherJobs(Process):
54 def __init__(self):
55 Process.__init__(self)
56
57 def doingJobs(self):
58 while True:
59 yield request,self,repairman,0
60 #starts working on jobs
61 yield hold,self,jobDuration
62 yield release,self,repairman
63
64 def timePerPart():
65 return random.normalvariate(processingTimeMean,processingTimeSigma)
66
67 def timeToFailure():
68 return random.expovariate(mean)
69
70 ## Experiment data -------------------------
71
72 repairtime=30.0 # minutes
73 processingTimeMean=10.0 # minutes
74 processingTimeSigma=2.0
75 timeToFailureMean = 300.0 # minutes
76 mean=1/timeToFailureMean # per minute
77 jobDuration=30 # minutes
78 nrMachines=10
79 random.seed(111333555)
80 weeks = 4 # weeks
81 simTime = weeks*24*60*7 ## minutes
82
83 ## Model/Experiment ------------------------------
84
85 print 'Machineshop'
86 initialize()
87 repairman=Resource(capacity=1,qType=PriorityQ)
88 m={}
89 for i in range(nrMachines):
90 m[i+1]=Machine(name="Machine %s" %(i+1))
91 activate(m[i+1],m[i+1].working())
92 oj=OtherJobs()
93 activate(oj,oj.doingJobs())
94 simulate(until=simTime) ## minutes
95
96 ## Analysis/output -------------------------
97
98 print "Machineshop results after %s weeks"%weeks
99 for i in range(nrMachines):
100 print "Machine %s: %s" %(i+1,m[i+1].partsMade)
101