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