Changeset 53 for exampleparties/timedependentparty/src
- Timestamp:
- 12/18/24 13:28:59 (4 days ago)
- Location:
- exampleparties/timedependentparty/src
- Files:
-
- 2 added
- 3 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 } -
exampleparties/timedependentparty/src/test/java/geniusweb/exampleparties/timedependentparty/ExtendedUtilSpaceTest.java
r52 r53 1 1 package geniusweb.exampleparties.timedependentparty; 2 2 3 import static org.junit.Assert.assert True;3 import static org.junit.Assert.assertEquals; 4 4 5 5 import java.io.IOException; 6 import java.math.BigDecimal;7 6 import java.nio.file.Files; 8 7 import java.nio.file.Paths; … … 19 18 20 19 import geniusweb.profile.Profile; 21 import geniusweb.profile.utilityspace. LinearAdditiveUtilitySpace;20 import geniusweb.profile.utilityspace.UtilitySpace; 22 21 23 22 @RunWith(Parameterized.class) 24 23 public class ExtendedUtilSpaceTest { 25 24 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; 27 26 28 27 @Parameters … … 31 30 { "src/test/resources/jobs/jobs1.json", 0.02 }, 32 31 { "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 } }); 34 36 } 35 37 36 38 private String filename; 37 private BigDecimalexpectedTolerance;39 private double expectedTolerance; 38 40 private ExtendedUtilSpace space; 39 41 40 42 public ExtendedUtilSpaceTest(String filename, double expectedTolerance) { 41 43 this.filename = filename; 42 this.expectedTolerance = BigDecimal.valueOf(expectedTolerance);44 this.expectedTolerance = expectedTolerance; 43 45 } 44 46 … … 46 48 public void before() throws IOException { 47 49 String file = new String(Files.readAllBytes(Paths.get(filename))); 48 LinearAdditiveUtilitySpace profile = (LinearAdditiveUtilitySpace) jackson49 .readValue(file,Profile.class);50 UtilitySpace profile = (UtilitySpace) jackson.readValue(file, 51 Profile.class); 50 52 space = new ExtendedUtilSpace(profile); 51 53 } … … 58 60 @Test 59 61 public void testTolerance() { 60 assert True(space.computeTolerance().subtract(expectedTolerance).abs()61 .compareTo(SMALL) < 0);62 assertEquals(expectedTolerance, space.computeTolerance().doubleValue(), 63 SMALL); 62 64 } 63 65 }
Note:
See TracChangeset
for help on using the changeset viewer.