1 | package agents.anac.y2012.AgentLG;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.HashMap;
|
---|
5 | import java.util.List;
|
---|
6 |
|
---|
7 | import genius.core.Bid;
|
---|
8 | import genius.core.Domain;
|
---|
9 | import genius.core.issue.Issue;
|
---|
10 | import genius.core.issue.Value;
|
---|
11 | import genius.core.utility.UtilitySpace;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Class that is used to save opponents bid and learn opponent utility
|
---|
15 | *
|
---|
16 | */
|
---|
17 | public class OpponentBids {
|
---|
18 |
|
---|
19 | private ArrayList<Bid> oppBids = new ArrayList<Bid>();
|
---|
20 | private HashMap<Issue, BidStatistic> statistic = new HashMap<Issue, BidStatistic>();
|
---|
21 | private Bid maxUtilityBidForMe = null;
|
---|
22 | private UtilitySpace utilitySpace;
|
---|
23 |
|
---|
24 | /**
|
---|
25 | * add opponent bid and updates statistics
|
---|
26 | *
|
---|
27 | */
|
---|
28 | public void addBid(Bid bid) {
|
---|
29 | oppBids.add(bid);
|
---|
30 | try {
|
---|
31 | // updates statistics
|
---|
32 | for (Issue issue : statistic.keySet()) {
|
---|
33 | Value v = bid.getValue(issue.getNumber());
|
---|
34 |
|
---|
35 | statistic.get(issue).add(v);
|
---|
36 | }
|
---|
37 |
|
---|
38 | // receiveMessage the max bid for the agent from the opponent bids
|
---|
39 | if (oppBids.size() == 1)
|
---|
40 | maxUtilityBidForMe = bid;
|
---|
41 | else if (utilitySpace.getUtility(maxUtilityBidForMe) < utilitySpace
|
---|
42 | .getUtility(bid))
|
---|
43 | maxUtilityBidForMe = bid;
|
---|
44 | } catch (Exception e) {
|
---|
45 | e.printStackTrace();
|
---|
46 | }
|
---|
47 | }
|
---|
48 |
|
---|
49 | /**
|
---|
50 | * return opponents Bids
|
---|
51 | *
|
---|
52 | */
|
---|
53 | public ArrayList<Bid> getOpponentsBids() {
|
---|
54 | return oppBids;
|
---|
55 | }
|
---|
56 |
|
---|
57 | public OpponentBids(UtilitySpace utilitySpace) {
|
---|
58 | this.utilitySpace = utilitySpace;
|
---|
59 | List<Issue> issues = utilitySpace.getDomain().getIssues();
|
---|
60 | for (Issue issue : issues) {
|
---|
61 | statistic.put(issue, new BidStatistic(issue));
|
---|
62 | }
|
---|
63 | }
|
---|
64 |
|
---|
65 | /**
|
---|
66 | * returns opponents Bids
|
---|
67 | *
|
---|
68 | */
|
---|
69 | public Bid getMaxUtilityBidForMe() {
|
---|
70 | return maxUtilityBidForMe;
|
---|
71 | }
|
---|
72 |
|
---|
73 | /**
|
---|
74 | * returns the most voted value for an isuue
|
---|
75 | *
|
---|
76 | */
|
---|
77 | public Value getMostVotedValueForIsuue(Issue issue) {
|
---|
78 | return statistic.get(issue).getMostBided();
|
---|
79 | }
|
---|
80 |
|
---|
81 | /**
|
---|
82 | * returns opponent bid utility that calculated from the vote statistics.
|
---|
83 | *
|
---|
84 | */
|
---|
85 | public double getOpponentBidUtility(Domain domain, Bid bid) {
|
---|
86 | double ret = 0;
|
---|
87 | List<Issue> issues = domain.getIssues();
|
---|
88 | for (Issue issue : issues) {
|
---|
89 | try {
|
---|
90 | ret += statistic.get(issue).getValueUtility(
|
---|
91 | bid.getValue(issue.getNumber()));
|
---|
92 | } catch (Exception e) {
|
---|
93 | e.printStackTrace();
|
---|
94 | }
|
---|
95 | }
|
---|
96 | return ret;
|
---|
97 | }
|
---|
98 | }
|
---|