Changeset 53 for profile/src/test/java


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

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

Location:
profile/src/test/java/geniusweb/profile
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • profile/src/test/java/geniusweb/profile/DefaultPartialOrderingTest.java

    r52 r53  
    2727import tudelft.utilities.junit.GeneralTests;
    2828
    29 public class DefaultPartialOrderingTest extends GeneralTests<DefaultPartialOrdering> {
     29public class DefaultPartialOrderingTest
     30                extends GeneralTests<DefaultPartialOrdering> {
    3031
    31         private final String serialized = "{\"DefaultPartialOrdering\":{" + "\"name\":\"ordering1\","
     32        private final String serialized = "{\"DefaultPartialOrdering\":{"
     33                        + "\"name\":\"ordering1\","
    3234                        + "\"domain\":{\"name\":\"dom1\",\"issuesValues\":{\"iss1\":{\"values\":[\"1\",\"2\",\"3\"]}}},"
    33                         + "\"reservationBid\":{\"issuevalues\":{\"iss1\":\"1\"}},"
    34                         + "\"bids\":[{\"issuevalues\":{\"iss1\":\"1\"}},{\"issuevalues\":{\"iss1\":\"3\"}},{\"issuevalues\":{\"iss1\":\"2\"}}],"
    35                         + "\"better\":[[0,2],[1,2]]}}";
     35                        + "\"better\":{\"{\\\"issuevalues\\\":{\\\"iss1\\\":\\\"1\\\"}}\":[{\"issuevalues\":{\"iss1\":\"2\"}}],\"{\\\"issuevalues\\\":{\\\"iss1\\\":\\\"3\\\"}}\":[{\"issuevalues\":{\"iss1\":\"2\"}}]},"
     36                        + "\"reservationbid\":{\"issuevalues\":{\"iss1\":\"1\"}}}}";
    3637
    3738        // we need real (not mock) values otherwise serializer crashes..
    3839        private String issue1 = "iss1";
    39         private DefaultPartialOrdering ordering1, ordering1b, ordering2, ordering3, ordering4, ordering5;
     40        private DefaultPartialOrdering ordering1, ordering1b, ordering2, ordering3,
     41                        ordering4, ordering5;
    4042
    4143        private Bid bid1, bid2, bid3;
     
    4749                DiscreteValue val2 = new DiscreteValue("2");
    4850                DiscreteValue val3 = new DiscreteValue("3");
    49                 issues.put(issue1, new DiscreteValueSet(new HashSet<>(Arrays.asList(val1, val2, val3))));
     51                issues.put(issue1, new DiscreteValueSet(
     52                                new HashSet<>(Arrays.asList(val1, val2, val3))));
    5053                Domain domain1 = new Domain("dom1", issues);
    5154                Domain domain2 = new Domain("dom2", issues);
     
    6265                map2.put(bid3, new HashSet<Bid>(Arrays.asList(bid1)));
    6366
    64                 ordering1 = new DefaultPartialOrdering("ordering1", domain1, bid1, map1);
    65                 ordering1b = new DefaultPartialOrdering("ordering1", domain1, bid1, map1);
    66                 ordering2 = new DefaultPartialOrdering("ordering2", domain1, bid1, map1);
    67                 ordering3 = new DefaultPartialOrdering("ordering1", domain2, bid1, map1);
    68                 ordering4 = new DefaultPartialOrdering("ordering1", domain1, bid2, map1);
    69                 ordering5 = new DefaultPartialOrdering("ordering1", domain1, bid1, map2);
     67                ordering1 = new DefaultPartialOrdering("ordering1", domain1, bid1,
     68                                map1);
     69                ordering1b = new DefaultPartialOrdering("ordering1", domain1, bid1,
     70                                map1);
     71                ordering2 = new DefaultPartialOrdering("ordering2", domain1, bid1,
     72                                map1);
     73                ordering3 = new DefaultPartialOrdering("ordering1", domain2, bid1,
     74                                map1);
     75                ordering4 = new DefaultPartialOrdering("ordering1", domain1, bid2,
     76                                map1);
     77                ordering5 = new DefaultPartialOrdering("ordering1", domain1, bid1,
     78                                map2);
    7079
    7180        }
     
    7382        @Override
    7483        public List<List<DefaultPartialOrdering>> getGeneralTestData() {
    75                 return Arrays.asList(Arrays.asList(ordering1, ordering1b), Arrays.asList(ordering2), Arrays.asList(ordering3),
     84                return Arrays.asList(Arrays.asList(ordering1, ordering1b),
     85                                Arrays.asList(ordering2), Arrays.asList(ordering3),
    7686                                Arrays.asList(ordering4), Arrays.asList(ordering5));
    7787        }
     
    7989        @Override
    8090        public List<String> getGeneralTestStrings() {
    81                 return Arrays.asList("DefaultPartialOrdering.*", "DefaultPartialOrdering.*", "DefaultPartialOrdering.*",
     91                return Arrays.asList("DefaultPartialOrdering.*",
     92                                "DefaultPartialOrdering.*", "DefaultPartialOrdering.*",
    8293                                "DefaultPartialOrdering.*", "DefaultPartialOrdering.*");
    8394        }
  • profile/src/test/java/geniusweb/profile/utilityspace/LinearAdditiveTest.java

    r52 r53  
    2222
    2323import com.fasterxml.jackson.databind.ObjectMapper;
     24import com.fasterxml.jackson.databind.exc.ValueInstantiationException;
    2425
    2526import geniusweb.issuevalue.Bid;
     
    309310        }
    310311
     312        /**
     313         * This should throw because computersell-domainmismatch has a mismatch: it
     314         * has "high 32G" as graphics option, but the utilities have no value for
     315         * that. Instead it talks about "high 24G"
     316         */
     317        @Test(expected = ValueInstantiationException.class)
     318        public void testIsFitting() throws IOException {
     319                String profile = new String(
     320                                Files.readAllBytes(Paths.get(
     321                                                "src/test/resources/computersell-domainmismatch.json")),
     322                                StandardCharsets.UTF_8);
     323                UtilitySpace space = jackson.readValue(profile, UtilitySpace.class);
     324
     325        }
     326
    311327}
  • profile/src/test/java/geniusweb/profile/utilityspace/SumOfGroupsUtilitySpaceTest.java

    r52 r53  
    2121import org.junit.Test;
    2222
     23import com.fasterxml.jackson.core.JsonParseException;
    2324import com.fasterxml.jackson.core.JsonProcessingException;
     25import com.fasterxml.jackson.databind.JsonMappingException;
    2426import com.fasterxml.jackson.databind.ObjectMapper;
     27import com.fasterxml.jackson.databind.exc.ValueInstantiationException;
    2528
    2629import geniusweb.issuevalue.Bid;
     
    3437import tudelft.utilities.immutablelist.ImmutableList;
    3538import tudelft.utilities.immutablelist.Outer;
    36 
    37 public class SumOfGroupsUtilitySpaceTest {
     39import tudelft.utilities.junit.GeneralTests;
     40
     41public class SumOfGroupsUtilitySpaceTest
     42                extends GeneralTests<SumOfGroupsUtilitySpace> {
    3843        private final ObjectMapper jackson = new ObjectMapper();
    3944        private SumOfGroupsUtilitySpace pa1;
     
    4954
    5055        private Domain domain;
    51         private PartsUtilities putils12, putils3;
     56        private PartsUtilities putils12, putils3, putils3b;
    5257        private String serialized = "{\"SumOfGroupsUtilitySpace\":{\"domain\":{\"name\":\"domain\",\"issuesValues\":{\"issue3\":{\"values\":[\"low\",\"high\"]},\"issue2\":{\"values\":[\"low\",\"high\"]},\"issue1\":{\"values\":[\"low\",\"high\"]}}},\"name\":\"testspace\",\"partUtilities\":{\"1and2\":{\"PartsUtilities\":{\"issues\":[\"issue1\",\"issue2\"],\"utilslist\":[{\"values\":[\"low\",\"low\"],\"util\":0.16},{\"values\":[\"high\",\"high\"],\"util\":0.72},{\"values\":[\"low\",\"high\"],\"util\":0.16},{\"values\":[\"high\",\"low\"],\"util\":0.16}]}},\"3\":{\"PartsUtilities\":{\"issues\":[\"issue3\"],\"utilslist\":[{\"values\":[\"low\"],\"util\":0.16},{\"values\":[\"high\"],\"util\":0.14}]}}},\"reservationbid\":{\"issuevalues\":{\"issue1\":\"high\"}}}}";
     58        private SumOfGroupsUtilitySpace sog1, sog1a, sog2, sog3;
    5359
    5460        @Before
     
    7884                putils3 = new PartsUtilities(Arrays.asList(iss3), utils3);
    7985
     86                Map<ProductOfValue, BigDecimal> utils3b = new HashMap<>();
     87                utils3b.put(new ProductOfValue(Arrays.asList(lo)), N07.multiply(N02));
     88                utils3b.put(new ProductOfValue(Arrays.asList(hi)), N08.multiply(N02));
     89                putils3b = new PartsUtilities(Arrays.asList(iss3), utils3b);
     90
     91                HashMap<String, PartsUtilities> partutils = new HashMap<>();
     92                partutils.put("1and2", putils12);
     93                partutils.put("3", putils3);
     94
     95                sog1 = new SumOfGroupsUtilitySpace(domain, "testspace", partutils,
     96                                resBid);
     97                sog1a = new SumOfGroupsUtilitySpace(domain, "testspace", partutils,
     98                                resBid);
     99                sog2 = new SumOfGroupsUtilitySpace(domain, "testspace2", partutils,
     100                                resBid);
     101
     102                // reuse partutils. Also checks that the values have been copied
     103                partutils = new HashMap<>();
     104                partutils.put("1and2", putils12);
     105                partutils.put("3", putils3b);
     106                sog3 = new SumOfGroupsUtilitySpace(domain, "testspace", partutils,
     107                                resBid);
     108
     109        }
     110
     111        @Override
     112        public List<List<SumOfGroupsUtilitySpace>> getGeneralTestData() {
     113                return Arrays.asList(Arrays.asList(sog1, sog1a), Arrays.asList(sog2),
     114                                Arrays.asList(sog3));
     115        }
     116
     117        @Override
     118        public List<String> getGeneralTestStrings() {
     119                return Arrays.asList(
     120                                "SumOfGroupsUtilitySpace.*testspace.*1and2.*PartsUtilities.*issue1.*issue2.*3.*PartsUtilities.*Bid.*issue1.*high.*",
     121                                "SumOfGroupsUtilitySpace.*testspace2.*1and2.*PartsUtilities.*issue1.*issue2.*3.*PartsUtilities.*Bid.*issue1.*high.*",
     122                                "SumOfGroupsUtilitySpace.*testspace.*1and2.*PartsUtilities.*issue1.*issue2.*3.*PartsUtilities.*Bid.*issue1.*high.*");
    80123        }
    81124
     
    161204                LinearAdditiveUtilitySpace las = jackson.readValue(profile,
    162205                                LinearAdditiveUtilitySpace.class);
    163                 SumOfGroupsUtilitySpace pas = new SumOfGroupsUtilitySpace(las);
     206                SumOfGroupsUtilitySpace pas = SumOfGroupsUtilitySpace.create(las);
    164207                checkUtilitiesAllEqual(las, pas);
    165208                System.out.println("Generated partial profile:\n" + pas);
     
    178221                LinearAdditiveUtilitySpace las = jackson.readValue(profile,
    179222                                LinearAdditiveUtilitySpace.class);
    180                 SumOfGroupsUtilitySpace pas = new SumOfGroupsUtilitySpace(las);
     223                SumOfGroupsUtilitySpace pas = SumOfGroupsUtilitySpace.create(las);
    181224                pas = pas.group(Arrays.asList("Food", "Drinks"), "food&drinks");
    182225                checkUtilitiesAllEqual(las, pas);
     
    235278        }
    236279
     280        @Test
     281        public void loadComputerBuy() throws IOException {
     282                UtilitySpace space = jackson.readValue(
     283                                getClass().getResourceAsStream("/computerbuy.json"),
     284                                UtilitySpace.class);
     285                assertTrue(space instanceof SumOfGroupsUtilitySpace);
     286
     287        }
     288
     289        @Test
     290        public void loadComputerSell() throws IOException {
     291                UtilitySpace space = jackson.readValue(
     292                                getClass().getResourceAsStream("/computersell.json"),
     293                                UtilitySpace.class);
     294                assertTrue(space instanceof LinearAdditiveUtilitySpace);
     295
     296        }
     297
     298        @Test(expected = ValueInstantiationException.class)
     299        public void loadComputerBuyIncomplete() throws IOException {
     300                UtilitySpace space = jackson.readValue(
     301                                getClass().getResourceAsStream("/computerbuyincomplete.json"),
     302                                UtilitySpace.class);
     303                assertTrue(space instanceof LinearAdditiveUtilitySpace);
     304
     305        }
     306
     307        @Test
     308        public void loadComputerBuyNumbers() throws IOException {
     309                UtilitySpace space = jackson.readValue(
     310                                getClass().getResourceAsStream("/computerbuynumbers.json"),
     311                                UtilitySpace.class);
     312                assertTrue(space instanceof SumOfGroupsUtilitySpace);
     313
     314        }
     315
     316        @Test
     317        public void testComputerBuyUtility()
     318                        throws JsonParseException, JsonMappingException, IOException {
     319                SumOfGroupsUtilitySpace space = jackson.readValue(
     320                                getClass().getResourceAsStream("/computerbuy.json"),
     321                                SumOfGroupsUtilitySpace.class);
     322                Bid bid = space.getReservationBid();
     323                assertEquals(new BigDecimal("0.625"), space.getUtility(bid));
     324        }
     325
    237326        /************************ PRIVATE FUNCTIONS *******************/
    238327
Note: See TracChangeset for help on using the changeset viewer.