Skip to content

Commit a59cec9

Browse files
committed
Modify constructors for Store and Container
1 parent cdfb47a commit a59cec9

7 files changed

Lines changed: 24 additions & 44 deletions

File tree

benchmark/coroutines_MM1.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ end
1717

1818
function test_mm1(n::Float64)
1919
sim = Simulation()
20-
server = Resource(sim, 1)
20+
server = Resource(sim)
2121
@coroutine exp_source(sim, 1.0, server, 1.1)
2222
run(sim, n)
2323
end

benchmark/processes_MM1.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ end
2525

2626
function test_mm1(n::Float64)
2727
sim = Simulation()
28-
server = Resource(sim, 1)
28+
server = Resource(sim)
2929
@process exp_source(sim, 1.0, server, 1.1)
3030
run(sim, n)
3131
end

examples/Ross_Simulation_7.7_A_repair_problem.ipynb

Lines changed: 16 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@
2929
{
3030
"cell_type": "code",
3131
"execution_count": null,
32-
"metadata": {
33-
"collapsed": false
34-
},
32+
"metadata": {},
3533
"outputs": [],
3634
"source": [
3735
"Pkg.update()\n",
@@ -48,7 +46,7 @@
4846
},
4947
{
5048
"cell_type": "code",
51-
"execution_count": 13,
49+
"execution_count": 1,
5250
"metadata": {
5351
"collapsed": true
5452
},
@@ -68,10 +66,8 @@
6866
},
6967
{
7068
"cell_type": "code",
71-
"execution_count": 14,
72-
"metadata": {
73-
"collapsed": false
74-
},
69+
"execution_count": 2,
70+
"metadata": {},
7571
"outputs": [],
7672
"source": [
7773
"const RUNS = 5\n",
@@ -95,18 +91,16 @@
9591
},
9692
{
9793
"cell_type": "code",
98-
"execution_count": 15,
99-
"metadata": {
100-
"collapsed": false
101-
},
94+
"execution_count": 3,
95+
"metadata": {},
10296
"outputs": [
10397
{
10498
"data": {
10599
"text/plain": [
106100
"machine (generic function with 1 method)"
107101
]
108102
},
109-
"execution_count": 15,
103+
"execution_count": 3,
110104
"metadata": {},
111105
"output_type": "execute_result"
112106
}
@@ -147,18 +141,16 @@
147141
},
148142
{
149143
"cell_type": "code",
150-
"execution_count": 16,
151-
"metadata": {
152-
"collapsed": false
153-
},
144+
"execution_count": 4,
145+
"metadata": {},
154146
"outputs": [
155147
{
156148
"data": {
157149
"text/plain": [
158150
"start_sim (generic function with 1 method)"
159151
]
160152
},
161-
"execution_count": 16,
153+
"execution_count": 4,
162154
"metadata": {},
163155
"output_type": "execute_result"
164156
}
@@ -188,18 +180,16 @@
188180
},
189181
{
190182
"cell_type": "code",
191-
"execution_count": 17,
192-
"metadata": {
193-
"collapsed": false
194-
},
183+
"execution_count": 5,
184+
"metadata": {},
195185
"outputs": [
196186
{
197187
"data": {
198188
"text/plain": [
199189
"sim_repair (generic function with 1 method)"
200190
]
201191
},
202-
"execution_count": 17,
192+
"execution_count": 5,
203193
"metadata": {},
204194
"output_type": "execute_result"
205195
}
@@ -208,7 +198,7 @@
208198
"function sim_repair()\n",
209199
" sim = Simulation()\n",
210200
" repair_facility = Resource(sim)\n",
211-
" spares = Store(Coroutine, sim)\n",
201+
" spares = Store{Coroutine}(sim)\n",
212202
" @coroutine start_sim(sim, repair_facility, spares)\n",
213203
" msg = run(sim)\n",
214204
" stop_time = now(sim)\n",
@@ -226,10 +216,8 @@
226216
},
227217
{
228218
"cell_type": "code",
229-
"execution_count": 18,
230-
"metadata": {
231-
"collapsed": false
232-
},
219+
"execution_count": 6,
220+
"metadata": {},
233221
"outputs": [
234222
{
235223
"name": "stdout",

src/resources/containers.jl

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,17 @@ mutable struct Container{N<:Number} <: AbstractResource
1111
seid :: UInt
1212
put_queue :: DataStructures.PriorityQueue{Put, ContainerKey{N}}
1313
get_queue :: DataStructures.PriorityQueue{Get, ContainerKey{N}}
14-
function Container{N}(env::Environment, capacity::N, level::N) where {N<:Number}
14+
function Container{N}(env::Environment, capacity::N=one(N); level::N=zero(N)) where {N<:Number}
1515
new(env, capacity, level, zero(UInt), DataStructures.PriorityQueue{Put, ContainerKey{N}}(), DataStructures.PriorityQueue{Get, ContainerKey{N}}())
1616
end
1717
end
1818

19-
function Container(env::Environment, capacity::N; level::N=zero(N)) where N<:Number
20-
Container{N}(env, capacity, level)
19+
function Container(env::Environment, capacity::N=one(N); level::N=zero(N)) where N<:Number
20+
Container{N}(env, capacity, level=level)
2121
end
2222

2323
const Resource = Container{Int}
2424

25-
function Resource(env::Environment, capacity::Int=1; level::Int=0) :: Resource
26-
Resource(env, capacity, level)
27-
end
28-
2925
function Put(con::Container{N}, amount::N; priority::Int=0) where N<:Number
3026
put_ev = Put(con.env)
3127
con.put_queue[put_ev] = ContainerKey(priority, con.seid+=one(UInt), amount)

src/resources/stores.jl

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,11 @@ mutable struct Store{T} <: AbstractResource
1818
seid :: UInt
1919
put_queue :: DataStructures.PriorityQueue{Put, StorePutKey{T}}
2020
get_queue :: DataStructures.PriorityQueue{Get, StoreGetKey}
21-
function Store{T}(env::Environment, capacity::UInt) where {T}
21+
function Store{T}(env::Environment; capacity::UInt=typemax(UInt)) where {T}
2222
new(env, capacity, Set{T}(), zero(UInt), DataStructures.PriorityQueue{Put, StorePutKey{T}}(), DataStructures.PriorityQueue{Get, StoreGetKey}())
2323
end
2424
end
2525

26-
function Store(t::Type, env::Environment, capacity::UInt=typemax(UInt))
27-
Store{t}(env, capacity)
28-
end
29-
3026
function Put(sto::Store{T}, item::T; priority::Int=0) where T
3127
put_ev = Put(sto.env)
3228
sto.put_queue[put_ev] = StorePutKey{T}(priority, sto.seid+=one(UInt), item)

test/containers.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,6 @@ function customer(sim::Simulation, server::Resource, i::Int)
7979
end
8080

8181
sim = Simulation()
82-
server = Resource(sim, 1)
82+
server = Resource(sim)
8383
@process source(sim, server)
8484
run(sim, 10.0)

test/stores.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ end
2424
end
2525

2626
sim = Simulation()
27-
sto = Store(StoreObject, sim)
27+
sto = Store{StoreObject}(sim)
2828
@coroutine my_consumer(sim, sto)
2929
@coroutine my_producer(sim, sto)
3030
run(sim)

0 commit comments

Comments
 (0)