- Timestamp:
- 01/28/20 10:19:54 (5 years ago)
- Location:
- profile/src
- Files:
-
- 1 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
profile/src/main/java/geniusweb/profile/DefaultPartialOrdering.java
r2 r10 26 26 * limited anyway. 27 27 */ 28 public class DefaultPartialOrdering extends DefaultProfile implements PartialOrdering { 28 public class DefaultPartialOrdering extends DefaultProfile 29 implements PartialOrdering { 29 30 30 31 /** … … 40 41 * @param reservationbid 41 42 * @param bids 42 * @param isbetterList a list of tuples [bid1index, bid2index]. It indicates 43 * that bids[bid1index] isbetterthan bids[bid2index]. 43 * @param isbetterList a list of tuples [bid1index, bid2index]. It 44 * indicates that bids[bid1index] isbetterthan 45 * bids[bid2index]. 44 46 */ 45 47 @JsonCreator 46 public DefaultPartialOrdering(@JsonProperty("name") String name, @JsonProperty("domain") Domain domain, 47 @JsonProperty("reservationBid") Bid reservationbid, @JsonProperty("bids") List<Bid> bids, 48 public DefaultPartialOrdering(@JsonProperty("name") String name, 49 @JsonProperty("domain") Domain domain, 50 @JsonProperty("reservationBid") Bid reservationbid, 51 @JsonProperty("bids") List<Bid> bids, 48 52 @JsonProperty("better") List<List<Integer>> isbetterList) { 49 53 this(name, domain, reservationbid, makeBidMap(bids, isbetterList)); … … 54 58 * @param domain the {@link Domain} description 55 59 * @param reservationbid the reservation {@link Bid} 56 * @param isBetterMap a map with keys = a better bid and value=a less good57 * bid.60 * @param isBetterMap a map with keys = a better bid and value=a less 61 * good bid. 58 62 */ 59 public DefaultPartialOrdering(String name, Domain domain, Bid reservationbid, Map<Bid, Set<Bid>> isBetterMap) { 63 public DefaultPartialOrdering(String name, Domain domain, 64 Bid reservationbid, Map<Bid, Set<Bid>> isBetterMap) { 60 65 super(name, domain, reservationbid); 61 66 this.isBetter = isBetterMap; … … 71 76 /** 72 77 * 73 * @return a list with all the bids 78 * @return a list with all the bids that are referred to, either as better 79 * or as worse than another bid 74 80 */ 75 81 @JsonGetter … … 97 103 if (isBetter.containsKey(bid)) { 98 104 for (Bid worsebid : isBetter.get(bid)) { 99 betterlist.add(Arrays.asList(bidslist.indexOf(bid), bidslist.indexOf(worsebid))); 105 betterlist.add(Arrays.asList(bidslist.indexOf(bid), 106 bidslist.indexOf(worsebid))); 100 107 } 101 108 } … … 107 114 @Override 108 115 public String toString() { 109 return "DefaultPartialOrdering[" + getValuesString() + "," + isBetter + "]"; 116 return "DefaultPartialOrdering[" + getValuesString() + "," + isBetter 117 + "]"; 110 118 } 111 119 112 private static Map<Bid, Set<Bid>> makeBidMap(List<Bid> bids, List<List<Integer>> isBetterList) { 120 private static Map<Bid, Set<Bid>> makeBidMap(List<Bid> bids, 121 List<List<Integer>> isBetterList) { 113 122 Map<Bid, Set<Bid>> betterMap = new HashMap<>(); 114 123 115 124 for (List<Integer> tuple : isBetterList) { 116 125 if (tuple.size() != 2) { 117 throw new IllegalArgumentException("Expected tuple but found " + tuple + "in " + isBetterList); 126 throw new IllegalArgumentException("Expected tuple but found " 127 + tuple + "in " + isBetterList); 118 128 } 119 129 Bid betterbid = bids.get(tuple.get(0)); … … 133 143 final int prime = 31; 134 144 int result = super.hashCode(); 135 result = prime * result + ((isBetter == null) ? 0 : isBetter.hashCode()); 145 result = prime * result 146 + ((isBetter == null) ? 0 : isBetter.hashCode()); 136 147 return result; 137 148 } -
profile/src/main/java/geniusweb/profile/utilityspace/DiscreteValueSetUtilities.java
r9 r10 2 2 3 3 import java.math.BigDecimal; 4 import java.util.Collections; 4 5 import java.util.HashMap; 5 6 import java.util.HashSet; … … 68 69 } 69 70 71 /** 72 * @return copy of the value-utility pair map. 73 */ 74 public Map<DiscreteValue, BigDecimal> getUtilities() { 75 return Collections.unmodifiableMap(valueUtilities); 76 } 77 70 78 @Override 71 79 public String isFitting(ValueSet valueset) { -
profile/src/main/java/geniusweb/profile/utilityspace/LinearAdditiveUtilitySpace.java
r7 r10 25 25 */ 26 26 @JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE) 27 public class LinearAdditiveUtilitySpace implements UtilitySpace {27 public class LinearAdditiveUtilitySpace implements LinearAdditive { 28 28 29 29 private final String name; … … 131 131 } 132 132 133 /** 134 * 135 * @param issue the issue to get weighted util for 136 * @param value the issue value to use (typically coming from a bid) 137 * @return weighted util of just the issue value: 138 * issueUtilities[issue].utility(value) * issueWeights[issue) 139 */ 140 private BigDecimal util(String issue, Value value) { 141 return issueWeights.get(issue) 142 .multiply(issueUtilities.get(issue).getUtility(value)); 143 } 144 133 @Override 145 134 public BigDecimal getWeight(String issue) { 146 135 return issueWeights.get(issue); … … 220 209 } 221 210 222 /** 223 * @return the map from issue names to valuesetutilities (un-weighted) 224 */ 211 @Override 225 212 public Map<String, ValueSetUtilities> getUtilities() { 226 213 return Collections.unmodifiableMap(issueUtilities); 227 214 } 228 215 229 /** 230 * 231 * @return the map from issue names to weights. weights sum to 1. 232 */ 216 @Override 233 217 public Map<String, BigDecimal> getWeights() { 234 218 return Collections.unmodifiableMap(issueWeights); 235 219 } 236 220 221 /** 222 * 223 * @param issue the issue to get weighted util for 224 * @param value the issue value to use (typically coming from a bid) 225 * @return weighted util of just the issue value: 226 * issueUtilities[issue].utility(value) * issueWeights[issue) 227 */ 228 private BigDecimal util(String issue, Value value) { 229 return issueWeights.get(issue) 230 .multiply(issueUtilities.get(issue).getUtility(value)); 231 } 232 237 233 } -
profile/src/main/java/geniusweb/profile/utilityspace/SumOfGroupsUtilitySpace.java
r9 r10 84 84 * grouping. 85 85 * 86 * @param las the {@link LinearAdditive UtilitySpace} to be converted/copied.87 * 88 */ 89 public SumOfGroupsUtilitySpace(LinearAdditive UtilitySpacelas) {86 * @param las the {@link LinearAdditive} to be converted/copied. 87 * 88 */ 89 public SumOfGroupsUtilitySpace(LinearAdditive las) { 90 90 this(las.getDomain(), las.getName(), las2parts(las), 91 91 las.getReservationBid()); … … 212 212 /** 213 213 * 214 * @param las a {@link LinearAdditive UtilitySpace}214 * @param las a {@link LinearAdditive} 215 215 * @return a Map with partname-PartsUtilities. The partnames are identical 216 216 * to the issues in the given las. 217 217 */ 218 218 private static HashMap<String, PartsUtilities> las2parts( 219 LinearAdditive UtilitySpacelas) {219 LinearAdditive las) { 220 220 221 221 HashMap<String, PartsUtilities> map = new HashMap<>(); -
profile/src/test/java/geniusweb/profile/utilityspace/NumberValueSetUtilTest.java
r9 r10 3 3 import static org.junit.Assert.assertEquals; 4 4 5 import java.io.IOException; 5 6 import java.math.BigDecimal; 6 7 import java.util.Arrays; … … 8 9 9 10 import org.junit.Test; 11 12 import com.fasterxml.jackson.core.JsonParseException; 13 import com.fasterxml.jackson.core.JsonProcessingException; 14 import com.fasterxml.jackson.databind.JsonMappingException; 15 import com.fasterxml.jackson.databind.ObjectMapper; 10 16 11 17 import geniusweb.issuevalue.DiscreteValue; … … 35 41 lowval1, low1util, highvalb, highutil); 36 42 private static final BigDecimal ZERO_1 = new BigDecimal("0.1"); 43 private final String utilstring = "{\"numberutils\":{\"lowValue\":12.5,\"lowUtility\":0.5,\"highValue\":18.5,\"highUtility\":0.9}}"; 44 45 private static final ObjectMapper jackson = new ObjectMapper(); 37 46 38 47 @Override … … 173 182 } 174 183 184 @Test 185 public void testSerialize() throws JsonProcessingException { 186 187 String json = jackson.writeValueAsString(valueset1); 188 System.out.println(json); 189 assertEquals(utilstring, json); 190 } 191 192 @Test 193 public void testDeserialize() 194 throws JsonParseException, JsonMappingException, IOException { 195 ValueSetUtilities valueutils = jackson.readValue(utilstring, 196 ValueSetUtilities.class); 197 assertEquals(valueset1, valueutils); 198 199 } 200 175 201 }
Note:
See TracChangeset
for help on using the changeset viewer.