[1] | 1 | package agents.anac.y2011.HardHeaded;
|
---|
| 2 |
|
---|
| 3 | import java.util.HashMap;
|
---|
| 4 | import java.util.List;
|
---|
| 5 | import java.util.TreeMap;
|
---|
| 6 |
|
---|
| 7 | import genius.core.Bid;
|
---|
| 8 | import genius.core.issue.Issue;
|
---|
| 9 | import genius.core.issue.IssueDiscrete;
|
---|
| 10 | import genius.core.issue.Value;
|
---|
| 11 | import genius.core.utility.AdditiveUtilitySpace;
|
---|
| 12 | import genius.core.utility.UtilitySpace;
|
---|
| 13 |
|
---|
| 14 | /**
|
---|
| 15 | * This class generates all possible bids that can be offered according to a
|
---|
| 16 | * given domain. The bids are stored in a treeMap structure sorted by the order
|
---|
| 17 | * of their utility for the agent.
|
---|
| 18 | *
|
---|
| 19 | */
|
---|
| 20 | public class BidSelector {
|
---|
| 21 | protected UtilitySpace utilitySpace;
|
---|
| 22 | TreeMap<Double, Bid> BidList;
|
---|
| 23 |
|
---|
| 24 | /**
|
---|
| 25 | * BidSelector constructor
|
---|
| 26 | *
|
---|
| 27 | * @param pUtilitySpace
|
---|
| 28 | * a passed {@link AdditiveUtilitySpace} that is used to generate
|
---|
| 29 | * all possible bid of its domain
|
---|
| 30 | */
|
---|
| 31 | public BidSelector(UtilitySpace pUtilitySpace) {
|
---|
| 32 |
|
---|
| 33 | this.utilitySpace = pUtilitySpace;
|
---|
| 34 | BidList = new TreeMap<Double, Bid>();
|
---|
| 35 |
|
---|
| 36 | List<Issue> issues = utilitySpace.getDomain().getIssues();
|
---|
| 37 |
|
---|
| 38 | HashMap<Integer, Value> InitialBid = new HashMap<Integer, Value>();
|
---|
| 39 | for (Issue lIssue : issues) {
|
---|
| 40 | Value v = ((IssueDiscrete) lIssue).getValue(0);
|
---|
| 41 | InitialBid.put(lIssue.getNumber(), v);
|
---|
| 42 | }
|
---|
| 43 | try {
|
---|
| 44 | Bid b = new Bid(utilitySpace.getDomain(), InitialBid);
|
---|
| 45 | BidList.put(utilitySpace.getUtility(b), b);
|
---|
| 46 | }
|
---|
| 47 |
|
---|
| 48 | catch (Exception e) {
|
---|
| 49 | e.printStackTrace();
|
---|
| 50 | }
|
---|
| 51 |
|
---|
| 52 | for (Issue lIssue : issues) {
|
---|
| 53 |
|
---|
| 54 | TreeMap<Double, Bid> TempBids = new TreeMap<Double, Bid>();
|
---|
| 55 |
|
---|
| 56 | IssueDiscrete lIssueDiscrete = (IssueDiscrete) lIssue;
|
---|
| 57 | int optionIndex = lIssueDiscrete.getNumberOfValues();
|
---|
| 58 |
|
---|
| 59 | // a small value is added to bid utilities, so that their ordering
|
---|
| 60 | // inside the
|
---|
| 61 | // TreeMap would be attained
|
---|
| 62 | double d = -0.00000001;
|
---|
| 63 | for (Bid TBid : BidList.values()) {
|
---|
| 64 | for (int i = 0; i < optionIndex; i++) {
|
---|
| 65 | HashMap<Integer, Value> NewBidV = Bidconfig(TBid);
|
---|
| 66 | NewBidV.put(lIssue.getNumber(),
|
---|
| 67 | ((IssueDiscrete) lIssue).getValue(i));
|
---|
| 68 | try {
|
---|
| 69 | Bid webid = new Bid(utilitySpace.getDomain(), NewBidV);
|
---|
| 70 | TempBids.put(utilitySpace.getUtility(webid) + d, webid);
|
---|
| 71 | d = d - 0.00000001;
|
---|
| 72 | } catch (Exception e) {
|
---|
| 73 | }
|
---|
| 74 |
|
---|
| 75 | }
|
---|
| 76 | BidList = TempBids;
|
---|
| 77 | }
|
---|
| 78 | }
|
---|
| 79 | }
|
---|
| 80 |
|
---|
| 81 | /**
|
---|
| 82 | * receives a bid an generates all possible configurations of it
|
---|
| 83 | *
|
---|
| 84 | * @param pBid
|
---|
| 85 | * passed bid
|
---|
| 86 | * @return a {@link HashMap} containing all configurations of a possible
|
---|
| 87 | * bid.
|
---|
| 88 | */
|
---|
| 89 | private HashMap<Integer, Value> Bidconfig(Bid pBid) {
|
---|
| 90 | HashMap<Integer, Value> lNewBidValues = new HashMap<Integer, Value>();
|
---|
| 91 |
|
---|
| 92 | for (Issue lIssue : this.utilitySpace.getDomain().getIssues()) {
|
---|
| 93 | try {
|
---|
| 94 | lNewBidValues.put(lIssue.getNumber(),
|
---|
| 95 | pBid.getValue(lIssue.getNumber()));
|
---|
| 96 | } catch (Exception e) {
|
---|
| 97 | }
|
---|
| 98 | }
|
---|
| 99 | return lNewBidValues;
|
---|
| 100 | }
|
---|
| 101 | }
|
---|