source: src/main/java/negotiator/onetomany/players/UF_prcntQTYandprcntPrice.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: 2.2 KB
Line 
1/**
2 *
3 */
4package negotiator.onetomany.players;
5
6import negotiator.onetomany.domain.Bundle;
7import negotiator.onetomany.domain.Stack;
8
9
10/**
11 * If p1 percent of the stacks regarding quantity and p2 percent of total price of the bundle be satisfied
12 * compared to the total price of the wishlist,
13 * bundle b would be evaluated as 1.0, otherwise as 0.0.
14 *
15 * @author Faria Nassiri-Mofakham
16 *
17 */
18public class UF_prcntQTYandprcntPrice implements Utility_Function {
19
20 Bundle wishlist;
21
22 double p1;
23 double p2;
24
25 public UF_prcntQTYandprcntPrice(Bundle w, double p1, double p2)
26 {
27 this.wishlist=w;
28 this.p1=p1; // tolerable percentage for extra price
29 this.p2=p2; // tolerable percentage for extra stacks and/or stacks with less quantities
30 }
31
32 /**
33 * @return the wishlist
34 */
35 public Bundle getWishlist() {
36 return wishlist;
37 }
38
39 /**
40 * @param wishlist the wishlist to set
41 */
42 public void setWishlist(Bundle w) {
43 this.wishlist = w;
44 }
45
46 @Override
47 public Double getUtility(Bundle b)
48 {
49 // TODO Auto-generated method stub
50 int num=wishlist.size();
51
52 if (b!=null)
53 {
54 for (Stack s : b)
55 for (Stack t: wishlist)
56 if (s.getColor()==t.getColor() && s.getQuantity() >= t.getQuantity())
57 // if the quantity is less than what is required, so this stack could not be satisfied
58 num--;
59 if (b.getPrice() <= p2* wishlist.getPrice()+wishlist.getPrice() && num < (double)wishlist.size()*(1-p1) )
60 // i.e., the number of `dissatisfied' stacks are less than p1 percent of the stacks regarding the quantity
61 // and, the bundle total price is less that or equal to p2 percent of the wishlist total price
62 return 1.0;
63 else
64 return 0.0;
65 }
66 return 0.0;
67 }
68
69
70 /**
71 * @return the p1
72 */
73 public double getP1() {
74 return p1;
75 }
76
77
78 /**
79 * @param p1 the p1 to set
80 */
81 public void setP1(double p1) {
82 this.p1 = p1;
83 }
84
85
86 /**
87 * @return the p2
88 */
89 public double getP2() {
90 return p2;
91 }
92
93
94 /**
95 * @param p2 the p2 to set
96 */
97 public void setP2(double p2) {
98 this.p2 = p2;
99 }
100
101 @Override
102 public String toString()
103 {
104 return this.getClass().getSimpleName()+":qty%"+p1+":price%"+p2;
105 }
106
107}
Note: See TracBrowser for help on using the repository browser.