Changeset 10 for profile/src


Ignore:
Timestamp:
01/28/20 10:19:54 (4 years ago)
Author:
bart
Message:

Update 28 jan 2020

Location:
profile/src
Files:
1 added
5 edited

Legend:

Unmodified
Added
Removed
  • profile/src/main/java/geniusweb/profile/DefaultPartialOrdering.java

    r2 r10  
    2626 * limited anyway.
    2727 */
    28 public class DefaultPartialOrdering extends DefaultProfile implements PartialOrdering {
     28public class DefaultPartialOrdering extends DefaultProfile
     29                implements PartialOrdering {
    2930
    3031        /**
     
    4041         * @param reservationbid
    4142         * @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].
    4446         */
    4547        @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,
    4852                        @JsonProperty("better") List<List<Integer>> isbetterList) {
    4953                this(name, domain, reservationbid, makeBidMap(bids, isbetterList));
     
    5458         * @param domain         the {@link Domain} description
    5559         * @param reservationbid the reservation {@link Bid}
    56          * @param isBetterMap    a map with keys = a better bid and value=a less good
    57          *                       bid.
     60         * @param isBetterMap    a map with keys = a better bid and value=a less
     61         *                       good bid.
    5862         */
    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) {
    6065                super(name, domain, reservationbid);
    6166                this.isBetter = isBetterMap;
     
    7176        /**
    7277         *
    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
    7480         */
    7581        @JsonGetter
     
    97103                        if (isBetter.containsKey(bid)) {
    98104                                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)));
    100107                                }
    101108                        }
     
    107114        @Override
    108115        public String toString() {
    109                 return "DefaultPartialOrdering[" + getValuesString() + "," + isBetter + "]";
     116                return "DefaultPartialOrdering[" + getValuesString() + "," + isBetter
     117                                + "]";
    110118        }
    111119
    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) {
    113122                Map<Bid, Set<Bid>> betterMap = new HashMap<>();
    114123
    115124                for (List<Integer> tuple : isBetterList) {
    116125                        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);
    118128                        }
    119129                        Bid betterbid = bids.get(tuple.get(0));
     
    133143                final int prime = 31;
    134144                int result = super.hashCode();
    135                 result = prime * result + ((isBetter == null) ? 0 : isBetter.hashCode());
     145                result = prime * result
     146                                + ((isBetter == null) ? 0 : isBetter.hashCode());
    136147                return result;
    137148        }
  • profile/src/main/java/geniusweb/profile/utilityspace/DiscreteValueSetUtilities.java

    r9 r10  
    22
    33import java.math.BigDecimal;
     4import java.util.Collections;
    45import java.util.HashMap;
    56import java.util.HashSet;
     
    6869        }
    6970
     71        /**
     72         * @return copy of the value-utility pair map.
     73         */
     74        public Map<DiscreteValue, BigDecimal> getUtilities() {
     75                return Collections.unmodifiableMap(valueUtilities);
     76        }
     77
    7078        @Override
    7179        public String isFitting(ValueSet valueset) {
  • profile/src/main/java/geniusweb/profile/utilityspace/LinearAdditiveUtilitySpace.java

    r7 r10  
    2525 */
    2626@JsonAutoDetect(fieldVisibility = Visibility.ANY, getterVisibility = Visibility.NONE, setterVisibility = Visibility.NONE, isGetterVisibility = Visibility.NONE)
    27 public class LinearAdditiveUtilitySpace implements UtilitySpace {
     27public class LinearAdditiveUtilitySpace implements LinearAdditive {
    2828
    2929        private final String name;
     
    131131        }
    132132
    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
    145134        public BigDecimal getWeight(String issue) {
    146135                return issueWeights.get(issue);
     
    220209        }
    221210
    222         /**
    223          * @return the map from issue names to valuesetutilities (un-weighted)
    224          */
     211        @Override
    225212        public Map<String, ValueSetUtilities> getUtilities() {
    226213                return Collections.unmodifiableMap(issueUtilities);
    227214        }
    228215
    229         /**
    230          *
    231          * @return the map from issue names to weights. weights sum to 1.
    232          */
     216        @Override
    233217        public Map<String, BigDecimal> getWeights() {
    234218                return Collections.unmodifiableMap(issueWeights);
    235219        }
    236220
     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
    237233}
  • profile/src/main/java/geniusweb/profile/utilityspace/SumOfGroupsUtilitySpace.java

    r9 r10  
    8484         * grouping.
    8585         *
    86          * @param las the {@link LinearAdditiveUtilitySpace} to be converted/copied.
    87          *
    88          */
    89         public SumOfGroupsUtilitySpace(LinearAdditiveUtilitySpace las) {
     86         * @param las the {@link LinearAdditive} to be converted/copied.
     87         *
     88         */
     89        public SumOfGroupsUtilitySpace(LinearAdditive las) {
    9090                this(las.getDomain(), las.getName(), las2parts(las),
    9191                                las.getReservationBid());
     
    212212        /**
    213213         *
    214          * @param las a {@link LinearAdditiveUtilitySpace}
     214         * @param las a {@link LinearAdditive}
    215215         * @return a Map with partname-PartsUtilities. The partnames are identical
    216216         *         to the issues in the given las.
    217217         */
    218218        private static HashMap<String, PartsUtilities> las2parts(
    219                         LinearAdditiveUtilitySpace las) {
     219                        LinearAdditive las) {
    220220
    221221                HashMap<String, PartsUtilities> map = new HashMap<>();
  • profile/src/test/java/geniusweb/profile/utilityspace/NumberValueSetUtilTest.java

    r9 r10  
    33import static org.junit.Assert.assertEquals;
    44
     5import java.io.IOException;
    56import java.math.BigDecimal;
    67import java.util.Arrays;
     
    89
    910import org.junit.Test;
     11
     12import com.fasterxml.jackson.core.JsonParseException;
     13import com.fasterxml.jackson.core.JsonProcessingException;
     14import com.fasterxml.jackson.databind.JsonMappingException;
     15import com.fasterxml.jackson.databind.ObjectMapper;
    1016
    1117import geniusweb.issuevalue.DiscreteValue;
     
    3541                        lowval1, low1util, highvalb, highutil);
    3642        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();
    3746
    3847        @Override
     
    173182        }
    174183
     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
    175201}
Note: See TracChangeset for help on using the changeset viewer.