package geniusweb.protocol.session.learn; import java.util.Collections; import java.util.LinkedList; import java.util.List; import java.util.UUID; import java.util.stream.Collectors; import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonProperty; import geniusweb.actions.FileLocation; import geniusweb.deadline.Deadline; import geniusweb.protocol.session.SessionProtocol; import geniusweb.protocol.session.SessionSettings; import geniusweb.protocol.session.TeamInfo; import geniusweb.protocol.session.saop.SAOPSettings; import geniusweb.references.Parameters; import geniusweb.references.PartyWithProfile; import tudelft.utilities.logging.Reporter; /** * Settings for learn protocol. */ public class LearnSettings implements SessionSettings { private final List participants; private final Deadline deadline; /** * * @param participants the list of {@link PartyWithProfile} in clockwise * order. There must be at least 2 to run the SAOP * protocol. But SAOP can be initialized with less, for * use in TournamentSettings. * * * * * * * * * * * *
Required parameters
persistentstatea {@link FileLocation}, serialized as json eg * "b29f3bf5-1dc4-499e-a676-7b2dbb864a03" , * where the party's persistant state is stored; this * must match the persistantstate used in earlier calls * for e.g. {@link SAOPSettings}.
negotiationdataa List of {@link FileLocation}s, serialized as * json, matching the negotiationdata used in earlier * calls for eg {@link SAOPSettings}.
* @param deadline the deadline of the negotiation. */ @SuppressWarnings("unused") @JsonCreator public LearnSettings( @JsonProperty("participants") List participants, @JsonProperty("deadline") Deadline deadline) { this.participants = participants; this.deadline = deadline; if (participants == null) { throw new IllegalArgumentException("participants must not be null"); } if (deadline == null) { throw new IllegalArgumentException("deadline must not be null"); } for (PartyWithProfile pwithp : getAllParties()) { Parameters params = pwithp.getParty().getParameters(); Object statestr = params.get("persistentstate"); if (!(statestr instanceof String)) throw new IllegalArgumentException( "persistentstate parameter containing UUID string is required, but found " + statestr); // check that it contains a UUID. Don't store it, we don't need // it. UUID.fromString((String) statestr); // and check the negotiationdata Object negotiationsstr = params.get("negotiationdata"); if (!(negotiationsstr instanceof List)) throw new IllegalArgumentException( "negotiationdata parameter containing a List is required"); for (Object negostr : (List) negotiationsstr) { if (!(negostr instanceof String)) throw new IllegalArgumentException( "The list in negotiationdata must contain UUID strings but found " + negostr); UUID.fromString((String) negostr); } } } @Override public Double getMaxRunTime() { return deadline.getDuration() / 1000d; } @Override public SessionProtocol getProtocol(Reporter logger) { return new Learn(new LearnState(this), logger); } @Override public List getTeams() { return Collections.unmodifiableList(participants); } /** * @return the deadline for this negotiation */ public Deadline getDeadline() { return deadline; } @Override public List getAllParties() { return participants.stream() .map(particip -> particip.getParties().get(0)) .collect(Collectors.toList()); } @Override public Integer getTeamSize() { return 1; } @Override public String toString() { return "LearnSettings" + participants + "," + deadline + "]"; } @Override public int hashCode() { final int prime = 31; int result = 1; result = prime * result + ((deadline == null) ? 0 : deadline.hashCode()); result = prime * result + ((participants == null) ? 0 : participants.hashCode()); return result; } @Override public boolean equals(Object obj) { if (this == obj) return true; if (obj == null) return false; if (getClass() != obj.getClass()) return false; LearnSettings other = (LearnSettings) obj; if (deadline == null) { if (other.deadline != null) return false; } else if (!deadline.equals(other.deadline)) return false; if (participants == null) { if (other.participants != null) return false; } else if (!participants.equals(other.participants)) return false; return true; } @Override public SessionSettings with(TeamInfo team) { if (team.getSize() != 1) throw new IllegalArgumentException( "Team must be size 1 but found " + team); List newparts = new LinkedList<>(participants); newparts.add(team); return new LearnSettings(newparts, deadline); } }