Changeset 53 for exampleparties/timedependentparty/src/main
- Timestamp:
- 12/18/24 13:28:59 (5 days ago)
- 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 9 9 import geniusweb.bidspace.Interval; 10 10 import geniusweb.bidspace.IssueInfo; 11 import geniusweb.bidspace.SumOfGroupsLinAdditiveAdapter; 11 12 import geniusweb.issuevalue.Bid; 12 13 import geniusweb.issuevalue.Value; 13 14 import geniusweb.profile.utilityspace.LinearAdditive; 15 import geniusweb.profile.utilityspace.SumOfGroupsUtilitySpace; 16 import geniusweb.profile.utilityspace.UtilitySpace; 14 17 import tudelft.utilities.immutablelist.ImmutableList; 18 import tudelft.utilities.immutablelist.MapList; 15 19 16 20 /** 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. 19 27 * 20 28 */ 21 29 public 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; 23 37 /** 24 38 * The tolerance for a utility. Generally utilities can be this amount … … 26 40 */ 27 41 private BigDecimal tolerance; 28 private BidsWithUtility bidutils;29 42 // min and max achievable utility 30 43 private BigDecimal minUtil; 31 44 private BigDecimal maxUtil; 32 45 33 public ExtendedUtilSpace( LinearAdditive space) {46 public ExtendedUtilSpace(UtilitySpace space) { 34 47 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); 36 54 computeMinMax(); 37 55 this.tolerance = computeTolerance(); 38 39 56 } 40 57 … … 52 69 this.maxUtil = range.getMax(); 53 70 54 Bid rvbid = utilspace.getReservationBid();71 Bid rvbid = linapprox.getReservationBid(); 55 72 if (rvbid != null) { 56 BigDecimal rv = utilspace.getUtility(rvbid);73 BigDecimal rv = linapprox.getUtility(rvbid); 57 74 if (rv.compareTo(minUtil) > 0) 58 75 minUtil = rv; … … 65 82 * best and one-but-best utility. 66 83 * 67 * @return the minimum tolerance required , which is the minimum difference68 * between the weighted utility of the best and one-but-best issue69 * 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. 70 87 */ 71 88 protected BigDecimal computeTolerance() { … … 87 104 } 88 105 106 /** 107 * @return the minimum utility in the {@link #linapprox} space 108 */ 89 109 public BigDecimal getMin() { 90 110 return minUtil; 91 111 } 92 112 113 /** 114 * @return the maximum utility in the {@link #linapprox} space 115 */ 93 116 public BigDecimal getMax() { 94 117 return maxUtil; … … 96 119 97 120 /** 98 * @param utilityGoal the requested utility 121 * @param utilityGoal the requested utility in the {@link #linapprox} space 99 122 * @return bids with utility inside [utilitygoal-{@link #tolerance}, 100 * utilitygoal] 123 * utilitygoal], converted back to bids in the utilspace 101 124 */ 102 125 public ImmutableList<Bid> getBids(BigDecimal utilityGoal) { 103 returnbidutils.getBids(126 ImmutableList<Bid> bidslist = bidutils.getBids( 104 127 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; 105 139 } 106 140 -
exampleparties/timedependentparty/src/main/java/geniusweb/exampleparties/timedependentparty/TimeDependentParty.java
r52 r53 74 74 * </table> 75 75 * <p> 76 * TimeDependentParty requires a {@link UtilitySpace}76 * TimeDependentParty requires a {@link LinearAdditive} utilityspace. 77 77 */ 78 78 public class TimeDependentParty extends DefaultParty { 79 79 80 80 private ProfileInterface profileint = null; 81 private LinearAdditive utilspace = null; // last received space81 private UtilitySpace utilspace = null; // last received space 82 82 private PartyId me; 83 83 private Progress progress; … … 238 238 } 239 239 240 private LinearAdditive updateUtilSpace() throws IOException {240 private UtilitySpace updateUtilSpace() throws IOException { 241 241 Profile newutilspace = profileint.getProfile(); 242 242 if (!newutilspace.equals(utilspace)) { 243 utilspace = ( LinearAdditive) newutilspace;243 utilspace = (UtilitySpace) newutilspace; 244 244 extendedspace = new ExtendedUtilSpace(utilspace); 245 245 }
Note:
See TracChangeset
for help on using the changeset viewer.