Skip to content

Commit 4dcb9a2

Browse files
committed
Bugfix in Containers
Containers with Complex as the type of their capacity gave errors with put/get requests because z1 < z2 is normally not defined for complex numbers. Solution: Containers have been restricted to subtypes of Real instead of Number.
1 parent b191173 commit 4dcb9a2

File tree

2 files changed

+11
-11
lines changed

2 files changed

+11
-11
lines changed

Project.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
name = "SimJulia"
22
uuid = "428bdadb-6287-5aa5-874b-9969638295fd"
3-
repo = "https://github.com/BenLauwens/SimJulia.jl.git"
43
keywords = ["discrete-even simulation"]
54
license = "MIT"
65
desc = "A discrete event process oriented simulation framework."
76
authors = ["Ben Lauwens <[email protected]>"]
8-
version = "0.8.1"
7+
repo = "https://github.com/BenLauwens/SimJulia.jl.git"
8+
version = "0.8.2"
99

1010
[deps]
1111
DataStructures = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
1212
Dates = "ade2ca70-3891-5945-98fb-dc099432e06a"
1313
ResumableFunctions = "c5292f4c-5179-55e1-98c5-05642aab7184"
1414

1515
[compat]
16-
julia = ">=1.2"
1716
ResumableFunctions = ">=0.5.1"
17+
julia = ">=1.2"
1818

1919
[extras]
2020
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

src/resources/containers.jl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,28 @@
1-
struct ContainerKey{N<:Number} <: ResourceKey
1+
struct ContainerKey{N<:Real} <: ResourceKey
22
priority :: Int
33
id :: UInt
44
amount :: N
55
end
66

7-
mutable struct Container{N<:Number} <: AbstractResource
7+
mutable struct Container{N<:Real} <: AbstractResource
88
env :: Environment
99
capacity :: N
1010
level :: N
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=one(N); level::N=zero(N)) where {N<:Number}
14+
function Container{N}(env::Environment, capacity::N=one(N); level::N=zero(N)) where {N<:Real}
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=one(N); level::N=zero(N)) where N<:Number
19+
function Container(env::Environment, capacity::N=one(N); level::N=zero(N)) where N<:Real
2020
Container{N}(env, capacity, level=level)
2121
end
2222

2323
const Resource = Container{Int}
2424

25-
function put(con::Container{N}, amount::N; priority::Int=0) where N<:Number
25+
function put(con::Container{N}, amount::N; priority::Int=0) where N<:Real
2626
put_ev = Put(con.env)
2727
con.put_queue[put_ev] = ContainerKey(priority, con.seid+=one(UInt), amount)
2828
@callback trigger_get(put_ev, con)
@@ -32,7 +32,7 @@ end
3232

3333
request(res::Resource; priority::Int=0) = put(res, 1; priority=priority)
3434

35-
function get(con::Container{N}, amount::N; priority::Int=0) where N<:Number
35+
function get(con::Container{N}, amount::N; priority::Int=0) where N<:Real
3636
get_ev = Get(con.env)
3737
con.get_queue[get_ev] = ContainerKey(priority, con.seid+=one(UInt), amount)
3838
@callback trigger_put(get_ev, con)
@@ -42,14 +42,14 @@ end
4242

4343
release(res::Resource; priority::Int=0) = get(res, 1; priority=priority)
4444

45-
function do_put(con::Container{N}, put_ev::Put, key::ContainerKey{N}) where N<:Number
45+
function do_put(con::Container{N}, put_ev::Put, key::ContainerKey{N}) where N<:Real
4646
con.level + key.amount > con.capacity && return false
4747
schedule(put_ev)
4848
con.level += key.amount
4949
true
5050
end
5151

52-
function do_get(con::Container{N}, get_ev::Get, key::ContainerKey{N}) where N<:Number
52+
function do_get(con::Container{N}, get_ev::Get, key::ContainerKey{N}) where N<:Real
5353
con.level - key.amount < zero(N) && return false
5454
schedule(get_ev)
5555
con.level -= key.amount

0 commit comments

Comments
 (0)