Changeset 20 for opponentmodel/src/main/java
- Timestamp:
- 08/05/20 09:42:15 (4 years ago)
- Location:
- opponentmodel/src/main/java/geniusweb/opponentmodel
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
opponentmodel/src/main/java/geniusweb/opponentmodel/FrequencyOpponentModel.java
r18 r20 24 24 * (as you might expect as {@link NumberValueSetUtilities} is only affected by 25 25 * the endpoints). 26 * 26 * <p> 27 * immutable. 27 28 */ 28 29 public class FrequencyOpponentModel implements UtilitySpace, OpponentModel { 29 30 30 31 private static final int DECIMALS = 4; // accuracy of our computations. 32 private static int serial = 1; // counter for auto name generation 33 31 34 private final Domain domain; 32 35 private final Map<String, Map<Value, Integer>> bidFrequencies; 33 36 private final BigDecimal totalBids; 34 private static int serial = 1; // counter for auto name generation 35 36 public FrequencyOpponentModel(Domain domain) { 37 /* 38 * simply reset the whole model and make a new one... maybe this can be 39 * done smarter for minor changes? map with empth hashmap for each 40 * issue. 41 */ 42 this(domain, 37 38 public FrequencyOpponentModel() { 39 this.domain = null; 40 this.bidFrequencies = null; 41 this.totalBids = BigDecimal.ZERO; 42 } 43 44 @Override 45 public FrequencyOpponentModel with(Domain domain, Bid resBid) { 46 // FIXME merge already available frequencies? 47 return new FrequencyOpponentModel(domain, 43 48 domain.getIssues().stream().collect( 44 49 Collectors.toMap(iss -> iss, iss -> new HashMap<>())), … … 115 120 } 116 121 117 /**118 * {@inheritDoc}119 *120 * <h1>change info</h1> This replaces update(Bid). Now you pass the entire121 * action and the progress instead of just the bid.122 */123 122 @Override 124 123 public FrequencyOpponentModel with(Action action, Progress progress) { … … 127 126 128 127 Bid bid = ((Offer) action).getBid(); 129 String err = domain.isComplete(bid);130 if (err != null) {131 throw new IllegalArgumentException(err);132 }133 128 Map<String, Map<Value, Integer>> newFreqs = cloneMap(bidFrequencies); 134 129 for (String issue : domain.getIssues()) { 135 130 Map<Value, Integer> freqs = newFreqs.get(issue); 136 131 Value value = bid.getValue(issue); 137 Integer oldfreq = freqs.get(value); 138 if (oldfreq == null) { 139 oldfreq = 0; 132 if (value != null) { 133 Integer oldfreq = freqs.get(value); 134 if (oldfreq == null) { 135 oldfreq = 0; 136 } 137 freqs.put(value, oldfreq + 1); 140 138 } 141 freqs.put(value, oldfreq + 1);142 139 } 143 140 -
opponentmodel/src/main/java/geniusweb/opponentmodel/OpponentModel.java
r18 r20 2 2 3 3 import geniusweb.actions.Action; 4 import geniusweb.issuevalue.Bid; 4 5 import geniusweb.issuevalue.Domain; 5 6 import geniusweb.profile.Profile; … … 13 14 * Domain as argument. unfortunately this can not be enforced in a java 14 15 * interface 16 * 17 * <p> 18 * <em>MUST</em> have an empty constructor as these are also used as part of the 19 * BOA framework. 20 * 15 21 */ 16 22 public interface OpponentModel extends Profile { 23 24 /** 25 * Initializes the model. This function must be called first after 26 * constructing an instance. It can also be called later, if there is a 27 * change in the domain or resBid. 28 * 29 * @param domain the domain to work with 30 * @param resBid the reservation bid, or null if no reservationbid is 31 * available. 32 * @return OpponentModel that uses given domain and reservationbid. 33 * 34 */ 35 OpponentModel with(Domain domain, Bid resBid); 17 36 18 37 /**
Note:
See TracChangeset
for help on using the changeset viewer.