mosaik.util
— Utility classes and functions¶
This module contains some utility functions and classes.
- mosaik.util.connect_many_to_one(world, src_set, dest, *attrs, async_requests=False)¶
connect()
each entity in src_set to dest.See the
connect()
for more details.
- mosaik.util.connect_randomly(world, src_set, dest_set, *attrs, evenly=True, max_connects=inf)¶
Randomly
connect()
the entities from src_set to the entities from dest_set and return a subset of dest_set containing all entities with a connection.world is an instance of the
World
to which the entities belong.src_set and dest_set are iterables containing
Entity
instances. src_set may be empty, dest_set must not be empty. Each entity of src_set will be connected to an entity of dest_set, but not every entity of dest_set will necessarily have a connection (e.g., if you connect a set of three entities to a set of four entities). A set of all entities from dest_set, to which at least one entity from src_set was connected, will be returned.attrs is a list of attribute names of pairs as in
connect()
.If the flag evenly is set to
True
, entities connections will be distributed as evenly as possible. That means if you connect a set of three entities to a set of three entities, there will be three 1:1 connections; if you connect four entities to three entities, there will be one 2:1 and two 1:1 connections. If evenly is set toFalse
, connections will be truly random. That means if you connect three entities to three entities, you may either have three 1:1 connections, one 2:1 and two 1:1 connections or just one 3:1 connection.max_connects lets you set the maximum number of connections that an entity of dest_set may receive. This argument is only taken into account if evenly is set to
False
.