Changeset 18 for opponentmodel/src/main/java
- Timestamp:
- 06/11/20 16:34:40 (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
r14 r18 6 6 import java.util.stream.Collectors; 7 7 8 import geniusweb.actions.Action; 9 import geniusweb.actions.Offer; 8 10 import geniusweb.issuevalue.Bid; 9 11 import geniusweb.issuevalue.Domain; … … 12 14 import geniusweb.profile.utilityspace.NumberValueSetUtilities; 13 15 import geniusweb.profile.utilityspace.UtilitySpace; 16 import geniusweb.progress.Progress; 14 17 15 18 /** … … 23 26 * 24 27 */ 25 public class FrequencyOpponentModel implements OpponentModel, UtilitySpace{28 public class FrequencyOpponentModel implements UtilitySpace, OpponentModel { 26 29 27 30 private static final int DECIMALS = 4; // accuracy of our computations. … … 32 35 33 36 public FrequencyOpponentModel(Domain domain) { 34 // map with empth hashmap for each issue. 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 */ 35 42 this(domain, 36 43 domain.getIssues().stream().collect( … … 39 46 } 40 47 48 /** 49 * internal constructor. Assumes the freqs keyset is equal to the available 50 * issues. 51 * 52 * @param domain the domain 53 * @param freqs the observed frequencies for all issue values. This map is 54 * assumed to be a fresh private-access only copy. 55 * @param total the total number of bids contained in the freqs map. This 56 * must be equal to the sum of the Integer values in the 57 * {@link #bidFrequencies} for each issue (this is not 58 * checked). 59 */ 60 private FrequencyOpponentModel(Domain domain, 61 Map<String, Map<Value, Integer>> freqs, BigDecimal total) { 62 if (domain == null) { 63 throw new NullPointerException("domain=null"); 64 } 65 this.domain = domain; 66 this.bidFrequencies = freqs; 67 this.totalBids = total; 68 } 69 41 70 @Override 42 71 public BigDecimal getUtility(Bid bid) { … … 86 115 } 87 116 88 @Override 89 public FrequencyOpponentModel update(Bid bid) { 117 /** 118 * {@inheritDoc} 119 * 120 * <h1>change info</h1> This replaces update(Bid). Now you pass the entire 121 * action and the progress instead of just the bid. 122 */ 123 @Override 124 public FrequencyOpponentModel with(Action action, Progress progress) { 125 if (!(action instanceof Offer)) 126 return this; 127 128 Bid bid = ((Offer) action).getBid(); 90 129 String err = domain.isComplete(bid); 91 130 if (err != null) { … … 108 147 109 148 /** 110 * internal constructor. Assumes the freqs keyset is equal to the available111 * issues.112 *113 * @param domain the domain114 * @param freqs the observed frequencies for all issue values. This map is115 * assumed to be a fresh private-access only copy.116 * @param total the total number of bids contained in the freqs map. This117 * must be equal to the sum of the Integer values in the118 * {@link #bidFrequencies} for each issue (this is not119 * checked).120 */121 private FrequencyOpponentModel(Domain domain,122 Map<String, Map<Value, Integer>> freqs, BigDecimal total) {123 if (domain == null) {124 throw new NullPointerException("domain=null");125 }126 this.domain = domain;127 this.bidFrequencies = freqs;128 this.totalBids = total;129 }130 131 /**132 149 * 133 150 * @param freqs … … 141 158 } 142 159 return map; 160 } 161 162 @Override 163 public Bid getReservationBid() { 164 // don't throw but we really have no clue. 165 return new Bid(new HashMap<>()); 143 166 } 144 167 … … 188 211 } 189 212 190 @Override191 public Bid getReservationBid() {192 throw new UnsupportedOperationException();193 }194 195 213 } -
opponentmodel/src/main/java/geniusweb/opponentmodel/OpponentModel.java
r14 r18 1 1 package geniusweb.opponentmodel; 2 2 3 import geniusweb.issuevalue.Bid; 3 import geniusweb.actions.Action; 4 import geniusweb.issuevalue.Domain; 4 5 import geniusweb.profile.Profile; 5 6 import geniusweb.profile.utilityspace.UtilitySpace; 7 import geniusweb.progress.Progress; 6 8 7 9 /** 8 10 * An opponentmodel estimates a {@link UtilitySpace} from received opponent 9 * bids. 11 * actions. 12 * <h1>Requirement</h1> A OpponentModel must have a constructor that takes the 13 * Domain as argument. unfortunately this can not be enforced in a java 14 * interface 10 15 */ 11 16 public interface OpponentModel extends Profile { 17 12 18 /** 13 * 14 * @param bid the next bid that was received 15 * @return a new {@link OpponentModel} that takes the next bid into account. 19 * Update this with a new action that was done by the opponent that this 20 * model is modeling. {@link #with(Domain)} must be called before calling 21 * this. 22 * 23 * @param action the new incoming action. 24 * @param progress the current progress of the negotiation. Calls to this 25 * must be done with increasing progress. 26 * @return the updated {@link OpponentModel} 16 27 */ 17 OpponentModel update(Bid bid);28 OpponentModel with(Action action, Progress progress); 18 29 19 30 }
Note:
See TracChangeset
for help on using the changeset viewer.