Skip to content

Commit 2354d26

Browse files
committed
add LimitedExponential example to docs
1 parent 8a6f17d commit 2354d26

1 file changed

Lines changed: 27 additions & 0 deletions

File tree

docs/Guides/time_dependent.rst

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,3 +119,30 @@ Now to test if this is working, the average service time should be roughly equal
119119
>>> (-0.05 * average_queue_size) + 0.2
120120
0.1547408...
121121

122+
For arrival distributions - when creating the :code:`Simulation` object, the distribution objects are given a :code:`.simulation` attribute, so something similar can happen. For example, the following distribution will sample form an Exponential distribution unil :code:`limit` number of individuals has been sampled::
123+
124+
>>> class LimitedExponential(ciw.dists.Exponential):
125+
... def __init__(self, rate, limit):
126+
... super().__init__(rate)
127+
... self.limit = limit
128+
...
129+
... def sample(self, t=None, ind=None):
130+
... if self.simulation.nodes[0].number_of_individuals < self.limit:
131+
... return super().sample()
132+
... else:
133+
... return float('Inf')
134+
135+
And to see it working, a limit of 44 individuals::
136+
137+
>>> N = ciw.create_network(
138+
... arrival_distributions=[LimitedExponential(1, 44)],
139+
... service_distributions=[ciw.dists.Exponential(3)],
140+
... number_of_servers=[2]
141+
... )
142+
143+
>>> ciw.seed(0)
144+
>>> Q = ciw.Simulation(N)
145+
>>> Q.simulate_until_max_time(3000)
146+
>>> recs = Q.get_all_records()
147+
>>> len(recs)
148+
44

0 commit comments

Comments
 (0)