-
Notifications
You must be signed in to change notification settings - Fork 15
/
common.py
120 lines (99 loc) · 2.95 KB
/
common.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
from __future__ import annotations
from collections import namedtuple
from enum import Enum
from typing import TYPE_CHECKING, Any
from attr import define, field
if TYPE_CHECKING:
from negmas.mechanisms import Mechanism
from negmas.outcomes import Issue
from .agent import Agent
__all__ = [
"PROTOCOL_CLASS_NAME_FIELD",
"EDGE_TYPES",
"DEFAULT_EDGE_TYPES",
"EDGE_COLORS",
"RunningNegotiationInfo",
"NegotiationRequestInfo",
"RenegotiationRequest",
"NegotiationInfo",
"Operations",
]
PROTOCOL_CLASS_NAME_FIELD = "__mechanism_class_name"
EDGE_TYPES = [
"negotiation-requests-rejected",
"negotiation-requests-accepted",
"negotiations-rejected",
"negotiations-started",
"negotiations-failed",
"negotiations-succeeded",
"contracts-concluded",
"contracts-cancelled",
"contracts-signed",
"contracts-nullified",
"contracts-erred",
"contracts-breached",
"contracts-executed",
]
"""All types of graphs that can be drawn for a world"""
DEFAULT_EDGE_TYPES = [
"negotiation-requests-rejected",
"negotiation-requests-accepted",
"negotiations-rejected",
"negotiations-started",
"negotiations-failed",
"contracts-concluded",
"contracts-cancelled",
"contracts-signed",
"contracts-breached",
"contracts-executed",
]
"""Default set of edge types to show by defaults in draw"""
EDGE_COLORS = {
"negotiation-requests-rejected": "silver",
"negotiation-requests-accepted": "gray",
"negotiations-rejected": "tab:pink",
"negotiations-started": "tab:blue",
"negotiations-failed": "tab:red",
"negotiations-succeeded": "tab:green",
"contracts-concluded": "tab:green",
"contracts-cancelled": "fuchsia",
"contracts-nullified": "yellow",
"contracts-erred": "darksalmon",
"contracts-signed": "blue",
"contracts-breached": "indigo",
"contracts-executed": "black",
}
RunningNegotiationInfo = namedtuple(
"RunningNegotiationInfo",
["negotiator", "annotation", "uuid", "extra", "my_request"],
)
"""Keeps track of running negotiations for an agent"""
NegotiationRequestInfo = namedtuple(
"NegotiationRequestInfo",
["partners", "issues", "annotation", "uuid", "negotiator", "requested", "extra"],
)
"""Keeps track to negotiation requests that an agent sent"""
@define(frozen=True)
class RenegotiationRequest:
"""A request for renegotiation."""
publisher: Agent
issues: list[Issue]
annotation: dict[str, Any] = field(factory=dict)
@define(frozen=True)
class NegotiationInfo:
"""Saves information about a negotiation"""
mechanism: Mechanism | None
partners: list[Agent]
annotation: dict[str, Any]
issues: list[Issue]
requested_at: int
rejectors: list[Agent] | None = None
caller: Agent | None = None
group: str | None = None
class Operations(Enum):
Negotiations = 1
ContractSigning = 2
AgentSteps = 3
ContractExecution = 4
SimulationStep = 5
StatsUpdate = 6