Changeset 14 for protocol/src/main/java
- Timestamp:
- 04/28/20 12:56:46 (5 years ago)
- Location:
- protocol/src/main/java/geniusweb/protocol/tournament
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
protocol/src/main/java/geniusweb/protocol/tournament/TournamentState.java
r1 r14 7 7 8 8 /** 9 * The current state of the tournament. Must be serializabl;e so that it can be 10 * restarted if a crash occurs. 9 * The current state of the tournament. Must be implement Json serialization so 10 * that it can be used to log the state. State must contain all information to 11 * determine the relevant info of the negotiation. It may also be used to 12 * restart the nego if a crash occurs. 11 13 */ 12 14 @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE) -
protocol/src/main/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsSettings.java
r11 r14 1 1 package geniusweb.protocol.tournament.allpermutations; 2 2 3 import java.net.URI;4 import java.net.URISyntaxException;5 3 import java.util.Collections; 6 4 import java.util.List; … … 9 7 import com.fasterxml.jackson.annotation.JsonProperty; 10 8 11 import geniusweb.profile.Profile;12 9 import geniusweb.protocol.session.SessionSettings; 13 10 import geniusweb.protocol.session.TeamOfPartiesAndProfiles; … … 18 15 import geniusweb.protocol.tournament.TournamentProtocol; 19 16 import geniusweb.protocol.tournament.TournamentSettings; 20 import geniusweb.references.Parameters;21 import geniusweb.references.PartyRef;22 import geniusweb.references.PartyWithParameters;23 17 import geniusweb.references.PartyWithProfile; 24 import geniusweb.references.ProfileRef;25 18 import tudelft.utilities.immutablelist.FixedList; 26 19 import tudelft.utilities.immutablelist.Function2; … … 68 61 69 62 public static final String COB_PARTY = "comparebids-1.2.0"; 70 private final List< PartyWithParameters> parties;71 private final List<Profile Ref> profiles;72 private final boolean reuse Parties;73 private final int partiesPerSession;63 private final List<Team> teams; 64 private final List<ProfileList> profileslists; 65 private final boolean reuseTeams; 66 private final int teamsPerSession; 74 67 private final SessionSettings sessionsettings; 75 68 76 69 /** 77 70 * 78 * @param parties a list of {@link PartyRef}s. Must contain at 79 * least <partiesPerSession> elements. 80 * @param reuseParties if true, we use PermutationsWithReturn, if false 81 * we use PermutationsWithoutReturn to create the 82 * parties. 83 * @param profiles list of available {@link Profile}s to be 84 * permutated over the parties 85 * @param partiesPerSession number of parties per session, must be at least 86 * 2. 87 * @param sesettings The generic {@link SessionSetting}. 88 * {@link SessionSettings#with(PartyWithProfile)} 89 * will be used to add the required 90 * {@link PartyWithProfile}s 71 * @param teams a list of {@link Team}s. Must contain at least 72 * <partiesPerSession> elements. The <teamsize> must 73 * match the protocol: (SAOP:1, SHAOP:2) 74 * @param reuseTeams if true, we use PermutationsWithReturn, if false 75 * we use PermutationsWithoutReturn to create the 76 * teams. 77 * @param plists list of available {@link ProfileList}s to be 78 * permutated over the teams. Each 79 * {@link ProfileList} must contain <teamsize> 80 * elements. 81 * @param teamsPerSession number of parties per session, must be at least 2. 82 * @param sesettings The generic {@link SessionSetting}. 83 * {@link SessionSettings#with(PartyWithProfile)} 84 * will be used to add the required 85 * {@link PartyWithProfile}s 91 86 */ 92 87 @JsonCreator 93 public AllPermutationsSettings( 94 @JsonProperty("parties") List<PartyWithParameters> parties, 95 @JsonProperty("reuseParties") boolean reuseParties, 96 @JsonProperty("profiles") List<ProfileRef> profiles, 97 @JsonProperty("partiesPerSession") int partiesPerSession, 88 public AllPermutationsSettings(@JsonProperty("teams") List<Team> teams, 89 @JsonProperty("profileslists") List<ProfileList> plists, 90 @JsonProperty("reuseTeams") boolean reuseTeams, 91 @JsonProperty("teamsPerSession") int teamsPerSession, 98 92 @JsonProperty("sessionsettings") SessionSettings sesettings) { 99 if (partiesPerSession < 2) 100 throw new IllegalArgumentException("partiesPerSession must be >=2"); 101 if (parties == null || parties.size() < partiesPerSession) 102 throw new IllegalArgumentException("parties must contain at least " 103 + partiesPerSession + " PartyRefs"); 104 if (profiles == null || profiles.size() < 2) 105 throw new IllegalArgumentException("profiles must contain at least " 106 + partiesPerSession + " ProfileRefs"); 107 this.partiesPerSession = partiesPerSession; 108 this.reuseParties = reuseParties; 109 this.parties = parties; 110 this.profiles = profiles; 93 if (teamsPerSession < 2) 94 throw new IllegalArgumentException("teamsPerSession must be >=2"); 95 if (teams == null || teams.size() < teamsPerSession) 96 throw new IllegalArgumentException("teams must contain at least " 97 + teamsPerSession + " teams"); 98 if (plists == null || plists.size() < 2) 99 throw new IllegalArgumentException( 100 "profileslist must contain at least " + teamsPerSession 101 + " ProfileList's"); 102 int teamsize; 103 if (sesettings instanceof SAOPSettings) 104 teamsize = 1; 105 else if (sesettings instanceof SHAOPSettings) 106 teamsize = 2; 107 else 108 throw new IllegalArgumentException( 109 "Unsupported protocol " + sesettings.getClass()); 110 111 for (Team team : teams) { 112 if (team.getParties().size() != teamsize) { 113 throw new IllegalArgumentException("All teams should have size " 114 + teamsize + " but found " + team.getParties().size()); 115 } 116 } 117 for (ProfileList profile : plists) { 118 if (profile.getProfiles().size() != teamsize) { 119 throw new IllegalArgumentException( 120 "All profiles should have size equal to the team size " 121 + teamsize + " but found " 122 + profile.getProfiles().size()); 123 124 } 125 } 126 this.teamsPerSession = teamsPerSession; 127 this.reuseTeams = reuseTeams; 128 this.teams = teams; 129 this.profileslists = plists; 111 130 this.sessionsettings = sesettings; 112 131 } … … 131 150 public ImmutableList<SessionSettings> permutations() { 132 151 ImmutableList<ImmutableList<TeamOfPartiesAndProfiles>> partylistlist; 133 ImmutableList<PartyWithParameters> partieslist = new FixedList<PartyWithParameters>( 134 parties); 135 ImmutableList<ProfileRef> profileslist = new FixedList<ProfileRef>( 136 profiles); 152 ImmutableList<Team> partieslist = new FixedList<Team>(teams); 153 ImmutableList<ProfileList> profileslist = new FixedList<ProfileList>( 154 profileslists); 137 155 partylistlist = getParticipants(partieslist, profileslist, 138 partiesPerSession, reuseParties);156 teamsPerSession, reuseTeams); 139 157 return new MapList<>(partyproflist -> createSetting(partyproflist), 140 158 partylistlist); … … 143 161 @Override 144 162 public String toString() { 145 return "AllPermutationsSettings[" + parties + "," + reuseParties + ","146 + profiles + "," + partiesPerSession + "," + sessionsettings163 return "AllPermutationsSettings[" + teams + "," + reuseTeams + "," 164 + profileslists + "," + teamsPerSession + "," + sessionsettings 147 165 + "]"; 148 166 } … … 152 170 final int prime = 31; 153 171 int result = 1; 154 result = prime * result + (( parties == null) ? 0 : parties.hashCode());155 result = prime * result + partiesPerSession;172 result = prime * result + ((teams == null) ? 0 : teams.hashCode()); 173 result = prime * result + teamsPerSession; 156 174 result = prime * result 157 + ((profiles == null) ? 0 : profiles.hashCode());158 result = prime * result + (reuse Parties ? 1231 : 1237);175 + ((profileslists == null) ? 0 : profileslists.hashCode()); 176 result = prime * result + (reuseTeams ? 1231 : 1237); 159 177 result = prime * result 160 178 + ((sessionsettings == null) ? 0 : sessionsettings.hashCode()); … … 171 189 return false; 172 190 AllPermutationsSettings other = (AllPermutationsSettings) obj; 173 if ( parties == null) {174 if (other. parties != null)191 if (teams == null) { 192 if (other.teams != null) 175 193 return false; 176 } else if (! parties.equals(other.parties))177 return false; 178 if ( partiesPerSession != other.partiesPerSession)179 return false; 180 if (profiles == null) {181 if (other.profiles != null)194 } else if (!teams.equals(other.teams)) 195 return false; 196 if (teamsPerSession != other.teamsPerSession) 197 return false; 198 if (profileslists == null) { 199 if (other.profileslists != null) 182 200 return false; 183 } else if (!profiles .equals(other.profiles))184 return false; 185 if (reuse Parties != other.reuseParties)201 } else if (!profileslists.equals(other.profileslists)) 202 return false; 203 if (reuseTeams != other.reuseTeams) 186 204 return false; 187 205 if (sessionsettings == null) { … … 219 237 */ 220 238 private ImmutableList<ImmutableList<TeamOfPartiesAndProfiles>> getParticipants( 221 ImmutableList<PartyWithParameters> parties, 222 ImmutableList<ProfileRef> profiles, int n, 223 boolean drawPartyWithPutback) { 224 225 Permutations<PartyWithParameters> partiesPermutations; 239 ImmutableList<Team> parties, ImmutableList<ProfileList> profiles, 240 int n, boolean drawPartyWithPutback) { 241 242 Permutations<Team> partiesPermutations; 226 243 if (drawPartyWithPutback) { 227 244 partiesPermutations = new PermutationsWithReturn<>(parties, n); … … 230 247 } 231 248 232 Permutations<Profile Ref> profilesPermutations = new PermutationsOrderedWithoutReturn<>(249 Permutations<ProfileList> profilesPermutations = new PermutationsOrderedWithoutReturn<>( 233 250 profiles, n); 234 251 235 // each tuple contains ses ion info: a list of partyrefand a list of236 // profileref's.237 Tuples<ImmutableList< PartyWithParameters>, ImmutableList<ProfileRef>> tuples = new Tuples<>(252 // each tuple contains session info: a list of Team and a list of 253 // ProfileList. 254 Tuples<ImmutableList<Team>, ImmutableList<ProfileList>> tuples = new Tuples<>( 238 255 partiesPermutations, profilesPermutations); 239 256 240 return new MapList<Tuple<ImmutableList< PartyWithParameters>, ImmutableList<ProfileRef>>, ImmutableList<TeamOfPartiesAndProfiles>>(257 return new MapList<Tuple<ImmutableList<Team>, ImmutableList<ProfileList>>, ImmutableList<TeamOfPartiesAndProfiles>>( 241 258 tuple -> teamlist(tuple), tuples); 242 259 } … … 244 261 /** 245 262 * 246 * @param tuple a tuple with (1) ImmutableList< PartyRef> (2)247 * ImmutableList<Profile Ref>263 * @param tuple a tuple with (1) ImmutableList<Team> (2) 264 * ImmutableList<Profiles> 248 265 * @return list of TeamOfPartiesAndProfiles, each picked from the two lists 249 266 * in order. 250 267 */ 251 268 private ImmutableList<TeamOfPartiesAndProfiles> teamlist( 252 Tuple<ImmutableList<PartyWithParameters>, ImmutableList<ProfileRef>> tuple) { 253 Function2<PartyWithParameters, ProfileRef, TeamOfPartiesAndProfiles> // 254 makeparty = new Function2<PartyWithParameters, ProfileRef, TeamOfPartiesAndProfiles>() { 269 Tuple<ImmutableList<Team>, ImmutableList<ProfileList>> tuple) { 270 Function2<Team, ProfileList, TeamOfPartiesAndProfiles> makeparty = new Function2<Team, ProfileList, TeamOfPartiesAndProfiles>() { 255 271 @Override 256 public TeamOfPartiesAndProfiles apply( PartyWithParameters party,257 Profile Ref profile) {272 public TeamOfPartiesAndProfiles apply(Team team, 273 ProfileList profilelist) { 258 274 if (sessionsettings instanceof SAOPSettings) 259 return new SaopPartyWithProfile(party, profile); 275 return new SaopPartyWithProfile(team.getParties().get(0), 276 profilelist.getProfiles().get(0)); 260 277 else if (sessionsettings instanceof SHAOPSettings) { 261 return new ShaopTeam(new PartyWithProfile(party, profile), 262 makeCob(party.getPartyRef(), profile)); 278 return new ShaopTeam( 279 new PartyWithProfile(team.getParties().get(0), 280 profilelist.getProfiles().get(0)), 281 new PartyWithProfile(team.getParties().get(1), 282 profilelist.getProfiles().get(1))); 263 283 } else 264 284 throw new IllegalArgumentException( … … 268 288 269 289 }; 270 return new MapThreadList<TeamOfPartiesAndProfiles, PartyWithParameters, ProfileRef>(290 return new MapThreadList<TeamOfPartiesAndProfiles, Team, ProfileList>( 271 291 makeparty, tuple.get1(), tuple.get2()); 272 292 } 273 293 274 /**275 * Extract the raw URL, without the part after the question mark276 *277 * @param party a party reference (for another party)278 * @param profile a profile that may have a filter like "?partial=XX"279 * @return profile without the filter and with a cob party on the same280 * machine. IT IS ASSUMED that there will the default281 * "comparebids-1.0.0" party on the same machine as where the other282 * party is283 */284 protected static PartyWithProfile makeCob(PartyRef party,285 ProfileRef profile) {286 try {287 URI profileuri = profile.getURI();288 URI partyuri = party.getURI();289 ProfileRef cobprof = new ProfileRef(profileuri.getScheme() + "://"290 + profileuri.getAuthority() + profileuri.getPath());291 String partypath = partyuri.getPath();292 partypath = partypath.substring(0, partypath.lastIndexOf('/'));293 PartyWithParameters cobparty = new PartyWithParameters(new PartyRef(294 partyuri.getScheme() + "://" + partyuri.getAuthority()295 + partypath + "/" + COB_PARTY),296 new Parameters());297 return new PartyWithProfile(cobparty, cobprof);298 299 } catch (URISyntaxException e) {300 throw new IllegalArgumentException(301 "Failed making cob party with profile " + profile, e);302 }303 }294 // /** 295 // * Extract the raw URL, without the part after the question mark 296 // * 297 // * @param party a party reference (for another party) 298 // * @param profile a profile that may have a filter like "?partial=XX" 299 // * @return profile without the filter and with a cob party on the same 300 // * machine. IT IS ASSUMED that there will the default 301 // * "comparebids-1.0.0" party on the same machine as where the other 302 // * party is 303 // */ 304 // protected static PartyWithProfile makeCob(PartyRef party, 305 // ProfileRef profile) { 306 // try { 307 // URI profileuri = profile.getURI(); 308 // URI partyuri = party.getURI(); 309 // ProfileRef cobprof = new ProfileRef(profileuri.getScheme() + "://" 310 // + profileuri.getAuthority() + profileuri.getPath()); 311 // String partypath = partyuri.getPath(); 312 // partypath = partypath.substring(0, partypath.lastIndexOf('/')); 313 // PartyWithParameters cobparty = new PartyWithParameters(new PartyRef( 314 // partyuri.getScheme() + "://" + partyuri.getAuthority() 315 // + partypath + "/" + COB_PARTY), 316 // new Parameters()); 317 // return new PartyWithProfile(cobparty, cobprof); 318 // 319 // } catch (URISyntaxException e) { 320 // throw new IllegalArgumentException( 321 // "Failed making cob party with profile " + profile, e); 322 // } 323 // } 304 324 305 325 }
Note:
See TracChangeset
for help on using the changeset viewer.