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:
exampleparties/timedependentparty/src/main/java/geniusweb/exampleparties/timedependentparty
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • 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                }
Note: See TracChangeset for help on using the changeset viewer.