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

Location:
exampleparties/timedependentparty
Files:
2 added
4 edited

Legend:

Unmodified
Added
Removed
  • exampleparties/timedependentparty/pom.xml

    r52 r53  
    66        <groupId>geniusweb.exampleparties</groupId>
    77        <artifactId>timedependentparty</artifactId>
    8         <version>2.1.6</version>  <!-- equals the geniusweb version -->
     8        <version>2.2.1</version>  <!-- equals the geniusweb version -->
    99        <packaging>jar</packaging>
    1010
     
    5353                        <groupId>tudelft.utilities</groupId>
    5454                        <artifactId>utilities</artifactId>
    55                         <version>1.2.1</version>
     55                        <version>1.3.1</version>
    5656                </dependency>
    5757
  • exampleparties/timedependentparty/src/main/java/geniusweb/exampleparties/timedependentparty/ExtendedUtilSpace.java

    r52 r53  
    99import geniusweb.bidspace.Interval;
    1010import geniusweb.bidspace.IssueInfo;
     11import geniusweb.bidspace.SumOfGroupsLinAdditiveAdapter;
    1112import geniusweb.issuevalue.Bid;
    1213import geniusweb.issuevalue.Value;
    1314import geniusweb.profile.utilityspace.LinearAdditive;
     15import geniusweb.profile.utilityspace.SumOfGroupsUtilitySpace;
     16import geniusweb.profile.utilityspace.UtilitySpace;
    1417import tudelft.utilities.immutablelist.ImmutableList;
     18import tudelft.utilities.immutablelist.MapList;
    1519
    1620/**
    17  * Inner class for TimeDependentParty, made public for testing purposes. This
    18  * class may change in the future, use at your own risk.
     21 * Inner class for TimeDependentParty, Handles mechanisms for searching the bid
     22 * space, and using adapters to handle the nonlinear
     23 * {@link SumOfGroupsUtilitySpace}.
     24 *
     25 * This class is public for testing purposes. This class may change in the
     26 * future, use at your own risk.
    1927 *
    2028 */
    2129public class ExtendedUtilSpace {
    22         private LinearAdditive utilspace;
     30        private UtilitySpace utilspace;
     31        // linear approximation of utilspace (possibly utilspace itself)
     32        // thsi may have different utilityes issues and values than utilspace.
     33        private LinearAdditive linapprox;
     34
     35        // bidutils tolerance minUtil maxUtil all work on linapprox
     36        private BidsWithUtility bidutils;
    2337        /**
    2438         * The tolerance for a utility. Generally utilities can be this amount
     
    2640         */
    2741        private BigDecimal tolerance;
    28         private BidsWithUtility bidutils;
    2942        // min and max achievable utility
    3043        private BigDecimal minUtil;
    3144        private BigDecimal maxUtil;
    3245
    33         public ExtendedUtilSpace(LinearAdditive space) {
     46        public ExtendedUtilSpace(UtilitySpace space) {
    3447                this.utilspace = space;
    35                 bidutils = new BidsWithUtility(utilspace);
     48                if (space instanceof LinearAdditive)
     49                        linapprox = (LinearAdditive) space;
     50                else
     51                        linapprox = SumOfGroupsLinAdditiveAdapter
     52                                        .create((SumOfGroupsUtilitySpace) space);
     53                bidutils = new BidsWithUtility(linapprox);
    3654                computeMinMax();
    3755                this.tolerance = computeTolerance();
    38 
    3956        }
    4057
     
    5269                this.maxUtil = range.getMax();
    5370
    54                 Bid rvbid = utilspace.getReservationBid();
     71                Bid rvbid = linapprox.getReservationBid();
    5572                if (rvbid != null) {
    56                         BigDecimal rv = utilspace.getUtility(rvbid);
     73                        BigDecimal rv = linapprox.getUtility(rvbid);
    5774                        if (rv.compareTo(minUtil) > 0)
    5875                                minUtil = rv;
     
    6582         * best and one-but-best utility.
    6683         *
    67          * @return the minimum tolerance required, which is the minimum difference
    68          *         between the weighted utility of the best and one-but-best issue
    69          *         value.
     84         * @return the minimum tolerance required in the {@link #linapprox} space,
     85         *         which is the minimum difference between the weighted utility of
     86         *         the best and one-but-best issue value.
    7087         */
    7188        protected BigDecimal computeTolerance() {
     
    87104        }
    88105
     106        /**
     107         * @return the minimum utility in the {@link #linapprox} space
     108         */
    89109        public BigDecimal getMin() {
    90110                return minUtil;
    91111        }
    92112
     113        /**
     114         * @return the maximum utility in the {@link #linapprox} space
     115         */
    93116        public BigDecimal getMax() {
    94117                return maxUtil;
     
    96119
    97120        /**
    98          * @param utilityGoal the requested utility
     121         * @param utilityGoal the requested utility in the {@link #linapprox} space
    99122         * @return bids with utility inside [utilitygoal-{@link #tolerance},
    100          *         utilitygoal]
     123         *         utilitygoal], converted back to bids in the utilspace
    101124         */
    102125        public ImmutableList<Bid> getBids(BigDecimal utilityGoal) {
    103                 return bidutils.getBids(
     126                ImmutableList<Bid> bidslist = bidutils.getBids(
    104127                                new Interval(utilityGoal.subtract(tolerance), utilityGoal));
     128                return new MapList<>((Bid b) -> realBid(b), bidslist);
     129        }
     130
     131        /**
     132         * @param b a bid in the linapprox space
     133         * @return a bid in the original space
     134         */
     135        private Bid realBid(Bid b) {
     136                if (linapprox instanceof SumOfGroupsLinAdditiveAdapter)
     137                        return ((SumOfGroupsLinAdditiveAdapter) linapprox).toGroupBid(b);
     138                return b;
    105139        }
    106140
  • exampleparties/timedependentparty/src/main/java/geniusweb/exampleparties/timedependentparty/TimeDependentParty.java

    r52 r53  
    7474 * </table>
    7575 * <p>
    76  * TimeDependentParty requires a {@link UtilitySpace}
     76 * TimeDependentParty requires a {@link LinearAdditive} utilityspace.
    7777 */
    7878public class TimeDependentParty extends DefaultParty {
    7979
    8080        private ProfileInterface profileint = null;
    81         private LinearAdditive utilspace = null; // last received space
     81        private UtilitySpace utilspace = null; // last received space
    8282        private PartyId me;
    8383        private Progress progress;
     
    238238        }
    239239
    240         private LinearAdditive updateUtilSpace() throws IOException {
     240        private UtilitySpace updateUtilSpace() throws IOException {
    241241                Profile newutilspace = profileint.getProfile();
    242242                if (!newutilspace.equals(utilspace)) {
    243                         utilspace = (LinearAdditive) newutilspace;
     243                        utilspace = (UtilitySpace) newutilspace;
    244244                        extendedspace = new ExtendedUtilSpace(utilspace);
    245245                }
  • exampleparties/timedependentparty/src/test/java/geniusweb/exampleparties/timedependentparty/ExtendedUtilSpaceTest.java

    r52 r53  
    11package geniusweb.exampleparties.timedependentparty;
    22
    3 import static org.junit.Assert.assertTrue;
     3import static org.junit.Assert.assertEquals;
    44
    55import java.io.IOException;
    6 import java.math.BigDecimal;
    76import java.nio.file.Files;
    87import java.nio.file.Paths;
     
    1918
    2019import geniusweb.profile.Profile;
    21 import geniusweb.profile.utilityspace.LinearAdditiveUtilitySpace;
     20import geniusweb.profile.utilityspace.UtilitySpace;
    2221
    2322@RunWith(Parameterized.class)
    2423public class ExtendedUtilSpaceTest {
    2524        private final static ObjectMapper jackson = new ObjectMapper();
    26         private final static BigDecimal SMALL = new BigDecimal("0.0001");
     25        private final static double SMALL = 0.0001;
    2726
    2827        @Parameters
     
    3130                                { "src/test/resources/jobs/jobs1.json", 0.02 },
    3231                                { "src/test/resources/7issues/7issues1.json", 0.0055 },
    33                                 { "src/test/resources/9issues/9issues1.json", 0.0013 } });
     32                                { "src/test/resources/9issues/9issues1.json", 0.0013 },
     33                                // tolerance in computerbuy is quite small because approximation
     34                                // scales the space
     35                                { "src/test/resources/computer/computerbuy.json", 0.0016 } });
    3436        }
    3537
    3638        private String filename;
    37         private BigDecimal expectedTolerance;
     39        private double expectedTolerance;
    3840        private ExtendedUtilSpace space;
    3941
    4042        public ExtendedUtilSpaceTest(String filename, double expectedTolerance) {
    4143                this.filename = filename;
    42                 this.expectedTolerance = BigDecimal.valueOf(expectedTolerance);
     44                this.expectedTolerance = expectedTolerance;
    4345        }
    4446
     
    4648        public void before() throws IOException {
    4749                String file = new String(Files.readAllBytes(Paths.get(filename)));
    48                 LinearAdditiveUtilitySpace profile = (LinearAdditiveUtilitySpace) jackson
    49                                 .readValue(file, Profile.class);
     50                UtilitySpace profile = (UtilitySpace) jackson.readValue(file,
     51                                Profile.class);
    5052                space = new ExtendedUtilSpace(profile);
    5153        }
     
    5860        @Test
    5961        public void testTolerance() {
    60                 assertTrue(space.computeTolerance().subtract(expectedTolerance).abs()
    61                                 .compareTo(SMALL) < 0);
     62                assertEquals(expectedTolerance, space.computeTolerance().doubleValue(),
     63                                SMALL);
    6264        }
    6365}
Note: See TracChangeset for help on using the changeset viewer.