Changeset 23 for protocol/src/main
- Timestamp:
- 09/28/20 09:28:44 (4 years ago)
- Location:
- protocol/src/main/java/geniusweb/protocol
- Files:
-
- 12 edited
Legend:
- Unmodified
- Added
- Removed
-
protocol/src/main/java/geniusweb/protocol/session/SessionResult.java
r21 r23 2 2 3 3 import java.util.Collections; 4 import java.util. List;4 import java.util.Map; 5 5 6 6 import com.fasterxml.jackson.annotation.JsonAutoDetect; … … 10 10 import com.fasterxml.jackson.annotation.JsonTypeInfo; 11 11 12 import geniusweb.actions.PartyId; 12 13 import geniusweb.inform.Agreements; 13 14 import geniusweb.references.PartyWithProfile; … … 19 20 @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE) 20 21 public class SessionResult { 21 private final List<PartyWithProfile> participants;22 private final Map<PartyId, PartyWithProfile> participants; 22 23 private final Agreements agreements; 23 private final List<Double> penalties;24 private final Map<PartyId, Double> penalties; 24 25 25 26 // add more type info so that jackson can deserialize the actual class … … 29 30 /** 30 31 * 31 * @param participants the list oof {@link PartyWithProfile}, in the proper 32 * order (this is relevant for the protocol etc). Should 33 * never be null. Some of them may have entered later of 34 * left early. This list should contain them all. 32 * @param participants the list oof {@link PartyWithProfile}. Should never 33 * be null. Some of them may have entered later of left 34 * early. This list should contain them all. 35 35 * @param agreements the final Agreements. 36 * @param penalties the penalties in [0,1] for each participant, same 37 * order as the participants list. 36 * @param penalties the penalties in [0,1] for each participant. 38 37 * @param error a fatal error that terminated the session. Non-fatal 39 38 * errors (warnings) are not to be reported. Null if no … … 46 45 @JsonCreator 47 46 public SessionResult( 48 @JsonProperty("participants") List<PartyWithProfile> participants,47 @JsonProperty("participants") Map<PartyId, PartyWithProfile> participants, 49 48 @JsonProperty("agreements") Agreements agreements, 50 @JsonProperty("penalties") List<Double> penalties,49 @JsonProperty("penalties") Map<PartyId, Double> penalties, 51 50 @JsonProperty("error") Throwable error) { 52 51 this.participants = participants; … … 58 57 /** 59 58 * 60 * @return the list oof {@link PartyWithProfile}, in the proper order (this61 * is relevant for the protocol etc). Should never be null. Some of62 * them may have entered later of left early. This list should63 * contain themall.59 * @return the map with for each {@link PartyId} the 60 * {@link PartyWithProfile}. Should never be null. Some of them may 61 * have entered later of left early. This list should contain them 62 * all. 64 63 */ 65 public List<PartyWithProfile> getParticipants() {66 return Collections.unmodifiable List(participants);64 public Map<PartyId, PartyWithProfile> getParticipants() { 65 return Collections.unmodifiableMap(participants); 67 66 } 68 67 … … 77 76 /** 78 77 * 79 * @return list of penalties, in same order as {@link #getParticipants()}.78 * @return Map of penalties, 80 79 */ 81 public List<Double> getPenalties() {82 return Collections.unmodifiable List(penalties);80 public Map<PartyId, Double> getPenalties() { 81 return Collections.unmodifiableMap(penalties); 83 82 } 84 83 -
protocol/src/main/java/geniusweb/protocol/session/amop/AMOPState.java
r21 r23 255 255 @Override 256 256 public SessionResult getResult() { 257 List<Double> emptylist = new LinkedList<>(); 258 for (int n = 0; n < getConnections().size(); n++) 259 emptylist.add(0d); 260 return new SessionResult(getSettings().getAllParties(), getAgreements(), 261 emptylist, null); 257 return new SessionResult(partyprofiles, getAgreements(), 258 Collections.emptyMap(), null); 262 259 } 263 260 -
protocol/src/main/java/geniusweb/protocol/session/mopac/MOPAC.java
r22 r23 145 145 ProtocolToPartyConnFactory connectionfactory) { 146 146 try { 147 // System.out.println("starting MOPAC");147 // System.out.println("starting MOPAC"); 148 148 // we're in Phase.INIT still 149 149 connect(connectionfactory); … … 314 314 final ProtocolToPartyConn partyconn, final Action action, 315 315 long now) { 316 //System.out.println("received " + action); 316 if (finished) 317 return; 317 318 state = state.with(partyconn.getParty(), action, now); 318 319 checkEndPhase(System.currentTimeMillis()); … … 352 353 */ 353 354 private void broadcastNegotiators(Inform info) { 354 // System.out.println("broadcasting " + info);355 // System.out.println("broadcasting " + info); 355 356 for (PartyId party : state.getPhase().getPartyStates() 356 357 .getNegotiatingParties()) { -
protocol/src/main/java/geniusweb/protocol/session/mopac/MOPACState.java
r22 r23 270 270 @Override 271 271 public SessionResult getResult() { 272 List<Double> emptylist = new LinkedList<>(); 273 for (int n = 0; n < getConnections().size(); n++) 274 emptylist.add(0d); 275 return new SessionResult(getSettings().getAllParties(), getAgreements(), 276 emptylist, null); 272 return new SessionResult(partyprofiles, getAgreements(), 273 Collections.emptyMap(), null); 277 274 } 278 275 -
protocol/src/main/java/geniusweb/protocol/session/mopac/phase/DefaultPhase.java
r21 r23 3 3 import java.util.List; 4 4 import java.util.stream.Collectors; 5 6 import com.fasterxml.jackson.annotation.JsonIgnore; 5 7 6 8 import geniusweb.actions.Action; … … 12 14 13 15 public abstract class DefaultPhase implements Phase { 14 protected final List<Class<? extends Action>> allowedActions; 15 protected final Long deadline; // unix timestamp ms since 1970 16 // deadline for this phase, ms since 1970 17 protected final Long deadline; 18 protected final PartyStates partyStates; 19 20 // don't serialize this, users don't need it.. 21 @JsonIgnore 22 protected final VotingEvaluator evaluator; 23 24 // don't serialize this, it will cause very large file 25 @JsonIgnore 16 26 protected final Phase prevPhase; 17 protected final PartyStates partyStates;18 protected final VotingEvaluator evaluator;19 27 20 28 /** 21 29 * 22 * @param actions 23 * @param prevPhases 30 * @param actions the actions done in this phase . 31 * @param prevPhase the previous phase, can be used to collect previous 32 * votes etc. 24 33 * @param partyStates 25 * @param allowed 26 * @param deadline deadline time ms since 1970 34 * @param deadline deadline for this phase, ms since 1970 27 35 */ 28 public DefaultPhase(Phase prevPhase, PartyStates partyStates, 29 List<Class<? extends Action>> allowed, Long deadline, 36 public DefaultPhase(Phase prevPhase, PartyStates partyStates, Long deadline, 30 37 VotingEvaluator evaluator) { 31 this.allowedActions = allowed;32 38 this.partyStates = partyStates; 33 39 this.deadline = deadline; … … 82 88 if (isFinal(timems)) 83 89 throw new ProtocolException("passed deadline", actor); 84 if (!( allowedActions.contains(action.getClass())))90 if (!(getAllowedActions().contains(action.getClass()))) 85 91 throw new ProtocolException( 86 92 "Action not allowed in " + this.getClass() + ":" + action, … … 129 135 // contains prevstate..... 130 136 return getClass().getSimpleName() + "[" + partyStates + "," + deadline 131 + "," + allowedActions + "," +evaluator + "]";137 + "," + evaluator + "]"; 132 138 } 133 139 } -
protocol/src/main/java/geniusweb/protocol/session/mopac/phase/OfferPhase.java
r21 r23 20 20 public OfferPhase(Phase prevPhase, PartyStates partyStates, Long deadlinems, 21 21 VotingEvaluator evaluator) { 22 super(prevPhase, partyStates, 23 Arrays.asList(Offer.class, EndNegotiation.class), deadlinems, 24 evaluator); 22 super(prevPhase, partyStates, deadlinems, evaluator); 25 23 } 26 24 … … 64 62 } 65 63 64 @Override 65 public List<Class<? extends Action>> getAllowedActions() { 66 return Arrays.asList(Offer.class, EndNegotiation.class); 67 } 68 66 69 } -
protocol/src/main/java/geniusweb/protocol/session/mopac/phase/OptInPhase.java
r21 r23 2 2 3 3 import java.util.Arrays; 4 import java.util.List; 4 5 import java.util.Map; 5 6 import java.util.stream.Collectors; … … 21 22 protected OptInPhase(Phase prevPhase, PartyStates partyStates, 22 23 Long deadlinems, VotingEvaluator evaluator) { 23 super(prevPhase, partyStates, 24 Arrays.asList(Votes.class, EndNegotiation.class), deadlinems, 25 evaluator); 24 super(prevPhase, partyStates, deadlinems, evaluator); 26 25 } 27 26 … … 94 93 } 95 94 95 @Override 96 public List<Class<? extends Action>> getAllowedActions() { 97 return Arrays.asList(Votes.class, EndNegotiation.class); 98 } 99 96 100 } -
protocol/src/main/java/geniusweb/protocol/session/mopac/phase/Phase.java
r21 r23 1 1 package geniusweb.protocol.session.mopac.phase; 2 2 3 import java.util.List; 3 4 import java.util.Set; 5 6 import com.fasterxml.jackson.annotation.JsonAutoDetect; 7 import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility; 4 8 5 9 import geniusweb.actions.Action; … … 15 19 * 16 20 */ 21 @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE) 17 22 public interface Phase { 18 23 public static final Long PHASE_MAXTIME = 30000l; // 30sec … … 99 104 public PartyStates getPartyStates(); 100 105 106 /** 107 * @return the allowed actinos in this phase 108 */ 109 public abstract List<Class<? extends Action>> getAllowedActions(); 110 101 111 } -
protocol/src/main/java/geniusweb/protocol/session/mopac/phase/VotingPhase.java
r21 r23 2 2 3 3 import java.util.Arrays; 4 import java.util.List; 4 5 5 6 import geniusweb.actions.Action; … … 17 18 VotingPhase(Phase prevPhase, PartyStates partyStates, Long deadlinems, 18 19 VotingEvaluator evaluator) { 19 super(prevPhase, partyStates, 20 Arrays.asList(Votes.class, EndNegotiation.class), deadlinems, 21 evaluator); 20 super(prevPhase, partyStates, deadlinems, evaluator); 22 21 } 23 22 … … 56 55 } 57 56 57 @Override 58 public List<Class<? extends Action>> getAllowedActions() { 59 return Arrays.asList(Votes.class, EndNegotiation.class); 60 } 61 58 62 } -
protocol/src/main/java/geniusweb/protocol/session/saop/SAOPState.java
r21 r23 266 266 @Override 267 267 public SessionResult getResult() { 268 List<Double> emptylist = new LinkedList<>(); 269 for (int n = 0; n < getConnections().size(); n++) 270 emptylist.add(0d); 271 return new SessionResult(getSettings().getAllParties(), getAgreements(), 272 emptylist, getError()); 268 return new SessionResult(getPartyProfiles(), getAgreements(), 269 Collections.emptyMap(), getError()); 273 270 } 274 271 -
protocol/src/main/java/geniusweb/protocol/session/shaop/BareSHAOPState.java
r21 r23 1 1 package geniusweb.protocol.session.shaop; 2 2 3 import java.util.Arrays;4 3 import java.util.Collections; 4 import java.util.HashMap; 5 5 import java.util.LinkedList; 6 6 import java.util.List; 7 7 import java.util.Map; 8 import java.util.stream.Collectors; 8 9 9 10 import com.fasterxml.jackson.annotation.JsonCreator; … … 171 172 @Override 172 173 public SessionResult getResult() { 173 Double[] penalties = new Double[partyNumbers.size()];174 Map<PartyId, Double> penalties = new HashMap<>(); 174 175 for (PartyId party : partyNumbers.keySet()) { 175 176 Double spent = totalSpent.get(party); … … 179 180 spent = Math.max(0, Math.min(1.0, spent)); 180 181 } 181 penalties[partyNumbers.get(party)] = spent; 182 } 183 return new SessionResult(getSettings().getAllParties(), getAgreements(), 184 Arrays.asList(penalties), getError()); 182 penalties.put(party, spent); 183 } 184 Map<PartyId, PartyWithProfile> allparties = partyNumbers.keySet() 185 .stream().collect(Collectors.toMap(pid -> pid, pid -> settings 186 .getAllParties().get(partyNumbers.get(pid)))); 187 return new SessionResult(allparties, getAgreements(), penalties, 188 getError()); 185 189 186 190 } -
protocol/src/main/java/geniusweb/protocol/tournament/allpermutations/AllPermutationsState.java
r21 r23 54 54 */ 55 55 public AllPermutationsState with(SessionResult result) { 56 if (!getNextSettings().getAllParties() 57 .equals(result.getParticipants())) { 58 throw new IllegalArgumentException("Inconsistent session result"); 59 } 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 // } 60 61 ArrayList<SessionResult> newresults = new ArrayList<>(results); 61 62 newresults.add(result);
Note:
See TracChangeset
for help on using the changeset viewer.