source: src/main/java/onetomany/bargainingchipsgame/OutcomeSpace.java@ 284

Last change on this file since 284 was 284, checked in by Tim Baarslag, 5 years ago

Coordinator has WishList
OutcomeSpace

File size: 2.6 KB
RevLine 
[284]1package onetomany.bargainingchipsgame;
2
3import java.util.List;
4
5import java.util.ArrayList;
6
7import onetomany.bargainingchipsgame.players.utilityfunction.UtilityFunction;
8
9/**
10 * This class generates the complete outcome space and is therefore useful if
11 * someone wants to quickly implement an agent. Note that working with a sorted
12 * outcomespace class would be faster during the negotiation.
13 */
14public class OutcomeSpace
15{
16 /** Reference to the utility space */
17 protected UtilityFunction u;
18 /** List of all possible bids in the domain */
19 protected List<Bundle> allBids = new ArrayList<Bundle>();
20
21 /**
22 * Creates an unsorted outcome space. Warning: this call iterates over ALL
23 * possible bids.
24 *
25 * @param utilSpace
26 */
27 public OutcomeSpace(UtilityFunction f)
28 {
29 this.u = f;
30 generateAllBids();
31 }
32
33 /**
34 * Generates all the possible bids in the domain
35 *
36 * @param utilSpace
37 */
38 public void generateAllBids()
39 {
40
41
42 }
43
44 /**
45 * @return list of all possible bids
46 */
47 public List<Bundle> getAllOutcomes()
48 {
49 return allBids;
50 }
51
52 /**
53 * gets a BidDetails which is closest to the given utility
54 *
55 * @param utility
56 * to which the found bid must be closest.
57 * @return BidDetails
58 */
59 public Bundle getBidNearUtility(double utility)
60 {
61 return allBids.get(getIndexOfBidNearUtility(utility));
62 }
63
64 /**
65 * @return best bid in the domain.
66 */
67 public Bundle getMaxBidPossible()
68 {
69 Bundle maxBid = allBids.get(0);
70 for (Bundle bid : allBids) {
71 if (u.getUtility(bid) > u.getUtility(maxBid)) {
72 maxBid = bid;
73 }
74 }
75 return maxBid;
76 }
77
78 /**
79 * @return worst bid in the domain.
80 */
81 public Bundle getMinBidPossible() {
82 Bundle minBid = allBids.get(0);
83 for (Bundle bid : allBids) {
84 if (u.getUtility(bid) < u.getUtility(minBid)) {
85 minBid = bid;
86 }
87 }
88 return minBid;
89 }
90
91 /**
92 * @param utility
93 * to which the found bid must be closest.
94 * @return index of the bid with the utility closest to the given utilty.
95 */
96 public int getIndexOfBidNearUtility(double utility)
97 {
98 double closesDistance = 1;
99 int best = 0;
100 for (int i = 0; i < allBids.size(); i++) {
101 if (Math.abs(u.getUtility(allBids.get(i)) - utility) < closesDistance) {
102 closesDistance = Math.abs(u.getUtility(allBids.get(i)) - utility);
103 best = i;
104 }
105 }
106 return best;
107 }
108
109 @Override
110 public String toString() {
111 String all = "";
112 for (Bundle b : allBids) {
113 all += b.toString() + "\n,";
114 }
115 return "OutcomeSpace[" + all + "]";
116 }
117}
Note: See TracBrowser for help on using the repository browser.