source: src/main/java/bargainingchips/utilityfunctions/UF_75pQtyOrNothing.java@ 315

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

package restructure

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