Ignore:
Timestamp:
12/18/24 13:28:59 (4 days ago)
Author:
ruud
Message:

All TimeDependent parties now support the nonlinear SumOfGroupsUtilitySpace. Example Nonlinear space in the computer domain

File:
1 edited

Legend:

Unmodified
Added
Removed
  • profile/src/main/java/geniusweb/profile/utilityspace/PartsUtilities.java

    r52 r53  
    77import java.util.List;
    88import java.util.Map;
     9import java.util.stream.Collectors;
    910
    1011import com.fasterxml.jackson.annotation.JsonAutoDetect;
     
    1314import com.fasterxml.jackson.annotation.JsonProperty;
    1415
     16import geniusweb.issuevalue.Domain;
    1517import geniusweb.issuevalue.Value;
    1618import geniusweb.issuevalue.ValueSet;
     19import tudelft.utilities.immutablelist.ImmutableList;
     20import tudelft.utilities.immutablelist.Outer;
    1721
    1822/**
     
    4145         *
    4246         * @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.
    4752         */
    4853        public PartsUtilities(List<String> issues,
    4954                        Map<ProductOfValue, BigDecimal> utils) {
    50                 if (issues == null || utils == null) {
     55                if (issues == null || utils == null || issues.isEmpty()) {
    5156                        throw new IllegalArgumentException(
    52                                         "issues and utils must be not null");
     57                                        "issues and utils must be not null or empty");
    5358                }
    5459
     
    149154        }
    150155
     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
    151177        @Override
    152178        public boolean equals(Object obj) {
     
    176202        }
    177203
     204        /**
     205         * Check that the set of utilities is complete and no weird utility values
     206         * were used
     207         *
     208         */
    178209        private void checkUtilities() {
    179                 if (utilities.values().stream()
    180                                 .anyMatch(v -> v == null || v.compareTo(BigDecimal.ZERO) < 0
    181                                                 || 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);
    184215                }
    185216        }
     
    196227
    197228        /**
    198          *
    199229         * @return the max utility of all values contained here.
    200230         */
Note: See TracChangeset for help on using the changeset viewer.