source: geniuswebcore/geniusweb/protocol/session/saop/SAOPSettings.py@ 79

Last change on this file since 79 was 73, checked in by Bart Vastenhouw, 3 years ago

Fix for IssueValue hashcode.

File size: 2.4 KB
Line 
1from typing import List
2
3from tudelft_utilities_logging.Reporter import Reporter
4
5from geniusweb.deadline.Deadline import Deadline
6from geniusweb.protocol.session.SessionProtocol import SessionProtocol
7from geniusweb.protocol.session.SessionSettings import SessionSettings
8from geniusweb.protocol.session.TeamInfo import TeamInfo
9
10from geniusweb.references.PartyWithProfile import PartyWithProfile
11
12
13class SAOPSettings(SessionSettings):
14
15 def __init__(self, participants:List[TeamInfo], deadline:Deadline ):
16 '''
17 @param participants the list of {@link PartyWithProfile} in clockwise
18 order. There must be at least 2 to run the SAOP
19 protocol. But SAOP can be initialized with less, for
20 use in TournamentSettings.
21 @param deadline the deadline of the negotiation
22 '''
23 self._participants = participants;
24 self._deadline = deadline;
25 if participants == None:
26 raise ValueError("participants must not be null")
27 if deadline == None:
28 raise ValueError("deadline must not be null")
29
30 def getMaxRunTime(self) -> float:
31 return self._deadline.getDuration() / 1000.
32
33 def getProtocol(self, logger:Reporter ) -> SessionProtocol :
34 # avoid circular imports
35 from geniusweb.protocol.session.saop.SAOP import SAOP
36 from geniusweb.protocol.session.saop.SAOPState import SAOPState
37 return SAOP(SAOPState([],[],None, self), logger)
38
39 def getParticipants(self) -> List[TeamInfo] :
40 return list(self._participants)
41
42 def getTeams(self) -> List[TeamInfo] :
43 return list(self._participants)
44
45 def getDeadline(self)->Deadline :
46 '''
47 @return the deadline for this negotiation
48 '''
49 return self._deadline
50
51 def getAllParties(self) -> List[PartyWithProfile] :
52 return [particip.getParties()[0] for particip in self._participants ]
53
54 def getTeamSize(self) -> int:
55 return 1
56
57 def __repr__(self)->str:
58 return "SAOPSettings" + str(self._participants) + "," + str(self._deadline) + "]"
59
60 def __hash__(self):
61 return hash((self._deadline, tuple(self._participants)))
62
63 def __eq__(self, other):
64 return isinstance(other, self.__class__) \
65 and self._deadline == other._deadline and self._participants==other._participants
66
67 def With(self, team:TeamInfo) -> SessionSettings :
68 if team.getSize() != 1:
69 raise ValueError("Team must be size 1 but found " + str(team));
70 newparts = list(self._participants)
71 newparts.append(team)
72 return SAOPSettings(newparts, self._deadline)
73
Note: See TracBrowser for help on using the repository browser.