source: geniuswebcore/geniusweb/inform/Agreements.py@ 88

Last change on this file since 88 was 88, checked in by Bart Vastenhouw, 2 years ago

Added python SimpleRunner GUI

File size: 1.7 KB
Line 
1from __future__ import annotations
2
3from typing import Any, Dict
4
5from pyson.JsonValue import JsonValue
6
7from geniusweb.actions.PartyId import PartyId
8from geniusweb.issuevalue.Bid import Bid
9from geniusweb.utils import toStr
10
11
12class Agreements:
13 '''
14 There can be multiple agreements from a single negotiation. This object
15 contains the agreements. Each party can agree only on 1 bid and there are
16 always at least 2 parties agreeing on a bid.
17 '''
18 def __init__(self, agreements:Dict[PartyId, Bid] = {} ) :
19 '''
20 @param agrees a map, with the bid that was agreed on by a party
21 HACK Must be Dict[PartyId, Bid]
22 '''
23 if type(agreements)!=dict:
24 raise ValueError("Agreements must be a dict")
25 self._agreements = agreements
26
27 @JsonValue()
28 def getAgreements(self)->Dict[PartyId, Bid]:
29 return self._agreements
30
31 def With(self, other:"Agreements" ) ->"Agreements" :
32 '''
33 * @param other {@link Agreements}
34 * @return a new Agreement containing this plus other agreements
35 * @throws IllegalArgumentException if parties in other are already in this
36 * agreement.
37 '''
38 newagrees = self._agreements.copy()
39 for pid in other._agreements.keys():
40 if pid in newagrees:
41 raise ValueError("party " + str(pid) + " already has agreement");
42 newagrees[pid]=other._agreements[pid]
43 return Agreements(newagrees);
44
45 def getMap(self)-> Dict[PartyId,Bid]:
46 '''
47 @return actual agreemenets contained here
48 '''
49 return self._agreements.copy()
50
51
52 def __repr__(self):
53 return "Agreements" + toStr(self._agreements)
54
55 def __eq__(self, other):
56 return isinstance(other, self.__class__) and self._agreements == other._agreements
57
58
59 def __hash__(self):
60 return sum([ hash(k) + 31 * hash(v) for (k,v) in self._agreements.items()])
Note: See TracBrowser for help on using the repository browser.