source: src/main/java/bargainingchips/utilityfunctions/UF_CloseToQuantity.java@ 338

Last change on this file since 338 was 338, checked in by Faria Nassiri Mofakham, 5 years ago

An extended version of Buyer (BuyerExtended), which can be constructed using one among many utility functions. UF_LessPrice and seven complex utility functions based on price+quantity and two types of weights: UF_LessPriceCloseToQuantity, UF_IntensifiedLessPriceCloseToQuantity, UF_PeakedPricePeakedQuantity, UF_PeakedFlatPricePeakedFlatQuantity, UF_PeakedFlatCurvePriceGaussianQuantity, UF_BezierPriceBezierQuantity, and UF_BezierPriceGaussianQuantity. Two more fundamental helper classes: ChipIssueValue, ChipIssueValueBuilder. Adding a validity check to Stack. An update in Bundle main. Adding getSampleBid function to Bid. An update in k variable in Agent. A UF class and UtilityHelperMethods for individual passing utility functions. Adding some more tests in UF_CloseToQuantity main. An update on BundleTest.

File size: 1.9 KB
RevLine 
[316]1package bargainingchips.utilityfunctions;
[315]2
[316]3import bargainingchips.Bundle;
4import bargainingchips.BundleBuilder;
5import bargainingchips.Chip;
6import bargainingchips.WishList;
7import bargainingchips.WishListBuilder;
[315]8
9/**
[338]10 * Utility function for testing that acts on quantity alone.
[315]11 * Returns 1 when the wish list is exactly satisfied. Becomes lower with higher quantity deviations.
[338]12 *
13 * @author Tim Baarslag
14 *
[315]15 */
16public class UF_CloseToQuantity implements UtilityFunction
17{
18 private WishList wishlist;
19
20 public UF_CloseToQuantity(WishList w)
21 {
22 this.wishlist = w;
23 }
24
25
26 @Override
27 public Double getUtility(Bundle b)
28 {
29 int totalDeviation = 0;
30 for (Chip c : wishlist)
31 {
32 int desired = wishlist.getQuantity(c);
33 Integer offered = b.getQuantity(c);
34 if (offered == null)
35 offered = 0;
36
37 int deviationOffered = Math.abs(desired - offered);
38 totalDeviation += deviationOffered;
39 }
40
41 return 1.0 / (1 + totalDeviation);
42 }
43
44 @Override
45 public String toString()
46 {
47 return this.getClass().getSimpleName() + ": " + wishlist.toString();
48 }
49
50 public static void main(String[] args)
51 {
52 WishList wishlist = new WishListBuilder().addWish("Red", 7).addWish("Green", 5).build();
53 UF_CloseToQuantity u = new UF_CloseToQuantity(wishlist);
54 System.out.println(u);
55
56 Bundle offer = new BundleBuilder()
57 .addStack("Red", 1.0, 6)
58 .addStack("Green", 3.0, 15)
59 .addStack("Purple", 0.10, 10)
[338]60//---
61// .addStack("Green", 2.0, 3)
62// .addStack("Yellow", 5.0, 4)
63// .addStack("Orange", 1.0, 17)
64//---
65// .addStack("Green", 3.0, 4) //should give utility 1.0
66// .addStack("Yellow", 5.0, 6)
67// .addStack("Orange", 1.0, 40)
68//---
69// .addStack("Green", 10.0, 1) //should give utility 0.0
70// .addStack("Yellow", 10.0, 1)
71// .addStack("Orange", 10.0, 1)
72//---
[315]73 .build();
74 System.out.println(u.getUtility(offer));
75 }
76
77}
78
Note: See TracBrowser for help on using the repository browser.