- Timestamp:
- 12/18/24 13:28:59 (4 days ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
profile/src/main/java/geniusweb/profile/utilityspace/PartsUtilities.java
r52 r53 7 7 import java.util.List; 8 8 import java.util.Map; 9 import java.util.stream.Collectors; 9 10 10 11 import com.fasterxml.jackson.annotation.JsonAutoDetect; … … 13 14 import com.fasterxml.jackson.annotation.JsonProperty; 14 15 16 import geniusweb.issuevalue.Domain; 15 17 import geniusweb.issuevalue.Value; 16 18 import geniusweb.issuevalue.ValueSet; 19 import tudelft.utilities.immutablelist.ImmutableList; 20 import tudelft.utilities.immutablelist.Outer; 17 21 18 22 /** … … 41 45 * 42 46 * @param issues list of issues 43 * @param utils with keys: list of values and value: utility value for that 44 * list of values. All list-of-values missing from the map are 45 * assumed to have utility 0. This includes partial bids where 46 * list-of-values contain null objects. 47 * @param utils with keys: list of values, one for each issue in issues (in 48 * the order of the list of issues) and value: utility value 49 * for that list of values. All list-of-values missing from 50 * the map are assumed to have utility 0. This includes 51 * partial bids where list-of-values contain null objects. 47 52 */ 48 53 public PartsUtilities(List<String> issues, 49 54 Map<ProductOfValue, BigDecimal> utils) { 50 if (issues == null || utils == null ) {55 if (issues == null || utils == null || issues.isEmpty()) { 51 56 throw new IllegalArgumentException( 52 "issues and utils must be not null ");57 "issues and utils must be not null or empty"); 53 58 } 54 59 … … 149 154 } 150 155 156 /** 157 * Check that all needed values have been set to a utility. 158 * 159 * @param domain the domain for which this should be parts. We need this to 160 * check that the values used are actually from the dmoain 161 * @throws IllegalArgumentException if a problem is found 162 */ 163 public void checkComplete(Domain domain) { 164 165 final List<ImmutableList<Value>> valuesofissues = issues.stream() 166 .map(iss -> domain.getValues(iss)).collect(Collectors.toList()); 167 168 // check that all possible value combinations are handled 169 for (ImmutableList<Value> vals : new Outer<Value>(valuesofissues)) { 170 ProductOfValue expected = ProductOfValue.create(vals); 171 if (!utilities.containsKey(expected)) 172 throw new IllegalArgumentException( 173 "Values " + vals + " must be assigned a utility"); 174 } 175 } 176 151 177 @Override 152 178 public boolean equals(Object obj) { … … 176 202 } 177 203 204 /** 205 * Check that the set of utilities is complete and no weird utility values 206 * were used 207 * 208 */ 178 209 private void checkUtilities() { 179 if (utilities.values().stream()180 .anyMatch(v -> v == null || v.compareTo(BigDecimal.ZERO) < 0181 || v.compareTo(BigDecimal.ONE) > 0)) {182 throw new IllegalArgumentException(183 "part weights must all be in [0,1]");210 for (BigDecimal value : utilities.values()) { 211 if (value == null || value.compareTo(BigDecimal.ZERO) < 0 212 || value.compareTo(BigDecimal.ONE) > 0) 213 throw new IllegalArgumentException( 214 "part weights must all be in [0,1] but found " + value); 184 215 } 185 216 } … … 196 227 197 228 /** 198 *199 229 * @return the max utility of all values contained here. 200 230 */
Note:
See TracChangeset
for help on using the changeset viewer.