Changeset 20 for opponentmodel
- Timestamp:
- 08/05/20 09:42:15 (4 years ago)
- Location:
- opponentmodel
- Files:
-
- 26 added
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
opponentmodel/pom.xml
r19 r20 6 6 <groupId>geniusweb</groupId> 7 7 <artifactId>opponentmodel</artifactId> 8 <version>1.4. 2</version> <!-- must equal ${geniusweb.version} -->8 <version>1.4.4</version> <!-- must equal ${geniusweb.version} --> 9 9 <packaging>jar</packaging> 10 10 … … 17 17 <passwd>${env.ARTIFACTORY_PASS}</passwd> 18 18 <jackson-2-version>2.9.10</jackson-2-version> 19 <geniusweb.version>1.4. 2</geniusweb.version>19 <geniusweb.version>1.4.4</geniusweb.version> 20 20 </properties> 21 21 -
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 /** -
opponentmodel/src/test/java/geniusweb/profile/opponentmodel/FrequencyOppModelTest.java
r18 r20 87 87 bid3 = new Bid(issuevalues); 88 88 89 oppModel1 = new FrequencyOpponentModel( domain);90 oppModel1b = new FrequencyOpponentModel( domain);91 oppModel2 = new FrequencyOpponentModel( domain2);92 oppModel3 = new FrequencyOpponentModel( domain3);89 oppModel1 = new FrequencyOpponentModel().with(domain, null); 90 oppModel1b = new FrequencyOpponentModel().with(domain, null); 91 oppModel2 = new FrequencyOpponentModel().with(domain2, null); 92 oppModel3 = new FrequencyOpponentModel().with(domain3, null); 93 93 oppModel4 = oppModel3.with(new Offer(other, bid1), progress); 94 94 … … 113 113 @Test(expected = NullPointerException.class) 114 114 public void smokeTestNull() { 115 new FrequencyOpponentModel( null);115 new FrequencyOpponentModel().with((Domain) null, null); 116 116 } 117 117 118 118 @Test 119 119 public void smokeTest() { 120 new FrequencyOpponentModel( domain);120 new FrequencyOpponentModel().with(domain, null); 121 121 } 122 122 123 123 @Test 124 124 public void testEmptyModel() { 125 FrequencyOpponentModel oppModel = new FrequencyOpponentModel(domain); 125 FrequencyOpponentModel oppModel = new FrequencyOpponentModel() 126 .with(domain, null); 126 127 assertEquals(BigDecimal.ONE, oppModel.getUtility(bid1)); 127 128 assertEquals(BigDecimal.ONE, oppModel.getUtility(bid2)); … … 153 154 } 154 155 156 @Test 157 public void testPartialBidUpdate() { 158 FrequencyOpponentModel oppModel = oppModel1.with(new Offer(other, bid1), 159 progress); 160 Bid partialbid = new Bid(ISS1, I1V1); 161 oppModel.with(new Offer(other, partialbid), progress); 162 } 163 155 164 }
Note:
See TracChangeset
for help on using the changeset viewer.