Changeset 18 for protocol/src


Ignore:
Timestamp:
06/11/20 16:34:40 (4 years ago)
Author:
bart
Message:

Update to version 1.41

Location:
protocol/src
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • protocol/src/main/java/geniusweb/protocol/session/shaop/BareSHAOPState.java

    r11 r18  
    2222 */
    2323public abstract class BareSHAOPState implements SessionState {
     24
    2425        protected final List<Action> actions;
    2526
     
    167168        }
    168169
     170        @Override
     171        public int hashCode() {
     172                final int prime = 31;
     173                int result = 1;
     174                result = prime * result + ((actions == null) ? 0 : actions.hashCode());
     175                result = prime * result + ((error == null) ? 0 : error.hashCode());
     176                result = prime * result
     177                                + ((partyNumbers == null) ? 0 : partyNumbers.hashCode());
     178                result = prime * result
     179                                + ((progress == null) ? 0 : progress.hashCode());
     180                result = prime * result
     181                                + ((settings == null) ? 0 : settings.hashCode());
     182                result = prime * result + teamNr;
     183                result = prime * result
     184                                + ((totalSpent == null) ? 0 : totalSpent.hashCode());
     185                return result;
     186        }
     187
     188        @Override
     189        public boolean equals(Object obj) {
     190                if (this == obj)
     191                        return true;
     192                if (obj == null)
     193                        return false;
     194                if (getClass() != obj.getClass())
     195                        return false;
     196                BareSHAOPState other = (BareSHAOPState) obj;
     197                if (actions == null) {
     198                        if (other.actions != null)
     199                                return false;
     200                } else if (!actions.equals(other.actions))
     201                        return false;
     202                if (error == null) {
     203                        if (other.error != null)
     204                                return false;
     205                } else if (!error.equals(other.error))
     206                        return false;
     207                if (partyNumbers == null) {
     208                        if (other.partyNumbers != null)
     209                                return false;
     210                } else if (!partyNumbers.equals(other.partyNumbers))
     211                        return false;
     212                if (progress == null) {
     213                        if (other.progress != null)
     214                                return false;
     215                } else if (!progress.equals(other.progress))
     216                        return false;
     217                if (settings == null) {
     218                        if (other.settings != null)
     219                                return false;
     220                } else if (!settings.equals(other.settings))
     221                        return false;
     222                if (teamNr != other.teamNr)
     223                        return false;
     224                if (totalSpent == null) {
     225                        if (other.totalSpent != null)
     226                                return false;
     227                } else if (!totalSpent.equals(other.totalSpent))
     228                        return false;
     229                return true;
     230        }
     231
    169232}
  • protocol/src/main/java/geniusweb/protocol/session/shaop/SHAOP.java

    r11 r18  
    5050 * party of this type can execute a RequestComparison(userid) action, which
    5151 * increases the total bother with the elicitationcost. The call results in the
    52  * associated COB party to execute a Comparison action.
     52 * associated COB party to execute a Comparison action. If this parameter is not
     53 * set, the {@link SHAOPState#DEFAULT_ELICITATATION_COST} is used.
    5354 * <p>
    5455 * A SHAOP party keeps the turn until it does an action that is not a
     
    5859 * <p>
    5960 * The Comparison/ComparisonTest actions are private between the
    60  * {@link ShaopTeam}. A SHAOP party can do a {@link ElicitComparison} action
    61  * at any time. These actions are completely transparent to the other parties
    62  * and are not dependent or influencing the normal turn taking.
     61 * {@link ShaopTeam}. A SHAOP party can do a {@link ElicitComparison} action at
     62 * any time. These actions are completely transparent to the other parties and
     63 * are not dependent or influencing the normal turn taking.
    6364 */
    6465public class SHAOP extends DefaultListenable<ProtocolEvent>
     
    162163                        ProtocolToPartyConnFactory connectionfactory)
    163164                        throws InterruptedException, IOException {
    164                 List<PartyWithProfile> participants = state.getSettings()
    165                                 .getTeams().stream().map(team -> team.getAllParties())
     165                List<PartyWithProfile> participants = state.getSettings().getTeams()
     166                                .stream().map(team -> team.getAllParties())
    166167                                .flatMap(List::stream).collect(Collectors.toList());
    167168                List<Reference> parties = participants.stream()
  • protocol/src/main/java/geniusweb/protocol/session/shaop/SHAOPState.java

    r11 r18  
    3030public class SHAOPState extends BareSHAOPState {
    3131
    32         private static final double DEFAULT_ELICITATATION_COST = 0.1d;
     32        public static final double DEFAULT_ELICITATATION_COST = 0.01d;
    3333
    3434        /**
     
    277277                        // shaop party does real action, move to next SHAOP party.
    278278                        newTeam = (teamNr + 1) % settings.getTeams().size();
    279                         if (newprogress instanceof ProgressRounds) {
     279                        // check if we completed a round
     280                        if (newprogress instanceof ProgressRounds && newTeam == 0) {
    280281                                newprogress = ((ProgressRounds) newprogress).advance();
     282                                System.out.println("Progressed rounds " + newprogress
     283                                                + " after action " + action + "");
    281284                        }
    282285                }
  • protocol/src/main/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsSettings.java

    r16 r18  
    11package geniusweb.protocol.tournament.allpermutations;
    22
     3import java.math.BigInteger;
    34import java.util.Collections;
    45import java.util.List;
     6import java.util.function.BiFunction;
    57
    68import com.fasterxml.jackson.annotation.JsonCreator;
     
    1719import geniusweb.references.PartyWithProfile;
    1820import tudelft.utilities.immutablelist.FixedList;
    19 import tudelft.utilities.immutablelist.Function2;
    2021import tudelft.utilities.immutablelist.ImmutableList;
    2122import tudelft.utilities.immutablelist.MapList;
     
    2526import tudelft.utilities.immutablelist.PermutationsWithReturn;
    2627import tudelft.utilities.immutablelist.PermutationsWithoutReturn;
     28import tudelft.utilities.immutablelist.Repeat;
    2729import tudelft.utilities.immutablelist.Tuple;
    2830import tudelft.utilities.immutablelist.Tuples;
     
    5658public class AllPermutationsSettings implements TournamentSettings {
    5759
    58         public static final String COB_PARTY = "comparebids-1.2.0";
    5960        private final List<Team> teams;
    6061        private final List<ProfileList> profileslists;
     
    6263        private final int teamsPerSession;
    6364        private final SessionSettings sessionsettings;
     65        private final int numberTournaments;
    6466
    6567        /**
    6668         *
    67          * @param teams           a list of {@link Team}s. Must contain at least
    68          *                        {@link #teamsPerSession} elements. The <teamsize>
    69          *                        must match the protocol: (SAOP:1, SHAOP:2)
    70          * @param reuseTeams      if true, we use PermutationsWithReturn, if false
    71          *                        we use PermutationsWithoutReturn to create the
    72          *                        teams.
    73          * @param plists          list of available {@link ProfileList}s to be
    74          *                        permutated over the teams. Each
    75          *                        {@link ProfileList} must contain <teamsize>
    76          *                        elements.
    77          * @param teamsPerSession number of parties per session, must be at least 2.
    78          * @param sesettings      The generic {@link SessionSetting}.
    79          *                        {@link SessionSettings#with(PartyWithProfile)}
    80          *                        will be used to add the required
    81          *                        {@link PartyWithProfile}s
     69         * @param teams             a list of {@link Team}s. Must contain at least
     70         *                          {@link #teamsPerSession} elements. The
     71         *                          <teamsize> must match the protocol: (SAOP:1,
     72         *                          SHAOP:2)
     73         * @param reuseTeams        if true, we use PermutationsWithReturn, if false
     74         *                          we use PermutationsWithoutReturn to create the
     75         *                          teams.
     76         * @param plists            list of available {@link ProfileList}s to be
     77         *                          permutated over the teams. Each
     78         *                          {@link ProfileList} must contain <teamsize>
     79         *                          elements.
     80         * @param teamsPerSession   number of parties per session, must be at least
     81         *                          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
     86         * @param numberTournaments the number of times the tournament should be
     87         *                          run.
    8288         */
    8389        @JsonCreator
     
    8692                        @JsonProperty("reuseTeams") boolean reuseTeams,
    8793                        @JsonProperty("teamsPerSession") int teamsPerSession,
    88                         @JsonProperty("sessionsettings") SessionSettings sesettings) {
     94                        @JsonProperty("sessionsettings") SessionSettings sesettings,
     95                        @JsonProperty("numberTournaments") int nTournaments) {
    8996                if (teamsPerSession < 2)
    9097                        throw new IllegalArgumentException("teamsPerSession must be >=2");
     
    96103                                        "profileslist must contain at least " + teamsPerSession
    97104                                                        + " ProfileList's");
     105                if (nTournaments <= 0)
     106                        throw new IllegalArgumentException("nTournaments must be >0");
    98107                int teamsize;
    99108                if (sesettings instanceof SAOPSettings)
     
    117126                                                                + teamsize + " but found "
    118127                                                                + profile.getProfiles().size());
    119 
    120128                        }
    121129                }
     
    125133                this.profileslists = plists;
    126134                this.sessionsettings = sesettings;
     135                this.numberTournaments = nTournaments;
    127136        }
    128137
     
    159168                return "AllPermutationsSettings[" + teams + "," + reuseTeams + ","
    160169                                + profileslists + "," + teamsPerSession + "," + sessionsettings
    161                                 + "]";
     170                                + "," + numberTournaments + "]";
    162171        }
    163172
     
    166175                final int prime = 31;
    167176                int result = 1;
    168                 result = prime * result + ((teams == null) ? 0 : teams.hashCode());
    169                 result = prime * result + teamsPerSession;
     177                result = prime * result + numberTournaments;
    170178                result = prime * result
    171179                                + ((profileslists == null) ? 0 : profileslists.hashCode());
     
    173181                result = prime * result
    174182                                + ((sessionsettings == null) ? 0 : sessionsettings.hashCode());
     183                result = prime * result + ((teams == null) ? 0 : teams.hashCode());
     184                result = prime * result + teamsPerSession;
    175185                return result;
    176186        }
     
    185195                        return false;
    186196                AllPermutationsSettings other = (AllPermutationsSettings) obj;
     197                if (numberTournaments != other.numberTournaments)
     198                        return false;
     199                if (profileslists == null) {
     200                        if (other.profileslists != null)
     201                                return false;
     202                } else if (!profileslists.equals(other.profileslists))
     203                        return false;
     204                if (reuseTeams != other.reuseTeams)
     205                        return false;
     206                if (sessionsettings == null) {
     207                        if (other.sessionsettings != null)
     208                                return false;
     209                } else if (!sessionsettings.equals(other.sessionsettings))
     210                        return false;
    187211                if (teams == null) {
    188212                        if (other.teams != null)
     
    191215                        return false;
    192216                if (teamsPerSession != other.teamsPerSession)
    193                         return false;
    194                 if (profileslists == null) {
    195                         if (other.profileslists != null)
    196                                 return false;
    197                 } else if (!profileslists.equals(other.profileslists))
    198                         return false;
    199                 if (reuseTeams != other.reuseTeams)
    200                         return false;
    201                 if (sessionsettings == null) {
    202                         if (other.sessionsettings != null)
    203                                 return false;
    204                 } else if (!sessionsettings.equals(other.sessionsettings))
    205217                        return false;
    206218                return true;
     
    251263                                partiesPermutations, profilesPermutations);
    252264
    253                 return new MapList<Tuple<ImmutableList<Team>, ImmutableList<ProfileList>>, ImmutableList<TeamOfPartiesAndProfiles>>(
     265                MapList<Tuple<ImmutableList<Team>, ImmutableList<ProfileList>>, ImmutableList<TeamOfPartiesAndProfiles>> tournamentsettings = new MapList<Tuple<ImmutableList<Team>, ImmutableList<ProfileList>>, ImmutableList<TeamOfPartiesAndProfiles>>(
    254266                                tuple -> teamlist(tuple), tuples);
     267                return new Repeat<ImmutableList<TeamOfPartiesAndProfiles>>(
     268                                tournamentsettings, BigInteger.valueOf(numberTournaments),
     269                                true);
    255270        }
    256271
     
    264279        private ImmutableList<TeamOfPartiesAndProfiles> teamlist(
    265280                        Tuple<ImmutableList<Team>, ImmutableList<ProfileList>> tuple) {
    266                 Function2<Team, ProfileList, TeamOfPartiesAndProfiles> makeparty = new Function2<Team, ProfileList, TeamOfPartiesAndProfiles>() {
     281                BiFunction<Team, ProfileList, TeamOfPartiesAndProfiles> makeparty = new BiFunction<Team, ProfileList, TeamOfPartiesAndProfiles>() {
    267282                        @Override
    268283                        public TeamOfPartiesAndProfiles apply(Team team,
     
    288303        }
    289304
    290 //      /**
    291 //       * Extract the raw URL, without the part after the question mark
    292 //       *
    293 //       * @param party   a party reference (for another party)
    294 //       * @param profile a profile that may have a filter like "?partial=XX"
    295 //       * @return profile without the filter and with a cob party on the same
    296 //       *         machine. IT IS ASSUMED that there will the default
    297 //       *         "comparebids-1.0.0" party on the same machine as where the other
    298 //       *         party is
    299 //       */
    300 //      protected static PartyWithProfile makeCob(PartyRef party,
    301 //                      ProfileRef profile) {
    302 //              try {
    303 //                      URI profileuri = profile.getURI();
    304 //                      URI partyuri = party.getURI();
    305 //                      ProfileRef cobprof = new ProfileRef(profileuri.getScheme() + "://"
    306 //                                      + profileuri.getAuthority() + profileuri.getPath());
    307 //                      String partypath = partyuri.getPath();
    308 //                      partypath = partypath.substring(0, partypath.lastIndexOf('/'));
    309 //                      PartyWithParameters cobparty = new PartyWithParameters(new PartyRef(
    310 //                                      partyuri.getScheme() + "://" + partyuri.getAuthority()
    311 //                                                      + partypath + "/" + COB_PARTY),
    312 //                                      new Parameters());
    313 //                      return new PartyWithProfile(cobparty, cobprof);
    314 //
    315 //              } catch (URISyntaxException e) {
    316 //                      throw new IllegalArgumentException(
    317 //                                      "Failed making cob party with profile " + profile, e);
    318 //              }
    319 //      }
    320 
    321305}
  • protocol/src/test/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsSettingsTest.java

    r14 r18  
    3232        private final ObjectMapper jackson = new ObjectMapper();
    3333
    34         private final String serialized = "{\"AllPermutationsSettings\":{\"teams\":[{\"Team\":[{\"partyref\":\"party1\",\"parameters\":{}}]},{\"Team\":[{\"partyref\":\"party2\",\"parameters\":{}}]}],\"profileslists\":[{\"ProfileList\":[\"profile1\"]},{\"ProfileList\":[\"profile2\"]},{\"ProfileList\":[\"profile3\"]}],\"reuseTeams\":false,\"teamsPerSession\":2,\"sessionsettings\":{\"SAOPSettings\":{\"participants\":[],\"deadline\":{\"deadlinetime\":{\"durationms\":10000}}}}}}";
     34        private final String serialized = "{\"AllPermutationsSettings\":{\"teams\":[{\"Team\":[{\"partyref\":\"party1\",\"parameters\":{}}]},{\"Team\":[{\"partyref\":\"party2\",\"parameters\":{}}]}],\"profileslists\":[{\"ProfileList\":[\"profile1\"]},{\"ProfileList\":[\"profile2\"]},{\"ProfileList\":[\"profile3\"]}],\"reuseTeams\":false,\"teamsPerSession\":2,\"sessionsettings\":{\"SAOPSettings\":{\"participants\":[],\"deadline\":{\"deadlinetime\":{\"durationms\":10000}}}},\"numberTournaments\":1}}";
    3535        private AllPermutationsSettings settings, settings1a, settings2, settings3,
    36                         settings4;
     36                        settings4, settings5;
    3737
    3838        // use directly because there is some hard coding currently.
     
    7676
    7777                settings = new AllPermutationsSettings(parties, profiles, false, 2,
    78                                 saopsettings);
     78                                saopsettings, 1);
    7979
    8080                settings1a = new AllPermutationsSettings(parties, profiles, false, 2,
    81                                 saopsettings);
     81                                saopsettings, 1);
    8282
    8383                settings2 = new AllPermutationsSettings(Arrays.asList(partywithparams1,
    8484                                partywithparams2, partywithparams3), profiles, false, 2,
    85                                 saopsettings);
     85                                saopsettings, 1);
    8686
    8787                settings3 = new AllPermutationsSettings(parties, profiles, true, 2,
    88                                 saopsettings);
     88                                saopsettings, 1);
    8989
    9090                settings4 = new AllPermutationsSettings(parties,
    9191                                Arrays.asList(profiles1, profiles2, profiles3, profiles1),
    92                                 false, 2, saopsettings);
     92                                false, 2, saopsettings, 1);
     93
     94                settings5 = new AllPermutationsSettings(parties, profiles, false, 2,
     95                                saopsettings, 2);
    9396
    9497        }
     
    98101                return Arrays.asList(Arrays.asList(settings, settings1a),
    99102                                Arrays.asList(settings2), Arrays.asList(settings3),
    100                                 Arrays.asList(settings4));
     103                                Arrays.asList(settings4), Arrays.asList(settings5));
    101104        }
    102105
     
    104107        public List<String> getGeneralTestStrings() {
    105108                return Arrays.asList(
    106                                 "AllPermutationsSettings.*party1.*party2.*,false,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*",
    107                                 "AllPermutationsSettings.*party1.*party2.*party3.*,false,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*",
    108                                 "AllPermutationsSettings.*party1.*party2.*,true,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*",
    109                                 "AllPermutationsSettings.*party1.*party2.*,false,.*profile1.*profile2.*profile3.*profile1.*,2,SAOPSettings.*");
     109                                "AllPermutationsSettings.*party1.*party2.*,false,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*1.*",
     110                                "AllPermutationsSettings.*party1.*party2.*party3.*,false,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*1.*",
     111                                "AllPermutationsSettings.*party1.*party2.*,true,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*1.*",
     112                                "AllPermutationsSettings.*party1.*party2.*,false,.*profile1.*profile2.*profile3.*profile1.*,2,SAOPSettings.*1.*",
     113                                "AllPermutationsSettings.*party1.*party2.*,false,.*profile1.*profile2.*profile3.*,2,SAOPSettings.*2.*");
    110114        }
    111115
     
    137141                new AllPermutationsSettings(null,
    138142                                Arrays.asList(profiles1, profiles2, profiles3, profiles1), true,
    139                                 2, saopsettings);
     143                                2, saopsettings, 1);
    140144
    141145        }
     
    145149                new AllPermutationsSettings(Collections.emptyList(),
    146150                                Arrays.asList(profiles1, profiles2, profiles3, profiles1), true,
    147                                 2, saopsettings);
     151                                2, saopsettings, 1);
    148152
    149153        }
     
    151155        @Test(expected = IllegalArgumentException.class)
    152156        public void testNullProfiles() {
    153                 new AllPermutationsSettings(parties, null, true, 2, saopsettings);
     157                new AllPermutationsSettings(parties, null, true, 2, saopsettings, 1);
    154158
    155159        }
     
    159163                new AllPermutationsSettings(parties,
    160164                                Arrays.asList(profiles1, profiles2, profiles3, profiles1), true,
    161                                 4, saopsettings);
     165                                4, saopsettings, 1);
    162166
    163167        }
     
    167171                new AllPermutationsSettings(parties,
    168172                                Arrays.asList(profiles1, profiles2, profiles3, profiles1), true,
    169                                 4, null);
     173                                4, null, 1);
    170174
    171175        }
     
    175179                new AllPermutationsSettings(parties,
    176180                                Arrays.asList(profiles1, profiles2, profiles3, profiles1), true,
    177                                 1, saopsettings);
     181                                1, saopsettings, 1);
    178182
    179183        }
Note: See TracChangeset for help on using the changeset viewer.