[1] | 1 | package agents.anac.y2010.AgentSmith;
|
---|
| 2 |
|
---|
| 3 | import java.util.HashMap;
|
---|
| 4 | import java.util.List;
|
---|
| 5 |
|
---|
| 6 | import genius.core.Bid;
|
---|
| 7 | import genius.core.issue.Issue;
|
---|
| 8 |
|
---|
| 9 | /**
|
---|
| 10 | * The OpponentModel. This model manages the opponents preferences, stores the
|
---|
| 11 | * bids and based on the number of times the opponent proposes a specific option
|
---|
| 12 | * in a bid, that option becomes more important and our agent uses this
|
---|
| 13 | * information to construct its own bids.
|
---|
| 14 | */
|
---|
| 15 | public class OpponentModel implements IOpponentModel {
|
---|
| 16 | private PreferenceProfileManager fPreferenceProfileManager;
|
---|
| 17 | private HashMap<Issue, IssueModel> fIssueModels;
|
---|
| 18 |
|
---|
| 19 | /**
|
---|
| 20 | * Constructor
|
---|
| 21 | */
|
---|
| 22 | public OpponentModel(PreferenceProfileManager pPreferenceProfileManager,
|
---|
| 23 | BidHistory pBidHistory) {
|
---|
| 24 | fPreferenceProfileManager = pPreferenceProfileManager;
|
---|
| 25 | fIssueModels = new HashMap<Issue, IssueModel>();
|
---|
| 26 |
|
---|
| 27 | initIssueModels();
|
---|
| 28 | }
|
---|
| 29 |
|
---|
| 30 | /**
|
---|
| 31 | * For each of the issues it initializes a model which stores the opponents'
|
---|
| 32 | * preferences
|
---|
| 33 | */
|
---|
| 34 | private void initIssueModels() {
|
---|
| 35 | List<Issue> lIssues = fPreferenceProfileManager.getIssues();
|
---|
| 36 | for (Issue lIssue : lIssues) {
|
---|
| 37 | IssueModel lModel;
|
---|
| 38 | lModel = new IssueModel(lIssue);
|
---|
| 39 | fIssueModels.put(lIssue, lModel);
|
---|
| 40 | }
|
---|
| 41 | }
|
---|
| 42 |
|
---|
| 43 | /**
|
---|
| 44 | * Adds the values of each issue of a bid to the preferenceprofilemanager
|
---|
| 45 | */
|
---|
| 46 | public void addBid(Bid pBid) {
|
---|
| 47 | List<Issue> lIssues = fPreferenceProfileManager.getIssues();
|
---|
| 48 | for (Issue lIssue : lIssues) {
|
---|
| 49 | fIssueModels.get(lIssue).addValue(
|
---|
| 50 | IssueModel.getBidValueByIssue(pBid, lIssue));
|
---|
| 51 | }
|
---|
| 52 | }
|
---|
| 53 |
|
---|
| 54 | /**
|
---|
| 55 | * Returns a hashmap with the weights for each of the issues
|
---|
| 56 | */
|
---|
| 57 | public HashMap<Issue, Double> getWeights() {
|
---|
| 58 | HashMap<Issue, Double> lWeights = new HashMap<Issue, Double>();
|
---|
| 59 | List<Issue> lIssues = fPreferenceProfileManager.getIssues();
|
---|
| 60 | for (Issue lIssue : lIssues) {
|
---|
| 61 | lWeights.put(lIssue, fIssueModels.get(lIssue).getWeight());
|
---|
| 62 | }
|
---|
| 63 |
|
---|
| 64 | double lTotal = 0;
|
---|
| 65 | for (Issue lIssue : lIssues)
|
---|
| 66 | lTotal += lWeights.get(lIssue);
|
---|
| 67 |
|
---|
| 68 | for (Issue lIssue : lIssues)
|
---|
| 69 | lWeights.put(lIssue, lWeights.get(lIssue) / lTotal);
|
---|
| 70 |
|
---|
| 71 | return lWeights;
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | /**
|
---|
| 75 | * Returns the utility of a bid, but instead of the normal utility it is
|
---|
| 76 | * based on the weights of each issues
|
---|
| 77 | */
|
---|
| 78 | public double getUtility(Bid pBid) {
|
---|
| 79 | double lUtility = 0;
|
---|
| 80 | HashMap<Issue, Double> lWeights = getWeights();
|
---|
| 81 | List<Issue> lIssues = fPreferenceProfileManager.getIssues();
|
---|
| 82 |
|
---|
| 83 | for (Issue lIssue : lIssues) {
|
---|
| 84 | double lWeight = lWeights.get(lIssue);
|
---|
| 85 | double lLocalUtility = fIssueModels.get(lIssue).getUtility(pBid);
|
---|
| 86 |
|
---|
| 87 | lUtility += lWeight * lLocalUtility;
|
---|
| 88 | }
|
---|
| 89 |
|
---|
| 90 | return lUtility;
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | }
|
---|