source: src/main/java/genius/core/boaframework/OutcomeSpace.java

Last change on this file was 127, checked in by Wouter Pasman, 6 years ago

#41 ROLL BACK of rev.126 . So this version is equal to rev. 125

File size: 4.1 KB
Line 
1package genius.core.boaframework;
2
3import java.util.ArrayList;
4import java.util.List;
5
6import genius.core.Bid;
7import genius.core.BidIterator;
8import genius.core.bidding.BidDetails;
9import genius.core.misc.Range;
10import genius.core.utility.AbstractUtilitySpace;
11
12/**
13 * This class generates the complete outcome space and is therefore useful if
14 * someone wants to quickly implement an agent. Note that while this
15 * outcomespace is faster upon initialization, the sorted outcomespace class is
16 * faster during the negotiation.
17 *
18 * @author Alex Dirkzwager, Mark Hendrikx
19 */
20public class OutcomeSpace {
21
22 /** Reference to the utility space */
23 protected AbstractUtilitySpace utilitySpace;
24 /** List of all possible bids in the domain */
25 protected List<BidDetails> allBids = new ArrayList<BidDetails>();
26
27 /**
28 * Creates an unsorted outcome space. Warning: this call iterates over ALL
29 * possible bids.
30 *
31 * @param utilSpace
32 */
33 public OutcomeSpace(AbstractUtilitySpace utilSpace) {
34 this.utilitySpace = utilSpace;
35 generateAllBids(utilSpace);
36 }
37
38 /**
39 * Generates all the possible bids in the domain
40 *
41 * @param utilSpace
42 */
43 public void generateAllBids(AbstractUtilitySpace utilSpace) {
44
45 BidIterator iter = new BidIterator(utilSpace.getDomain());
46 while (iter.hasNext()) {
47 Bid bid = iter.next();
48 try {
49 BidDetails BidDetails = new BidDetails(bid, utilSpace.getUtility(bid), -1);
50 allBids.add(BidDetails);
51 } catch (Exception e) {
52 e.printStackTrace();
53 }
54 }
55 }
56
57 /**
58 * @return list of all possible bids
59 */
60 public List<BidDetails> getAllOutcomes() {
61 return allBids;
62 }
63
64 /**
65 * @return list of all possible bids without their utilities
66 */
67 public List<Bid> getAllBidsWithoutUtilities() {
68
69 List<Bid> bidsList = new ArrayList<Bid>();
70 for (BidDetails bid : this.allBids) {
71 bidsList.add(bid.getBid());
72 }
73 return bidsList;
74 }
75
76 /**
77 * Returns a list of bids (from possibleBids) that have a utility within the
78 * given range.
79 *
80 * @param range
81 * in which the bids must be found.
82 * @return list of bids which a utility in the given range.
83 */
84 public List<BidDetails> getBidsinRange(Range range) {
85 ArrayList<BidDetails> result = new ArrayList<BidDetails>();
86 double upperbound = range.getUpperbound();
87 double lowerbound = range.getLowerbound();
88
89 for (BidDetails bid : allBids) {
90 if (bid.getMyUndiscountedUtil() > lowerbound && bid.getMyUndiscountedUtil() < upperbound) {
91 result.add(bid);
92 }
93 }
94 return result;
95 }
96
97 /**
98 * gets a BidDetails which is closest to the given utility
99 *
100 * @param utility
101 * to which the found bid must be closest.
102 * @return BidDetails
103 */
104 public BidDetails getBidNearUtility(double utility) {
105 return allBids.get(getIndexOfBidNearUtility(utility));
106 }
107
108 /**
109 * @return best bid in the domain.
110 */
111 public BidDetails getMaxBidPossible() {
112 BidDetails maxBid = allBids.get(0);
113 for (BidDetails bid : allBids) {
114 if (bid.getMyUndiscountedUtil() > maxBid.getMyUndiscountedUtil()) {
115 maxBid = bid;
116 }
117 }
118 return maxBid;
119 }
120
121 /**
122 * @return worst bid in the domain.
123 */
124 public BidDetails getMinBidPossible() {
125 BidDetails minBid = allBids.get(0);
126 for (BidDetails bid : allBids) {
127 if (bid.getMyUndiscountedUtil() < minBid.getMyUndiscountedUtil()) {
128 minBid = bid;
129 }
130 }
131 return minBid;
132 }
133
134 /**
135 * @param utility
136 * to which the found bid must be closest.
137 * @return index of the bid with the utility closest to the given utilty.
138 */
139 public int getIndexOfBidNearUtility(double utility) {
140 double closesDistance = 1;
141 int best = 0;
142 for (int i = 0; i < allBids.size(); i++) {
143 if (Math.abs(allBids.get(i).getMyUndiscountedUtil() - utility) < closesDistance) {
144 closesDistance = Math.abs(allBids.get(i).getMyUndiscountedUtil() - utility);
145 best = i;
146 }
147 }
148 return best;
149 }
150
151 @Override
152 public String toString() {
153 String all = "";
154 for (BidDetails b : allBids) {
155 all += b.toString() + "\n,";
156 }
157 return "OutcomeSpace[" + all + "]";
158 }
159}
Note: See TracBrowser for help on using the repository browser.