Changeset 9 for profile


Ignore:
Timestamp:
11/28/19 14:40:48 (5 years ago)
Author:
bart
Message:

Release 1.1.0

Location:
profile
Files:
6 added
8 edited

Legend:

Unmodified
Added
Removed
  • profile/pom.xml

    r4 r9  
    66        <groupId>geniusweb</groupId>
    77        <artifactId>profile</artifactId>
    8         <version>1.0.0</version>
     8        <version>1.1.0</version>
    99        <packaging>jar</packaging>
    1010
     
    1616                <basedir>.</basedir>
    1717                <passwd>${env.ARTIFACTORY_PASS}</passwd>
    18                 <jackson-2-version>2.9.6</jackson-2-version>
     18                <jackson-2-version>2.9.10</jackson-2-version>
    1919        </properties>
    2020
     
    3131                        <groupId>geniusweb</groupId>
    3232                        <artifactId>issuevalue</artifactId>
    33                         <version>1.0.0</version>
     33                        <version>1.1.0</version>
    3434                </dependency>
    3535                <dependency>
    3636                        <groupId>geniusweb</groupId>
    3737                        <artifactId>references</artifactId>
    38                         <version>1.0.0</version>
     38                        <version>1.1.0</version>
    3939                </dependency>
    4040
  • profile/src/main/java/geniusweb/profile/Profile.java

    r2 r9  
    77import geniusweb.issuevalue.Domain;
    88import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
     9import geniusweb.profile.utilityspace.SumOfGroupsUtilitySpace;
    910
    1011/**
     
    1718@JsonTypeInfo(use = JsonTypeInfo.Id.NAME, include = JsonTypeInfo.As.WRAPPER_OBJECT)
    1819@JsonSubTypes({ @JsonSubTypes.Type(value = LinearAdditiveUtilitySpace.class),
    19                 @JsonSubTypes.Type(value = DefaultPartialOrdering.class) })
     20                @JsonSubTypes.Type(value = DefaultPartialOrdering.class),
     21                @JsonSubTypes.Type(value = SumOfGroupsUtilitySpace.class) })
    2022public interface Profile {
    2123
     
    3335        /**
    3436         *
    35          * @return a (hypothetical) bid that is the best alternative to a non-agreement.
    36          *         Only bids that are {@link #isPreferredOrEqual(Bid, Bid)} should be
    37          *         accepted. If a negotiation does not reach an agreement, the party can
    38          *         get this offer somewhere else. This replaces the older notion of a
     37         * @return a (hypothetical) bid that is the best alternative to a
     38         *         non-agreement. Only bids that are
     39         *         {@link #isPreferredOrEqual(Bid, Bid)} should be accepted. If a
     40         *         negotiation does not reach an agreement, the party can get this
     41         *         offer somewhere else. This replaces the older notion of a
    3942         *         "reservation value" and is more general. If null, there is no
    4043         *         reservation bid and any agreement is better than no agreement.
  • profile/src/main/java/geniusweb/profile/utilityspace/DiscreteValueSetUtilities.java

    r1 r9  
    88import com.fasterxml.jackson.annotation.JsonAutoDetect;
    99import com.fasterxml.jackson.annotation.JsonAutoDetect.Visibility;
     10import com.fasterxml.jackson.annotation.JsonTypeName;
    1011
    1112import geniusweb.issuevalue.DiscreteValue;
     
    1314import geniusweb.issuevalue.Value;
    1415import geniusweb.issuevalue.ValueSet;
    15 
    16 import com.fasterxml.jackson.annotation.JsonTypeName;
    1716
    1817/**
     
    3736         * create new object based on the given mapping from values to utilities.
    3837         *
    39          * @param valueUtils map with key {@link DiscreteValue}s and value a Double in
    40          *                   the range [0,1].
     38         * @param valueUtils map with key {@link DiscreteValue}s and value a Double
     39         *                   in the range [0,1].
    4140         * @throws NullPointerException     if one of the args is null
    4241         * @throws IllegalArgumentException if values are not in range [0,1].
    4342         */
    44         public DiscreteValueSetUtilities(Map<DiscreteValue, BigDecimal> valueUtils) {
     43        public DiscreteValueSetUtilities(
     44                        Map<DiscreteValue, BigDecimal> valueUtils) {
    4545                if (valueUtils == null) {
    4646                        throw new NullPointerException("valueUtils==null");
    4747                }
    4848                if (valueUtils.keySet().contains(null)) {
    49                         throw new NullPointerException("one of the keys in valueUtils is null");
     49                        throw new NullPointerException(
     50                                        "one of the keys in valueUtils is null");
    5051                }
    5152                if (valueUtils.values().stream()
    52                                 .anyMatch(v -> v == null || v.compareTo(BigDecimal.ZERO) < 0 || v.compareTo(BigDecimal.ONE) > 0)) {
    53                         throw new IllegalArgumentException("Weights in valueUtils must all be in [0,1]");
     53                                .anyMatch(v -> v == null || v.compareTo(BigDecimal.ZERO) < 0
     54                                                || v.compareTo(BigDecimal.ONE) > 0)) {
     55                        throw new IllegalArgumentException(
     56                                        "Weights in valueUtils must all be in [0,1]");
    5457                }
    5558                this.valueUtilities.putAll(valueUtils);
     
    6871        public String isFitting(ValueSet valueset) {
    6972                if (!(valueset instanceof DiscreteValueSet)) {
    70                         return "The utilities are for a discrete valueset but the given values are " + valueset;
     73                        return "The utilities are for a discrete valueset but the given values are "
     74                                        + valueset;
    7175                }
    7276                DiscreteValueSet discvalueset = (DiscreteValueSet) valueset;
    73                 if (!valueUtilities.keySet().equals(new HashSet<>(discvalueset.getValues())))
    74                         return "The values in the set " + valueset + " do not match the values mapped to utilities "
     77                if (!valueUtilities.keySet()
     78                                .equals(new HashSet<>(discvalueset.getValues())))
     79                        return "The values in the set " + valueset
     80                                        + " do not match the values mapped to utilities "
    7581                                        + valueUtilities.keySet();
    7682                return null;
     
    7985        @Override
    8086        public String toString() {
    81                 return "ValueSetUtilities" + valueUtilities;
     87                return "DiscreteValueSetUtilities" + valueUtilities;
    8288        }
    8389
     
    8692                final int prime = 31;
    8793                int result = 1;
    88                 result = prime * result + ((valueUtilities == null) ? 0 : valueUtilities.hashCode());
     94                result = prime * result
     95                                + ((valueUtilities == null) ? 0 : valueUtilities.hashCode());
    8996                return result;
    9097        }
  • profile/src/main/java/geniusweb/profile/utilityspace/NumberValueSetUtilities.java

    r4 r9  
    139139        @Override
    140140        public String toString() {
    141                 return "NumberValUtility(" + lowValue + "->" + lowUtility + ","
     141                return "NumberValueSetUtilities(" + lowValue + "->" + lowUtility + ","
    142142                                + highValue + "->" + highUtility + ")";
    143143        }
  • profile/src/test/java/geniusweb/profile/utilityspace/DiscreteValueSetUtilitiesTest.java

    r7 r9  
    33import static org.junit.Assert.assertEquals;
    44import static org.junit.Assert.assertFalse;
     5import static org.junit.Assert.assertTrue;
    56
    67import java.io.IOException;
     
    8182        @Override
    8283        public List<String> getGeneralTestStrings() {
    83                 return Arrays.asList("ValueSetUtilities\\{\"a\"=0.14\\}",
    84                                 "ValueSetUtilities\\{\"b\"=0.37\\}",
    85                                 "ValueSetUtilities\\{\"a\"=0.37\\}",
    86                                 "ValueSetUtilities\\{\"a\"=0.14, \"b\"=0.37\\}");
     84                return Arrays.asList("DiscreteValueSetUtilities\\{\"a\"=0.14\\}",
     85                                "DiscreteValueSetUtilities\\{\"b\"=0.37\\}",
     86                                "DiscreteValueSetUtilities\\{\"a\"=0.37\\}",
     87                                "DiscreteValueSetUtilities\\{\"a\"=0.14, \"b\"=0.37\\}");
    8788        }
    8889
     
    200201
    201202        }
     203
     204        @Test
     205        public void testDeserializeAsDiscrete()
     206                        throws JsonParseException, JsonMappingException, IOException {
     207                // Check that DiscreteValueSetUtilities properly deserializes
     208                // discreteutils.
     209                String utilstring = "{\"discreteutils\": {\"valueUtilities\": {\"Party Tent\": 0.52,\"Your Dorm\": 0.23,\"Party Room\": 0.99,\"Ballroom\": 0.77}}}";
     210                DiscreteValueSetUtilities valueutils = jackson.readValue(utilstring,
     211                                DiscreteValueSetUtilities.class);
     212                assertTrue(new BigDecimal("0.23").compareTo(
     213                                valueutils.getUtility(new DiscreteValue("Your Dorm"))) == 0);
     214
     215        }
     216
    202217}
  • profile/src/test/java/geniusweb/profile/utilityspace/LinearAdditiveTest.java

    r7 r9  
    2020
    2121import com.fasterxml.jackson.databind.ObjectMapper;
    22 import com.fasterxml.jackson.databind.exc.InvalidDefinitionException;
    2322
    2423import geniusweb.issuevalue.Bid;
     
    145144        public List<String> getGeneralTestStrings() {
    146145                return Arrays.asList(
    147                                 "LinearAdditive\\[\\{issue2=ValueSetUtilities\\{\"issue2value2\"=0.8, \"issue2value1\"=0.6\\}, issue1=ValueSetUtilities\\{\"issue1value1\"=0.3, \"issue1value2\"=0.2\\}\\},\\{issue2=0.6, issue1=0.4\\},Bid\\{issue2=\"issue2value1\", issue1=\"issue1value2\"\\}\\]",
    148                                 "LinearAdditive\\[\\{issue2=ValueSetUtilities\\{\"issue2value2\"=0.8, \"issue2value1\"=0.6\\}, issue1=ValueSetUtilities\\{\"issue1value1\"=0.3, \"issue1value2\"=0.2\\}\\},\\{issue2=0.7, issue1=0.3\\},Bid\\{issue2=\"issue2value1\", issue1=\"issue1value2\"\\}\\]",
    149                                 "LinearAdditive\\[\\{issue2=ValueSetUtilities\\{\"issue2value2\"=0.2, \"issue2value1\"=0.3\\}, issue1=ValueSetUtilities\\{\"issue1value1\"=0.6, \"issue1value2\"=0.8\\}\\},\\{issue2=0.6, issue1=0.4\\},Bid\\{issue2=\"issue2value1\", issue1=\"issue1value2\"\\}\\]",
    150                                 "LinearAdditive\\[\\{issue2=ValueSetUtilities\\{\"issue2value2\"=0.2, \"issue2value1\"=0.3\\}, issue1=ValueSetUtilities\\{\"issue1value1\"=0.6, \"issue1value2\"=0.8\\}\\},\\{issue2=0.6, issue1=0.4\\},Bid\\{issue2=\"issue2value1\", issue1=\"issue1value1\"\\}\\]");
     146                                "LinearAdditive\\[\\{issue2=DiscreteValueSetUtilities\\{\"issue2value2\"=0.8, \"issue2value1\"=0.6\\}, issue1=DiscreteValueSetUtilities\\{\"issue1value1\"=0.3, \"issue1value2\"=0.2\\}\\},\\{issue2=0.6, issue1=0.4\\},Bid\\{issue2=\"issue2value1\", issue1=\"issue1value2\"\\}\\]",
     147                                "LinearAdditive\\[\\{issue2=DiscreteValueSetUtilities\\{\"issue2value2\"=0.8, \"issue2value1\"=0.6\\}, issue1=DiscreteValueSetUtilities\\{\"issue1value1\"=0.3, \"issue1value2\"=0.2\\}\\},\\{issue2=0.7, issue1=0.3\\},Bid\\{issue2=\"issue2value1\", issue1=\"issue1value2\"\\}\\]",
     148                                "LinearAdditive\\[\\{issue2=DiscreteValueSetUtilities\\{\"issue2value2\"=0.2, \"issue2value1\"=0.3\\}, issue1=DiscreteValueSetUtilities\\{\"issue1value1\"=0.6, \"issue1value2\"=0.8\\}\\},\\{issue2=0.6, issue1=0.4\\},Bid\\{issue2=\"issue2value1\", issue1=\"issue1value2\"\\}\\]",
     149                                "LinearAdditive\\[\\{issue2=DiscreteValueSetUtilities\\{\"issue2value2\"=0.2, \"issue2value1\"=0.3\\}, issue1=DiscreteValueSetUtilities\\{\"issue1value1\"=0.6, \"issue1value2\"=0.8\\}\\},\\{issue2=0.6, issue1=0.4\\},Bid\\{issue2=\"issue2value1\", issue1=\"issue1value1\"\\}\\]");
    151150        }
    152151
     
    271270        }
    272271
    273         @Test(expected = InvalidDefinitionException.class)
     272        @Test
    274273        public void loadFullWithJson() throws IOException {
    275274                String profile = new String(
  • profile/src/test/java/geniusweb/profile/utilityspace/NumberValueSetUtilTest.java

    r3 r9  
    4444        @Override
    4545        public List<String> getGeneralTestStrings() {
    46                 return Arrays.asList("NumberValUtility\\(12.5->0.5,18.5->0.9\\)",
    47                                 "NumberValUtility\\(12.5->0.6,18.5->0.9\\)",
    48                                 "NumberValUtility\\(12.5->0.5,18.4->0.9\\)");
     46                return Arrays.asList("NumberValueSetUtilities\\(12.5->0.5,18.5->0.9\\)",
     47                                "NumberValueSetUtilities\\(12.5->0.6,18.5->0.9\\)",
     48                                "NumberValueSetUtilities\\(12.5->0.5,18.4->0.9\\)");
    4949        }
    5050
  • profile/src/test/resources/party1.json

    r7 r9  
    9292                                "Location": {
    9393                                        "values": [
    94                                                 "Party Tent'",
     94                                                "Party Tent",
    9595                                                "Your Dorm",
    9696                                                "Party Room",
Note: See TracChangeset for help on using the changeset viewer.