BulletinBoard
- class negmas.situated.BulletinBoard[source]
Bases:
EventSource
,ConfigReader
The bulletin-board which carries all public information. It consists of sections each with a dictionary of records.
Attributes Summary
This property is intended for use only by the world manager.
Methods Summary
add_section
(name)Adds a section to the bulletin Board
announce
(event)Raises an event and informs all event sinks that are registered for notifications on this event type
from_config
(config[, section, ...])Creates an object of this class given the configuration info.
query
(section, query[, query_keys])Returns all records in the given section/sections of the bulletin-board that satisfy the query
read
(section, key)Reads the value associated with given key
read_config
(config[, section])Reads the configuration from a file or a dict and prepares it for parsing.
record
(section, value[, key])Records data in the given section of the bulletin-board
register_listener
(event_type, listener)Registers a listener for the given event_type.
remove
(section, *[, query, key, query_keys, ...])Removes a value or a set of values from the bulletin Board
satisfies
(value, query)- rtype:
Attributes Documentation
- data
This property is intended for use only by the world manager. No other agent is allowed to use it
Methods Documentation
- announce(event)
Raises an event and informs all event sinks that are registered for notifications on this event type
- classmethod from_config(config, section=None, ignore_children=True, try_parsing_children=True, scope=None)
Creates an object of this class given the configuration info.
- Parameters:
section (
str
|None
) – A section in the file or a key in the dictionary to use for loading paramsignore_children (
bool
) – If true then children will be ignored and there will be a single returntry_parsing_children (
bool
) – If true the children will first be parsed asConfigReader
classes if they are notint (simple types (e.g.)
str
float
Iterable[int|str|float]
scope – The scope at which to evaluate any child classes. This MUST be passed as scope=globals() if you are
parsed. (having any children that are to be)
- Returns:
An object of cls if ignore_children is True or a tuple with an object of cls and a dictionary with children that were not parsed.
Remarks:
This function will return an object of its class after passing the key-value pairs found in the config to the init function.
Requiring passing scope=globals() to this function is to get around the fact that in python eval() will be called with a globals dictionary based on the module in which the function is defined not called. This means that in general when eval() is called to create the children, it will not have access to the class definitions of these children (except if they happen to be imported in this file). To avoid this problem causing an undefined_name exception, the caller must pass her globals() as the scope.
- query(section, query, query_keys=False)[source]
Returns all records in the given section/sections of the bulletin-board that satisfy the query
- Parameters:
section (
str
|list
[str
] |None
) – Either a section name, a list of sections or None specifying ALL public sections (see remarks)query (
Any
) – The query which is USUALLY a dict with conditions on it when querying values and a RegExp whenkeys (querying)
query_keys – Whether the query is to be applied to the keys or values.
- Returns:
value pairs giving all records that satisfied the given requirements.
- Return type:
A dictionary with key
Remarks:
A public section is a section with a name that does not start with an underscore
If a set of sections is given, and two records in different sections had the same key, only one of them will be returned
Key queries use regular expressions and match from the beginning using the standard re.match function
- classmethod read_config(config, section=None)
Reads the configuration from a file or a dict and prepares it for parsing.
- Parameters:
- Return type:
- Returns:
A dict ready to be parsed by from_config
Remarks:
- register_listener(event_type, listener)
Registers a listener for the given event_type.