1 | package agents.anac.y2013.MetaAgent.portfolio.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 | statistic.get(issue).add(v);
|
---|
35 | }
|
---|
36 |
|
---|
37 | // receiveMessage the max bid for the agent from the opponent bids
|
---|
38 | if (oppBids.size() == 1)
|
---|
39 | maxUtilityBidForMe = bid;
|
---|
40 | else if (utilitySpace.getUtility(maxUtilityBidForMe) < utilitySpace
|
---|
41 | .getUtility(bid))
|
---|
42 | maxUtilityBidForMe = bid;
|
---|
43 | } catch (Exception e) {
|
---|
44 | e.printStackTrace();
|
---|
45 | }
|
---|
46 | }
|
---|
47 |
|
---|
48 | /**
|
---|
49 | * return opponents Bids
|
---|
50 | *
|
---|
51 | */
|
---|
52 | public ArrayList<Bid> getOpponentsBids() {
|
---|
53 | return oppBids;
|
---|
54 | }
|
---|
55 |
|
---|
56 | public OpponentBids(UtilitySpace utilitySpace) {
|
---|
57 | this.utilitySpace = utilitySpace;
|
---|
58 | List<Issue> issues = utilitySpace.getDomain().getIssues();
|
---|
59 | for (Issue issue : issues) {
|
---|
60 | statistic.put(issue, new BidStatistic(issue));
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | /**
|
---|
65 | * returns opponents Bids
|
---|
66 | *
|
---|
67 | */
|
---|
68 | public Bid getMaxUtilityBidForMe() {
|
---|
69 | return maxUtilityBidForMe;
|
---|
70 | }
|
---|
71 |
|
---|
72 | /**
|
---|
73 | * returns the most voted value for an isuue
|
---|
74 | *
|
---|
75 | */
|
---|
76 | public Value getMostVotedValueForIsuue(Issue issue) {
|
---|
77 | return statistic.get(issue).getMostBided();
|
---|
78 | }
|
---|
79 |
|
---|
80 | /**
|
---|
81 | * returns opponent bid utility that calculated from the vote statistics.
|
---|
82 | *
|
---|
83 | */
|
---|
84 | public double getOpponentBidUtility(Domain domain, Bid bid) {
|
---|
85 | double ret = 0;
|
---|
86 | List<Issue> issues = domain.getIssues();
|
---|
87 | for (Issue issue : issues) {
|
---|
88 | try {
|
---|
89 | ret += statistic.get(issue).getValueUtility(
|
---|
90 | bid.getValue(issue.getNumber()));
|
---|
91 | } catch (Exception e) {
|
---|
92 | e.printStackTrace();
|
---|
93 | }
|
---|
94 | }
|
---|
95 | System.out.println(ret / domain.getIssues().size());
|
---|
96 | return ret;
|
---|
97 | }
|
---|
98 | }
|
---|