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

data

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:

bool

Attributes Documentation

data

This property is intended for use only by the world manager. No other agent is allowed to use it

Methods Documentation

add_section(name)[source]

Adds a section to the bulletin Board

Parameters:

name (str) – Section name

Return type:

None

Returns:

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:
  • config (str | dict) – Either a file name or a dictionary

  • section (str | None) – A section in the file or a key in the dictionary to use for loading params

  • ignore_children (bool) – If true then children will be ignored and there will be a single return

  • try_parsing_children (bool) – If true the children will first be parsed as ConfigReader classes if they are not

  • int (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 when

  • keys (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

read(section, key)[source]

Reads the value associated with given key

Parameters:
  • section (str) – section name

  • key (str) – key

Return type:

Any

Returns:

Content of that key in the bulletin-board

classmethod read_config(config, section=None)

Reads the configuration from a file or a dict and prepares it for parsing.

Parameters:
  • config (str | dict) – Either a file name or a dictionary

  • section (str | None) – A section in the file or a key in the dictionary to use for loading params

Return type:

dict[str, Any]

Returns:

A dict ready to be parsed by from_config

Remarks:

record(section, value, key=None)[source]

Records data in the given section of the bulletin-board

Parameters:
  • section (str) – section name (can contain subsections separated by ‘/’)

  • key (str | None) – The key

  • value (Any) – The value

Return type:

None

register_listener(event_type, listener)

Registers a listener for the given event_type.

Parameters:
  • event_type (str | None) – The type to register. If None, the listener will be registered for all types

  • listener (EventSink) – The listening agent (must have an on_event method that receives an event: Event and a sender: EventSource)

remove(section, *, query=None, key=None, query_keys=False, value=None)[source]

Removes a value or a set of values from the bulletin Board

Parameters:
  • section (list[str] | str | None) – The section

  • query (Any | None) – the query to use to select what to remove

  • key (str | None) – the key to remove (no need to give a full query)

  • query_keys (bool) – Whether to apply the query (if given) to keys or values

  • value (Any) – Value to be removed

Returns:

Success of failure

Return type:

bool

classmethod satisfies(value, query)[source]
Return type:

bool