source: src/main/java/agents/anac/y2014/BraveCat/necessaryClasses/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: 2.5 KB
Line 
1package agents.anac.y2014.BraveCat.necessaryClasses;
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
12public class OutcomeSpace {
13 protected AbstractUtilitySpace utilitySpace;
14 protected List<BidDetails> allBids = new ArrayList();
15
16 public OutcomeSpace(AbstractUtilitySpace utilSpace) {
17 this.utilitySpace = utilSpace;
18 System.out.println("Generating All Bids...");
19 generateAllBids(utilSpace);
20 System.out.println("All Bids Generated!");
21 }
22
23 public void generateAllBids(AbstractUtilitySpace utilSpace) {
24 BidIterator iter = new BidIterator(utilSpace.getDomain());
25 while (iter.hasNext()) {
26 Bid bid = iter.next();
27 try {
28 BidDetails BidDetails = new BidDetails(bid,
29 utilSpace.getUtility(bid), -1.0D);
30 this.allBids.add(BidDetails);
31 } catch (Exception e) {
32 e.printStackTrace();
33 }
34 }
35 }
36
37 public List<BidDetails> getAllOutcomes() {
38 return this.allBids;
39 }
40
41 public List<BidDetails> getBidsinRange(Range range) {
42 ArrayList result = new ArrayList();
43 double upperbound = range.getUpperbound();
44 double lowerbound = range.getLowerbound();
45
46 for (BidDetails bid : this.allBids) {
47 if ((bid.getMyUndiscountedUtil() > lowerbound)
48 && (bid.getMyUndiscountedUtil() < upperbound)) {
49 result.add(bid);
50 }
51 }
52 return result;
53 }
54
55 public BidDetails getBidNearUtility(double utility) {
56 return (BidDetails) this.allBids.get(getIndexOfBidNearUtility(utility));
57 }
58
59 public BidDetails getMaxBidPossible() {
60 BidDetails maxBid = (BidDetails) this.allBids.get(0);
61 for (BidDetails bid : this.allBids) {
62 if (bid.getMyUndiscountedUtil() > maxBid.getMyUndiscountedUtil()) {
63 maxBid = bid;
64 }
65 }
66 return maxBid;
67 }
68
69 public BidDetails getMinBidPossible() {
70 BidDetails minBid = (BidDetails) this.allBids.get(0);
71 for (BidDetails bid : this.allBids) {
72 if (bid.getMyUndiscountedUtil() < minBid.getMyUndiscountedUtil()) {
73 minBid = bid;
74 }
75 }
76 return minBid;
77 }
78
79 public int getIndexOfBidNearUtility(double utility) {
80 double closesDistance = 1.0D;
81 int best = 0;
82 for (int i = 0; i < this.allBids.size(); i++) {
83 if (Math.abs(((BidDetails) this.allBids.get(i))
84 .getMyUndiscountedUtil() - utility) < closesDistance) {
85 closesDistance = Math.abs(((BidDetails) this.allBids.get(i))
86 .getMyUndiscountedUtil() - utility);
87 best = i;
88 }
89 }
90 return best;
91 }
92}
Note: See TracBrowser for help on using the repository browser.