source: src/main/java/bargainingchips/utilityfunctions/UF_prcntQTYandprcntPrice.java@ 316

Last change on this file since 316 was 316, checked in by Tim Baarslag, 5 years ago

new packages complete

File size: 2.2 KB
Line 
1package bargainingchips.utilityfunctions;
2
3import bargainingchips.Bundle;
4import bargainingchips.Stack;
5
6
7/**
8 * If p1 percent of the stacks regarding quantity and p2 percent of total price of the bundle be satisfied
9 * compared to the total price of the wishlist,
10 * bundle b would be evaluated as 1.0, otherwise as 0.0.
11 *
12 * @author Faria Nassiri-Mofakham
13 *
14 */
15public class UF_prcntQTYandprcntPrice implements UtilityFunction {
16
17 Bundle wishlist;
18
19 double p1;
20 double p2;
21
22 public UF_prcntQTYandprcntPrice(Bundle w, double p1, double p2)
23 {
24 this.wishlist=w;
25 this.p1=p1; // tolerable percentage for extra price
26 this.p2=p2; // tolerable percentage for extra stacks and/or stacks with less quantities
27 }
28
29 /**
30 * @return the wishlist
31 */
32 public Bundle getWishlist() {
33 return wishlist;
34 }
35
36 /**
37 * @param wishlist the wishlist to set
38 */
39 public void setWishlist(Bundle w) {
40 this.wishlist = w;
41 }
42
43 @Override
44 public Double getUtility(Bundle b)
45 {
46 // TODO Auto-generated method stub
47 int num=wishlist.size();
48
49 if (b!=null)
50 {
51 for (Stack s : b)
52 for (Stack t: wishlist)
53 if (s.hasSameColorAs(t) && s.getQuantity() >= t.getQuantity())
54 // if the quantity is less than what is required, so this stack could not be satisfied
55 num--;
56 if (b.getTotalPrice() <= p2* wishlist.getTotalPrice()+wishlist.getTotalPrice() && num < (double)wishlist.size()*(1-p1) )
57 // i.e., the number of `dissatisfied' stacks are less than p1 percent of the stacks regarding the quantity
58 // and, the bundle total price is less that or equal to p2 percent of the wishlist total price
59 return 1.0;
60 else
61 return 0.0;
62 }
63 return 0.0;
64 }
65
66
67 /**
68 * @return the p1
69 */
70 public double getP1() {
71 return p1;
72 }
73
74
75 /**
76 * @param p1 the p1 to set
77 */
78 public void setP1(double p1) {
79 this.p1 = p1;
80 }
81
82
83 /**
84 * @return the p2
85 */
86 public double getP2() {
87 return p2;
88 }
89
90
91 /**
92 * @param p2 the p2 to set
93 */
94 public void setP2(double p2) {
95 this.p2 = p2;
96 }
97
98 @Override
99 public String toString()
100 {
101 return this.getClass().getSimpleName()+":qty%"+p1+":price%"+p2;
102 }
103
104}
Note: See TracBrowser for help on using the repository browser.