diff --git a/docs/source/getting-started.rst b/docs/source/getting-started.rst index 203c756..25a65e2 100644 --- a/docs/source/getting-started.rst +++ b/docs/source/getting-started.rst @@ -16,44 +16,55 @@ Install SimPM from PyPI: A minimal example ----------------- -This minimal model represents a single project activity that requires one crew. -The activity waits until the crew is available, works for a random duration, and then finishes. +This minimal model represents a single project activity that requires one crew. +The activity waits until the crew is available, performs the work, and then releases +the resource. The SimPM engine models activities with ``do`` (time spent working) +and ``get`` / ``put`` (queueing for and releasing resources), rather than raw +``timeout`` calls. + This example shows how to: - Create a :class:`simpm.des.Environment` - Define a simple :class:`simpm.des.Resource` -- Run the simulation -- Inspect basic outputs (duration and finish time) +- Model work with :class:`simpm.des.Entity` using ``do`` and ``get`` +- Run the simulation and inspect basic outputs .. code-block:: python + import simpm from simpm.des import Environment, Resource from simpm.dist import norm # 1) Create the simulation environment - env = Environment() + env = Environment("Single activity") # 2) Define resources (e.g., one crew) - crew = Resource(env, capacity=1, name="Crew 1") + crew = Resource(env, name="Crew 1", capacity=1) + + # 3) Create an entity to perform the activity + (activity_entity,) = env.create_entities("Activity", 1, print_actions=False, log=True) - # 3) Define an activity process - def activity(env, resource, name): + # 4) Define the activity process + def activity(entity, resource): # Request one unit of the crew resource and wait until it is available - yield resource.request() + yield entity.get(resource, 1) # Perform the work duration = norm(10, 2).sample() - yield env.timeout(duration) + yield entity.do("work", duration) + + # Release the crew + yield entity.put(resource, 1) - print(f"{env.now:.2f}: {name} finished (duration={duration:.2f})") + print(f"{entity.env.now:.2f}: {entity} finished (duration={duration:.2f})") - # 4) Create entities / activities - env.process(activity(env, crew, "Activity A")) + env.process(activity(activity_entity, crew)) # 5) Run the simulation - env.run() + simpm.run(env) print(f"Project finished at t={env.now:.2f}") + print(activity_entity.schedule()) Next steps ----------