source: src/main/java/bargainingchips/utilityfunctions/UF_FreeDisposal.java@ 340

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

new packages complete

File size: 1.6 KB
Line 
1package bargainingchips.utilityfunctions;
2
3import bargainingchips.Bundle;
4import bargainingchips.Stack;
5
6/**
7 * While the total price of the bundle b is less than that of the wishlist,
8 * it evaluates the bundle as 1.0 if quantity of all stacks in b is equal or more than
9 * that of the stack of the same color in wishlist; since
10 * under free disposal it doesn't cost to receive extra quantities.
11 * If any less quantity or extra total price, it evaluates bundle b as 0.0.
12 *
13 * @author Faria Nassiri-Mofakham
14 *
15 */
16public class UF_FreeDisposal implements UtilityFunction {
17
18 Bundle wishlist;
19
20 public UF_FreeDisposal(Bundle w)
21 {
22 this.wishlist=w;
23 }
24
25 /**
26 * @return the wishlist
27 */
28 public Bundle getWishlist()
29 {
30 return wishlist;
31 }
32
33 /**
34 * @param wishlist the wishlist to set
35 */
36 public void setWishlist(Bundle w)
37 {
38 this.wishlist = w;
39 }
40
41 @Override
42 public Double getUtility(Bundle b)
43 {
44 // TODO Auto-generated method stub
45 int num=0;
46 if (b!=null)
47 {
48 for (Stack s : b)
49 {
50 for (Stack t: wishlist)
51 if (s.getColor()==t.getColor() && s.getQuantity() != t.getQuantity())
52 if (s.getQuantity() < t.getQuantity()) //bundle b doesn't have any stacks with extra quantities
53 return 0.0;
54 num++; //bundle b has extra stacks
55 }
56 if (b.size() >= wishlist.size() && num >= 0 && b.getTotalPrice() <= wishlist.getTotalPrice())
57 return 1.0;
58 else
59 return 0.0;
60 }
61 return 0.0;
62 }
63
64 @Override
65 public String toString()
66 {
67 return this.getClass().getSimpleName();
68 }
69
70}
71
72
Note: See TracBrowser for help on using the repository browser.