source: src/main/java/onetomany/bargainingchipsgame/players/utilityfunction/UF_75pQtyOrNothing.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.6 KB
Line 
1/**
2 * UtilityFunction75percentQuantityOrNothing
3 */
4package onetomany.bargainingchipsgame.players.utilityfunction;
5
6import onetomany.bargainingchipsgame.Bundle;
7import onetomany.bargainingchipsgame.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.