negmas.common¶
Common data-structures and classes used by all other modules.
This module does not import anything from the library except during type checking
- negmas.common.AgentMechanismInterface[source]¶
A depricated alias for
NegotiatorMechanismInterface
- negmas.common.DEFAULT_RESERVED_VALUE_PENALTY = 0.0[source]¶
Default penalty applied when correcting non-finite reserved values (None, inf, -inf, NaN). The corrected value is set to
ufun.min() - DEFAULT_RESERVED_VALUE_PENALTY.
- class negmas.common.MechanismState(running: bool = False, waiting: bool = False, started: bool = False, step: int = 0, time: float = 0.0, relative_time: float = 0.0, broken: bool = False, timedout: bool = False, agreement: tuple | None = None, results: tuple | OutcomeSpace | tuple[tuple] | None = None, n_negotiators: int = 0, has_error: bool = False, error_details: str = '', erred_negotiator: str = '', erred_agent: str = '')[source]¶
Bases:
objectEncapsulates the mechanism state at any point
- agreement: tuple | None[source]¶
Agreement at the end of the negotiation (it is always None until an agreement is reached).
- n_negotiators: int[source]¶
Number of agents currently in the negotiation. Notice that this may change over time if the mechanism supports dynamic entry
- relative_time: float[source]¶
A number in the period [0, 1] giving the relative time of the negotiation. Relative time is calculated as
max(step/n_steps, time/time_limit).
- class negmas.common.NegotiatorInfo(name: str, id: str, type: str)[source]¶
Bases:
objectKeeps information about a negotiator. Mostly for use with controllers.
- class negmas.common.NegotiatorMechanismInterface(id: str, n_outcomes: int | float, outcome_space: OutcomeSpace, shared_time_limit: float, shared_n_steps: int | None, private_time_limit: float, private_n_steps: int | None, pend: float, pend_per_second: float, step_time_limit: float, negotiator_time_limit: float, dynamic_entry: bool, max_n_negotiators: int | None, _mechanism: Mechanism, annotation: dict[str, Any] = NOTHING)[source]¶
Bases:
objectAll information of a negotiation visible to negotiators.
The NMI provides negotiators with access to mechanism parameters and state. It supports per-negotiator time and step limits through a three-tier system:
Shared limits (
shared_time_limit,shared_n_steps): Apply to all negotiatorsPrivate limits (
private_time_limit,private_n_steps): Apply to individual negotiatorsEffective limits (
time_limit,n_steps): Computed as min(shared, private)
The effective limits are what negotiators actually see and are used to calculate
relative_time. This design allows different negotiators to have different time/step constraints while maintaining backward compatibility with code that doesn’t use per-negotiator limits.Examples
Standard usage (all negotiators see same limits):
mechanism = SAOMechanism(time_limit=60, n_steps=100) # All negotiators see time_limit=60, n_steps=100
Per-negotiator limits:
mechanism = SAOMechanism(time_limit=60, n_steps=100) mechanism.add(negotiator1, time_limit=30) # Sees time_limit=30 (stricter) mechanism.add( negotiator2, time_limit=90 ) # Sees time_limit=60 (shared is stricter) mechanism.add(negotiator3) # Sees time_limit=60 (no private limit)
- annotation: dict[str, Any][source]¶
An arbitrary annotation as a
dict[str, Any]that is always available for all negotiators
- property atomic_steps: bool[source]¶
Whether steps in this mechanism are atomic (cannot be interrupted).
- property cartesian_outcome_space: CartesianOutcomeSpace[source]¶
Returns the
outcome_spaceas aCartesianOutcomeSpaceor raises aValueErrorif that was not possible.Remarks:
Useful for negotiators that only work with
CartesianOutcomeSpaces (i.e.GeniusNegotiator)
- discrete_outcome_space(levels: int = 5, max_cardinality: int = 10000000000) DiscreteOutcomeSpace[source]¶
Returns a stable discrete version of the given outcome-space
- discrete_outcomes(max_cardinality: int | float = inf) Iterable[tuple][source]¶
A discrete set of outcomes that spans the outcome space
- dynamic_entry: bool[source]¶
Whether it is allowed for negotiators to enter/leave the negotiation after it starts
- property estimated_n_steps: int[source]¶
Return an estimate of the number of steps for this negotiation.
- property estimated_time_limit: float[source]¶
Return an estimate of the number of seconds for this negotiation.
- genius_id(id: str | None) str | None[source]¶
Gets the Genius ID corresponding to the given negotiator if known otherwise its normal ID
- property genius_negotiator_ids: list[str][source]¶
Gets the Java IDs of all negotiators (if the negotiator is not a GeniusNegotiator, its normal ID is returned)
- property history: list[source]¶
The full negotiation history of actions, offers, and responses.
- Returns:
Chronological list of all negotiation events and actions
- Return type:
- property issues: tuple[Issue, ...][source]¶
The negotiation issues defining the outcome space dimensions.
- max_n_negotiators: int | None[source]¶
Maximum allowed number of negotiators in the session. None indicates no limit
- n_steps: int | None[source]¶
The effective allowed number of steps for this negotiator. Computed as min(shared_n_steps, private_n_steps) in __attrs_post_init__
- negotiator_index(source: str) int[source]¶
Returns the negotiator index for the given negotiator. Raises an exception if not found
- negotiator_time_limit: float[source]¶
The time limit in seconds to wait for negotiator responses of this negotiation session. None indicates infinity
- outcome_space: OutcomeSpace[source]¶
Negotiation agenda as as an
OutcomeSpaceobject. The most common type isCartesianOutcomeSpacewhich represents the cartesian product of a list of issues
- property outcomes: Iterable[tuple] | None[source]¶
All outcomes for discrete outcome spaces or None for continuous outcome spaces. See
discrete_outcomes
- property participants: list[NegotiatorInfo][source]¶
Information about all negotiators participating in this negotiation.
- Returns:
List of participant information including IDs and preferences
- Return type:
- pend: float[source]¶
The probability that the negotiation times out at every step. Must be less than one. If <= 0, it is ignored
- pend_per_second: float[source]¶
The probability that the negotiation times out every second. Must be less than one. If <= 0, it is ignored
- private_n_steps: int | None[source]¶
The private allowed number of steps for this negotiator. None indicates infinity. Set via Mechanism.add(n_steps=…)
- private_time_limit: float[source]¶
The private time limit in seconds for this negotiator. inf indicates infinity. Set via Mechanism.add(time_limit=…)
- random_outcomes(n: int = 1) list[tuple][source]¶
A set of random outcomes from the outcome-space of this negotiation
- property requirements: dict[source]¶
The protocol requirements
- Returns:
A dict of str/Any pairs giving the requirements
The shared allowed number of steps for this negotiation. Applies to all negotiators. None indicates infinity
The shared time limit in seconds for this negotiation session. Applies to all negotiators. inf indicates infinity
- property state: MechanismState[source]¶
Access the current state of the mechanism.
Remarks:
Whenever a method receives a
AgentMechanismInterfaceobject, it can always access the current state of the protocol by accessing this property.
- step_time_limit: float[source]¶
The time limit in seconds for each step of this negotiation session. None indicates infinity
- class negmas.common.PreferencesChange(type: PreferencesChangeType = PreferencesChangeType.General, data: Any = None)[source]¶
Bases:
objectPreferencesChange implementation.
- class negmas.common.PreferencesChangeType(*values)[source]¶
Bases:
EnumThe type of change in preferences.
Remarks:
Returned from
changesproperty ofPreferencesto help the owner of the preferences in deciding what to do with the change.Received by the
on_preferences_changedmethod ofRationalentities to inform them about a change in preferences.Note that the
Rationalentity needs to callchangesexplicitly and call its ownon_preferences_changedto handle changes that happen without assignment to negmas.preferences of theRationalentity.If the negmas.preferences of the
Rationalagent are changed through assignment, itson_preferences_changedwill be called with the appropriatePreferencesChangelist.
- class negmas.common.TraceElement(time, relative_time, step, negotiator, offer, responses, state, text, data)[source]¶
Bases:
tupleAn element of the trace returned by
full_tracerepresenting the history of the negotiation
- negmas.common.Value[source]¶
A value in NegMAS can either be crisp ( float ) or probabilistic (
Distribution)alias of
Distribution|float