Rev | Line | |
---|
[316] | 1 | package bargainingchips.utilityfunctions;
|
---|
[315] | 2 |
|
---|
[316] | 3 | import bargainingchips.Bundle;
|
---|
| 4 | import bargainingchips.Stack;
|
---|
[315] | 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 | */
|
---|
| 16 | public 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.