source: protocol/src/main/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsState.java@ 39

Last change on this file since 39 was 39, checked in by bart, 3 years ago

Geniusweb 2.0.3. MOPAC protocol translated to Python. Small fixes.

File size: 2.3 KB
Line 
1package geniusweb.protocol.tournament.allpermutations;
2
3import java.math.BigInteger;
4import java.util.ArrayList;
5import java.util.List;
6
7import geniusweb.protocol.session.SessionResult;
8import geniusweb.protocol.session.SessionSettings;
9import geniusweb.protocol.tournament.TournamentState;
10import tudelft.utilities.immutablelist.ImmutableList;
11
12/**
13 * A non-parallel simple implementation of all-permutations
14 */
15public class AllPermutationsState implements TournamentState {
16
17 protected final AllPermutationsSettings toursettings; // original settings
18 protected final ImmutableList<SessionSettings> sessionsettings;
19 // limited to MAX_INT elements. But we need to store results anyway
20 protected final List<SessionResult> results;
21
22 public AllPermutationsState(AllPermutationsSettings toursettings,
23 ImmutableList<SessionSettings> settings,
24 List<SessionResult> results) {
25 this.toursettings = toursettings;
26 this.sessionsettings = settings;
27 this.results = results;
28 }
29
30 public List<SessionResult> getResults() {
31 return results;
32 }
33
34 @Override
35 public boolean isFinal(long currentTimeMs) {
36 return sessionsettings.size().intValue() == results.size();
37 }
38
39 /**
40 * @return the settings for the next session. Null if no such session.
41 */
42 public SessionSettings getNextSettings() {
43 if (isFinal(0l))
44 return null;
45 return sessionsettings.get(BigInteger.valueOf(results.size()));
46 }
47
48 /**
49 *
50 * @param result the next {@link SessionResult}
51 * @return new state
52 * @throws IllegalArgumentException if the result participants are not
53 * matching the expected participants
54 */
55 public AllPermutationsState with(SessionResult result) {
56 // FIXME do we really need this? Why is this not working?
57 // if (!new HashSet<PartyWithProfile>(getNextSettings().getAllParties())
58 // .equals(result.getParticipants().values())) {
59 // throw new IllegalArgumentException("Inconsistent session result");
60 // }
61 ArrayList<SessionResult> newresults = new ArrayList<>(results);
62 newresults.add(result);
63 return new AllPermutationsState(toursettings, sessionsettings,
64 newresults);
65 }
66
67 /**
68 *
69 * @return number of sessions in this tournament.
70 */
71 public BigInteger getSize() {
72 return sessionsettings.size();
73 }
74
75 @Override
76 public AllPermutationsSettings getSettings() {
77 return toursettings;
78 }
79
80}
Note: See TracBrowser for help on using the repository browser.