|
12 | 12 | "cell_type": "markdown", |
13 | 13 | "metadata": {}, |
14 | 14 | "source": [ |
15 | | - "## Description" |
16 | | - ] |
17 | | - }, |
18 | | - { |
19 | | - "cell_type": "markdown", |
20 | | - "metadata": {}, |
21 | | - "source": [ |
| 15 | + "## Description\n", |
| 16 | + "\n", |
22 | 17 | "A system needs $n$ working machines to be operational. To guard against machine breakdown, additional machines are kept available as spares. Whenever a machine breaks down it is immediately replaced by a spare and is itself sent to the repair facility, which consists of a single repairperson who repairs failed machines one at a time. Once a failed machine has been repaired it becomes available as a spare to be used when the need arises. All repair times are independent random variables having the common distribution function $G$. Each time a machine is put into use the amount of time it functions before breaking down is a random variable, independent of the past, having distribution function $F$.\n", |
23 | 18 | "\n", |
24 | 19 | "The system is said to “crash” when a machine fails and no spares are available. Assuming that there are initially $n + s$ functional machines of which $n$ are put in use and $s$ are kept as spares, we are interested in simulating this system so as to approximate $E[T]$, where $T$ is the time at which the system crashes." |
|
53 | 48 | }, |
54 | 49 | { |
55 | 50 | "cell_type": "code", |
56 | | - "execution_count": 1, |
| 51 | + "execution_count": null, |
57 | 52 | "metadata": { |
58 | 53 | "collapsed": true |
59 | 54 | }, |
|
73 | 68 | }, |
74 | 69 | { |
75 | 70 | "cell_type": "code", |
76 | | - "execution_count": 2, |
| 71 | + "execution_count": null, |
77 | 72 | "metadata": { |
78 | 73 | "collapsed": false |
79 | 74 | }, |
|
96 | 91 | }, |
97 | 92 | { |
98 | 93 | "cell_type": "code", |
99 | | - "execution_count": 7, |
| 94 | + "execution_count": null, |
100 | 95 | "metadata": { |
101 | 96 | "collapsed": false |
102 | 97 | }, |
103 | | - "outputs": [ |
104 | | - { |
105 | | - "ename": "LoadError", |
106 | | - "evalue": "\u001b[91mMethodError: no method matching start(::Void)\u001b[0m\nClosest candidates are:\n start(\u001b[91m::SimpleVector\u001b[39m) at essentials.jl:258\n start(\u001b[91m::Base.MethodList\u001b[39m) at reflection.jl:560\n start(\u001b[91m::ExponentialBackOff\u001b[39m) at error.jl:107\n ...\u001b[39m", |
107 | | - "output_type": "error", |
108 | | - "traceback": [ |
109 | | - "\u001b[91mMethodError: no method matching start(::Void)\u001b[0m\nClosest candidates are:\n start(\u001b[91m::SimpleVector\u001b[39m) at essentials.jl:258\n start(\u001b[91m::Base.MethodList\u001b[39m) at reflection.jl:560\n start(\u001b[91m::ExponentialBackOff\u001b[39m) at error.jl:107\n ...\u001b[39m", |
110 | | - "" |
111 | | - ] |
112 | | - } |
113 | | - ], |
| 98 | + "outputs": [], |
114 | 99 | "source": [ |
115 | 100 | "@resumable function machine(sim::Simulation, repair_facility::Resource, spares::Store{Coroutine})\n", |
116 | | - " dist_work = Exponential(LAMBDA)\n", |
117 | | - " dist_repair = Exponential(MU)\n", |
| 101 | + " F = Exponential(LAMBDA)\n", |
| 102 | + " G = Exponential(MU)\n", |
118 | 103 | " while true\n", |
119 | | - " try \n", |
| 104 | + " try\n", |
120 | 105 | " @yield Timeout(sim, Inf)\n", |
121 | | - " catch\n", |
| 106 | + " catch exc\n", |
122 | 107 | " end\n", |
123 | 108 | " #println(\"At time $(now(sim)): $(active_process(sim)) starts working.\")\n", |
124 | | - " @yield Timeout(sim, rand(dist_work))\n", |
| 109 | + " @yield Timeout(sim, rand(F))\n", |
125 | 110 | " #println(\"At time $(now(sim)): $(active_process(sim)) stops working.\")\n", |
126 | 111 | " get_spare = Get(spares)\n", |
127 | 112 | " @yield get_spare | Timeout(sim, 0.0)\n", |
|
132 | 117 | " end\n", |
133 | 118 | " @yield Request(repair_facility)\n", |
134 | 119 | " #println(\"At time $(now(sim)): $(active_process(sim)) repair starts.\")\n", |
135 | | - " @yield Timeout(sim, rand(dist_repair))\n", |
| 120 | + " @yield Timeout(sim, rand(G))\n", |
136 | 121 | " @yield Release(repair_facility)\n", |
137 | 122 | " #println(\"At time $(now(sim)): $(active_process(sim)) is repaired.\")\n", |
138 | 123 | " @yield Put(spares, active_process(sim))\n", |
139 | 124 | " end\n", |
140 | | - "end\n" |
| 125 | + "end" |
141 | 126 | ] |
142 | 127 | }, |
143 | 128 | { |
|
149 | 134 | }, |
150 | 135 | { |
151 | 136 | "cell_type": "code", |
152 | | - "execution_count": 4, |
| 137 | + "execution_count": null, |
153 | 138 | "metadata": { |
154 | 139 | "collapsed": false |
155 | 140 | }, |
156 | | - "outputs": [ |
157 | | - { |
158 | | - "data": { |
159 | | - "text/plain": [ |
160 | | - "start_sim (generic function with 1 method)" |
161 | | - ] |
162 | | - }, |
163 | | - "execution_count": 4, |
164 | | - "metadata": {}, |
165 | | - "output_type": "execute_result" |
166 | | - } |
167 | | - ], |
| 141 | + "outputs": [], |
168 | 142 | "source": [ |
169 | 143 | "@resumable function start_sim(sim::Simulation, repair_facility::Resource, spares::Store{Coroutine})\n", |
170 | 144 | " procs = Coroutine[]\n", |
|
190 | 164 | }, |
191 | 165 | { |
192 | 166 | "cell_type": "code", |
193 | | - "execution_count": 5, |
| 167 | + "execution_count": null, |
194 | 168 | "metadata": { |
195 | 169 | "collapsed": false |
196 | 170 | }, |
197 | | - "outputs": [ |
198 | | - { |
199 | | - "data": { |
200 | | - "text/plain": [ |
201 | | - "sim_repair (generic function with 1 method)" |
202 | | - ] |
203 | | - }, |
204 | | - "execution_count": 5, |
205 | | - "metadata": {}, |
206 | | - "output_type": "execute_result" |
207 | | - } |
208 | | - ], |
| 171 | + "outputs": [], |
209 | 172 | "source": [ |
210 | 173 | "function sim_repair()\n", |
211 | 174 | " sim = Simulation()\n", |
|
228 | 191 | }, |
229 | 192 | { |
230 | 193 | "cell_type": "code", |
231 | | - "execution_count": 6, |
| 194 | + "execution_count": null, |
232 | 195 | "metadata": { |
233 | 196 | "collapsed": false |
234 | 197 | }, |
235 | | - "outputs": [ |
236 | | - { |
237 | | - "ename": "LoadError", |
238 | | - "evalue": "\u001b[91mUndefVarError: machine not defined\u001b[39m", |
239 | | - "output_type": "error", |
240 | | - "traceback": [ |
241 | | - "\u001b[91mUndefVarError: machine not defined\u001b[39m", |
242 | | - "", |
243 | | - "Stacktrace:", |
244 | | - " [1] \u001b[1mmacro expansion\u001b[22m\u001b[22m at \u001b[1m/home/juser/.julia/v0.6/ResumableFunctions/src/transforms.jl:16\u001b[22m\u001b[22m [inlined]", |
245 | | - " [2] \u001b[1mmacro expansion\u001b[22m\u001b[22m at \u001b[1m./In[4]:14\u001b[22m\u001b[22m [inlined]", |
246 | | - " [3] \u001b[1mmacro expansion\u001b[22m\u001b[22m at \u001b[1m/home/juser/.julia/v0.6/ResumableFunctions/src/macro.jl:66\u001b[22m\u001b[22m [inlined]", |
247 | | - " [4] \u001b[1m(::##660)\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::Void\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m/home/juser/.julia/v0.6/ResumableFunctions/src/macrotoolutils.jl:99\u001b[22m\u001b[22m", |
248 | | - " [5] \u001b[1mexecute\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::SimJulia.Timeout, ::SimJulia.Coroutine\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m/home/juser/.julia/v0.6/SimJulia/src/coroutines.jl:27\u001b[22m\u001b[22m", |
249 | | - " [6] \u001b[1m(::SimJulia.##3#4{SimJulia.#execute,SimJulia.Timeout,Tuple{SimJulia.Coroutine}})\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m/home/juser/.julia/v0.6/SimJulia/src/base.jl:43\u001b[22m\u001b[22m", |
250 | | - " [7] \u001b[1mstep\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::SimJulia.Simulation\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m/home/juser/.julia/v0.6/SimJulia/src/simulations.jl:39\u001b[22m\u001b[22m", |
251 | | - " [8] \u001b[1mrun\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m::SimJulia.Simulation, ::SimJulia.Timeout\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m/home/juser/.julia/v0.6/SimJulia/src/base.jl:87\u001b[22m\u001b[22m", |
252 | | - " [9] \u001b[1msim_repair\u001b[22m\u001b[22m\u001b[1m(\u001b[22m\u001b[22m\u001b[1m)\u001b[22m\u001b[22m at \u001b[1m./In[5]:6\u001b[22m\u001b[22m", |
253 | | - " [10] \u001b[1mmacro expansion\u001b[22m\u001b[22m at \u001b[1m./In[6]:4\u001b[22m\u001b[22m [inlined]", |
254 | | - " [11] \u001b[1manonymous\u001b[22m\u001b[22m at \u001b[1m./<missing>:?\u001b[22m\u001b[22m" |
255 | | - ] |
256 | | - } |
257 | | - ], |
| 198 | + "outputs": [], |
258 | 199 | "source": [ |
259 | 200 | "srand(SEED)\n", |
260 | 201 | "results = Float64[]\n", |
|
264 | 205 | "println(sum(results)/RUNS)" |
265 | 206 | ] |
266 | 207 | }, |
| 208 | + { |
| 209 | + "cell_type": "code", |
| 210 | + "execution_count": null, |
| 211 | + "metadata": { |
| 212 | + "collapsed": true |
| 213 | + }, |
| 214 | + "outputs": [], |
| 215 | + "source": [] |
| 216 | + }, |
267 | 217 | { |
268 | 218 | "cell_type": "code", |
269 | 219 | "execution_count": null, |
|
0 commit comments