source: src/main/java/negotiator/onetomany/players/UF_75pQtyOrNothing.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.5 KB
Line 
1/**
2 * UtilityFunction75percentQuantityOrNothing
3 */
4package negotiator.onetomany.players;
5
6import negotiator.onetomany.domain.Bundle;
7import negotiator.onetomany.domain.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 Utility_Function {
18
19 Bundle wishlist;
20
21
22 public UF_75pQtyOrNothing(Bundle w)
23 {
24 this.wishlist=w;
25 }
26
27 /**
28 * @return the wishlist
29 */
30 public Bundle getWishlist() {
31 return wishlist;
32 }
33
34 /**
35 * @param wishlist the wishlist to set
36 */
37 public void setWishlist(Bundle w) {
38 this.wishlist = w;
39 }
40
41 @Override
42 public Double getUtility(Bundle b)
43 {
44 // TODO Auto-generated method stub
45 int num=wishlist.size();
46 if (b!=null)
47 {
48 for (Stack s : b)
49 for (Stack t: wishlist)
50 if (s.getColor()==t.getColor() && s.getQuantity() >= t.getQuantity())
51 // if bundle b has any additional stack
52 // if the quantity is less than what is required, so this stack could not be satisfied
53 num--;
54 if (b.getPrice() <= wishlist.getPrice() && num < (double)wishlist.size()*0.25) // i.e. less than 25 percent of the stacks could not be satisfied
55 return 1.0;
56 else
57 return 0.0;
58 }
59 return 0.0;
60 }
61
62
63 @Override
64 public String toString()
65 {
66 return this.getClass().getSimpleName();
67 }
68
69}
Note: See TracBrowser for help on using the repository browser.