source: geniuswebcore/geniusweb/protocol/session/learn/LearnSettings.py@ 88

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

Added python SimpleRunner GUI

File size: 3.9 KB
Line 
1from typing import List
2from uuid import UUID
3
4from tudelft_utilities_logging.Reporter import Reporter
5
6from geniusweb.deadline.Deadline import Deadline
7from geniusweb.protocol.session.SessionProtocol import SessionProtocol
8from geniusweb.protocol.session.SessionSettings import SessionSettings
9from geniusweb.protocol.session.TeamInfo import TeamInfo
10from geniusweb.references.PartyWithProfile import PartyWithProfile
11
12
13class LearnSettings(SessionSettings):
14 '''
15 Settings for learn protocol.
16 '''
17
18 def __init__(self, participants:List[TeamInfo] , deadline:Deadline) :
19 '''
20 @param participants the list of {@link PartyWithProfile} in clockwise
21 order. There must be at least 2 to run the SAOP
22 protocol. But SAOP can be initialized with less, for
23 use in TournamentSettings.
24 <table>
25 <caption>Required parameters</caption>
26 <tr>
27 <td>persistentstate</td>
28 <td>a {@link FileLocation}, serialized as json eg
29 <code>"b29f3bf5-1dc4-499e-a676-7b2dbb864a03"</code> ,
30 where the party's persistant state is stored; this
31 must match the persistantstate used in earlier calls
32 for e.g. {@link SAOPSettings}.</td>
33 </tr>
34
35 <tr>
36 <td>negotiationdata</td>
37 <td>a List of {@link FileLocation}s, serialized as
38 json, matching the negotiationdata used in earlier
39 calls for eg {@link SAOPSettings}.</td>
40 </tr>
41 </table>
42 @param deadline the deadline of the negotiation.
43 '''
44 self._participants = participants
45 self._deadline = deadline
46 if participants == None:
47 raise ValueError("participants must not be null")
48 if deadline == None:
49 raise ValueError("deadline must not be null")
50
51 for pwithp in self.getAllParties():
52 params = pwithp.getParty().getParameters()
53 statestr = params.get("persistentstate")
54 if not isinstance(statestr , str):
55 raise ValueError(
56 "persistentstate parameter containing UUID string is required, but found "\
57 + str(statestr))
58 # check that it contains a UUID. Don't store it, we don't need
59 # it.
60 UUID(statestr)
61
62 # and check the negotiationdata
63 negotiationsstr = params.get("negotiationdata")
64 if not isinstance(negotiationsstr, list):
65 raise ValueError(
66 "negotiationdata parameter containing a List is required")
67
68 for negostr in negotiationsstr:
69 if not isinstance(negostr,str):
70 raise ValueError(
71 "The list in negotiationdata must contain UUID strings but found "\
72 + str(negostr))
73 UUID(negostr)
74
75 def getMaxRunTime(self)->float:
76 return self._deadline.getDuration() / 1000.
77
78 def getProtocol(self, logger:Reporter )->SessionProtocol :
79 from geniusweb.protocol.session.learn.LearnState import LearnState
80 from geniusweb.protocol.session.learn.Learn import Learn
81 return Learn(LearnState([],[],None, self), logger)
82
83 def getTeams(self)->List[TeamInfo] :
84 return list(self._participants)
85
86 def getParticipants(self) -> List[TeamInfo] :
87 return list(self._participants)
88
89 def getDeadline(self)->Deadline :
90 '''
91 @return the deadline for this negotiation
92 '''
93 return self._deadline
94
95 def getAllParties(self)->List[PartyWithProfile] :
96 return [particip.getParties()[0]
97 for particip in self._participants ]
98
99 def getTeamSize(self)->int:
100 return 1
101
102 def __repr__(self):
103 return "LearnSettings" + str(self._participants) +\
104 "," + str(self._deadline) + "]"
105
106 def __hash__(self):
107 return hash((self._deadline, tuple(self._participants)))
108
109
110 def __eq__(self, other) -> bool:
111 return isinstance(other, self.__class__) and \
112 self._participants == other._participants and \
113 self._deadline==other._deadline
114
115 def With(self, team:TeamInfo)->SessionSettings :
116 if team.getSize() != 1:
117 raise ValueError(
118 "Team must be size 1 but found " + str(team))
119 newparts = list(self._participants)
120 newparts.append(team)
121 return LearnSettings(newparts, self._deadline)
Note: See TracBrowser for help on using the repository browser.