1 | package bargainingchips.utilityfunctions;
|
---|
2 |
|
---|
3 | import bargainingchips.Bundle;
|
---|
4 | import bargainingchips.Stack;
|
---|
5 |
|
---|
6 | /**
|
---|
7 | * If 75 percent of the stacks be satisfied regarding the quantity as long as
|
---|
8 | * the total price would be less than the total price of the wishlist,
|
---|
9 | * bundle b would be evaluated as 1.0, otherwise as 0.0.
|
---|
10 | *
|
---|
11 | * @author Faria Nassiri-Mofakham
|
---|
12 | *
|
---|
13 | */
|
---|
14 | public class UF_75pQtyOrNothing implements UtilityFunction {
|
---|
15 |
|
---|
16 | Bundle wishlist;
|
---|
17 | String role;
|
---|
18 |
|
---|
19 |
|
---|
20 | /**
|
---|
21 | * @return the role
|
---|
22 | */
|
---|
23 | public String getRole() {
|
---|
24 | return role;
|
---|
25 | }
|
---|
26 |
|
---|
27 | /**
|
---|
28 | * @param role the role to set
|
---|
29 | */
|
---|
30 | public void setRole(String role) {
|
---|
31 | this.role = role;
|
---|
32 | }
|
---|
33 |
|
---|
34 | public UF_75pQtyOrNothing(Bundle w)
|
---|
35 | {
|
---|
36 | this.wishlist=w;
|
---|
37 | }
|
---|
38 |
|
---|
39 | /**
|
---|
40 | * @return the wishlist
|
---|
41 | */
|
---|
42 | public Bundle getWishlist() {
|
---|
43 | return wishlist;
|
---|
44 | }
|
---|
45 |
|
---|
46 | /**
|
---|
47 | * @param wishlist the wishlist to set
|
---|
48 | */
|
---|
49 | public void setWishlist(Bundle w) {
|
---|
50 | this.wishlist = w;
|
---|
51 | }
|
---|
52 |
|
---|
53 | @Override
|
---|
54 | public Double getUtility(Bundle b)
|
---|
55 | {
|
---|
56 | // TODO Auto-generated method stub
|
---|
57 | int num=wishlist.size();
|
---|
58 | if (b!=null)
|
---|
59 | {
|
---|
60 | for (Stack s : b)
|
---|
61 | for (Stack t: wishlist)
|
---|
62 | if (s.getColor()==t.getColor() && s.getQuantity() >= t.getQuantity())
|
---|
63 | // if bundle b has any additional stack
|
---|
64 | // if the quantity is less than what is required, so this stack could not be satisfied
|
---|
65 | num--;
|
---|
66 | if (b.getTotalPrice() <= wishlist.getTotalPrice() && num < (double)wishlist.size()*0.25) // i.e. less than 25 percent of the stacks could not be satisfied
|
---|
67 | if (isBuyer(role))
|
---|
68 | return 1.0;
|
---|
69 | else
|
---|
70 | return 0.0;
|
---|
71 | else
|
---|
72 | if (isBuyer(role))
|
---|
73 | return 0.0;
|
---|
74 | else
|
---|
75 | return 1.0;
|
---|
76 | }
|
---|
77 | if (isBuyer(role))
|
---|
78 | return 0.0;
|
---|
79 | else
|
---|
80 | return 1.0;
|
---|
81 | }
|
---|
82 |
|
---|
83 |
|
---|
84 | @Override
|
---|
85 | public String toString()
|
---|
86 | {
|
---|
87 | return this.getClass().getSimpleName();
|
---|
88 | }
|
---|
89 |
|
---|
90 |
|
---|
91 | public Boolean isBuyer(String role)
|
---|
92 | {
|
---|
93 | switch (role.toLowerCase())
|
---|
94 | {
|
---|
95 | case "buyer": return Boolean.TRUE;
|
---|
96 | case "seller": return Boolean.FALSE;
|
---|
97 | default:
|
---|
98 | System.out.println("Undefined role!");
|
---|
99 | return null;
|
---|
100 | }
|
---|
101 | }
|
---|
102 |
|
---|
103 | }
|
---|