source: src/main/java/negotiator/onetomany/players/UF_AllOrNothing.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.2 KB
Line 
1/**
2 * UtilityFunctionAllOrNothing class
3 */
4package negotiator.onetomany.players;
5
6import negotiator.onetomany.domain.Bundle;
7import negotiator.onetomany.domain.Stack;
8
9/**
10 * If all requested quantities at the total requested price (or less) would be satisfied,
11 * then the bundle is evaluated as 1.0, otherwise as 0.0;
12 *
13 * @author Faria Nassiri-Mofakham
14 *
15 */
16public class UF_AllOrNothing implements Utility_Function {
17
18 Bundle wishlist;
19
20
21 public UF_AllOrNothing(Bundle w)
22 {
23 this.wishlist=w;
24 }
25
26 /**
27 * @return the wishlist
28 */
29 public Bundle getWishlist() {
30 return wishlist;
31 }
32
33 /**
34 * @param wishlist the wishlist to set
35 */
36 public void setWishlist(Bundle w) {
37 this.wishlist = w;
38 }
39
40 @Override
41 public Double getUtility(Bundle b)
42 {
43 // TODO Auto-generated method stub
44 if (b!=null)
45 {
46 for (Stack s : b)
47 for (Stack t: wishlist)
48 if (s.getColor()==t.getColor())
49 if (s.getQuantity() !=t.getQuantity())
50 return 0.0;
51 if (b.getPrice() <=wishlist.getPrice())
52 return 1.0;
53 else
54 return 0.0;
55 }
56 return 0.0;
57 }
58
59 @Override
60 public String toString()
61 {
62 return this.getClass().getSimpleName();
63 }
64
65}
66
Note: See TracBrowser for help on using the repository browser.