source: src/main/java/negotiator/onetomany/players/UF_FreeDisposal.java@ 244

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

Agent class. Utility_Function interface defined. 8 sample utility functions created and all tested. Now, Bundle has getPrice() and Stack has getColor(). Still, aggregation in Bundle class is without iterators (iterators could not work out yet).

File size: 1.6 KB
Line 
1/**
2 * UtilityFunctionFreeDisposal class
3 */
4package negotiator.onetomany.players;
5
6import negotiator.onetomany.domain.Bundle;
7import negotiator.onetomany.domain.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.