Skip to content

Commit

Permalink
Adding the possibility to generate more than one message at once
Browse files Browse the repository at this point in the history
  • Loading branch information
Mallets committed Aug 2, 2019
2 parents c15afad + 8efa582 commit 3ac3ae7
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 6 deletions.
2 changes: 1 addition & 1 deletion docs/conf.py
Expand Up @@ -63,7 +63,7 @@
# The short X.Y version.
version = '1.0.0'
# The full version, including alpha/beta/rc tags.
release = 'rc9'
release = 'rc10'

# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.
Expand Down
27 changes: 27 additions & 0 deletions docs/tutorial/random.rst
Expand Up @@ -83,6 +83,33 @@ The arrival time of a generator is described with a :class:`~simpype.random.Rand
Please note that in this case there is no need of calling the ``simpype.Random`` constructor.
The generator object automatically converts the dictionary into a :class:`~simpype.random.Random` object.

Generation of more than one message at once
===========================================

The number of messages to be generated at any arrival time is described with a :class:`~simpype.random.Random` variable.

.. code-block:: python
import simpype
import random
sim = simpype.Simulation(id = 'simple')
gen0 = sim.add_generator(id = 'gen0')
# Arrival time of 1 second
gen0.random['arrival'] = {0: lambda: 1}
# Start generating events at a random simulation time
gen0.random['quantity'] = {
# From t=0 to t=10, 3 messages are generated at once
0 : lambda: 3,
# From t=10 to t=20, a random number of messages (between 1 and 10) is generated at once
10 : lambda: random.randint(1, 10),
# From t=20 to t=inf, 1 message is generated everytime
20 : lambda: 1
}
Please note that in this case there is no need of calling the ``simpype.Random`` constructor.
The generator object automatically converts the dictionary into a :class:`~simpype.random.Random` object.

Resource service time
=====================

Expand Down
2 changes: 1 addition & 1 deletion setup.py
Expand Up @@ -14,7 +14,7 @@
# Versions should comply with PEP440. For a discussion on single-sourcing
# the version across setup.py and the project code, see
# https://packaging.python.org/en/latest/single_source_version.html
version='1.0.0.rc9',
version='1.0.0.rc10',
description='SimPype is a simulation framework based on Simpy that relies on the concepts of resource and pipe.',
long_description=long_description,
# The project's main homepage.
Expand Down
2 changes: 1 addition & 1 deletion simpype/__init__.py
Expand Up @@ -58,4 +58,4 @@ def compile_toc(entries, section_marker='='):
__all__ = [obj.__name__ for section, objs in toc for obj in objs]

__path__ = extend_path(__path__, __name__)
__version__ = '1.0.0.rc9'
__version__ = '1.0.0.rc10'
8 changes: 5 additions & 3 deletions simpype/model/generator.py
Expand Up @@ -10,6 +10,7 @@ def __init__(self, sim, id):
# Init
self.message.is_alive = False
self.random['arrival'] = {0: lambda: float("inf")}
self.random['quantity'] = {0: lambda: 1}
self.a_gen = self.env.process(self.h_gen())

def gen_message(self):
Expand All @@ -31,9 +32,10 @@ def h_gen(self):
more = False
else:
yield self.env.timeout(val)
message = self.gen_message()
self.send(message)
self.counter = self.counter + 1
for i in range(0, self.random['quantity'].value):
message = self.gen_message()
self.send(message)
self.counter = self.counter + 1

# Do NOT remove
resource = lambda *args: Generator(*args)
8 changes: 8 additions & 0 deletions tests/all.py
Expand Up @@ -354,6 +354,14 @@ def enqueue(self, message):
res24.pipe.queue['default'].log = False
p24 = sim.add_pipeline(gen24, res24)

# Gen25 |-> Res25
gen25 = sim.add_generator(id = 'gen25')
gen25.random['arrival'] = {0: lambda: 1.0}
gen25.random['quantity'] = {0: lambda: random.randint(1,10)}
res25 = sim.add_resource(id = 'res25')
res25.random['service'] = {0: lambda: 1.0}
p25 = sim.add_pipeline(gen25, res25)

sim.log.file = True
sim.log.print = False
sim.run(until = 30)
Expand Down

0 comments on commit 3ac3ae7

Please sign in to comment.