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

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

AbstractTimeDependentNegotiationParty works

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