source: src/main/java/onetomany/bargainingchipsgame/players/utilityfunction/UF_FreeDisposal.java@ 254

Last change on this file since 254 was 253, checked in by Faria Nassiri Mofakham, 5 years ago

Commit #1 of:
+ negotiator.onetomany package refactored into onetomany package.
+ info created for all contained the packages.
+ current work defined under onetomany.bargainingchipsgame.
+ in this package, onetomany.bargainingchipsgame.players package includes packages for utility function, coordinator, negotiatior, and buyer and seller.
+ negotiator.onetomany package now contains nothing, can be deleted.
+ Interaction thread

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