[1] | 1 | package geniusweb.exampleparties.agentgg;
|
---|
| 2 |
|
---|
| 3 | import java.util.ArrayList;
|
---|
| 4 | import java.util.HashMap;
|
---|
| 5 | import java.util.List;
|
---|
| 6 | import java.util.Map;
|
---|
| 7 |
|
---|
| 8 | import geniusweb.issuevalue.Bid;
|
---|
| 9 | import geniusweb.issuevalue.Domain;
|
---|
| 10 | import geniusweb.issuevalue.Value;
|
---|
| 11 | import geniusweb.issuevalue.ValueSet;
|
---|
| 12 | import geniusweb.profile.PartialOrdering;
|
---|
| 13 |
|
---|
| 14 | /**
|
---|
| 15 | * Importance map. One is created for each party. The key (String) is the issue
|
---|
| 16 | * and value is list of Importances of the values.
|
---|
| 17 | *
|
---|
| 18 | */
|
---|
| 19 | @SuppressWarnings("serial")
|
---|
| 20 | public class ImpMap extends HashMap<String, List<impUnit>> {
|
---|
| 21 | private Domain domain;
|
---|
| 22 |
|
---|
| 23 | // importance map
|
---|
| 24 | public ImpMap(PartialOrdering profile) {
|
---|
| 25 | super();
|
---|
| 26 | this.domain = profile.getDomain();
|
---|
| 27 | // Create empty my import map and opponent's value map
|
---|
| 28 | for (String issue : domain.getIssues()) {
|
---|
| 29 | ValueSet values = domain.getValues(issue);
|
---|
| 30 | List<impUnit> issueImpUnit = new ArrayList<>();
|
---|
| 31 | for (Value value : values) {
|
---|
| 32 | issueImpUnit.add(new impUnit(value));
|
---|
| 33 | }
|
---|
| 34 | this.put(issue, issueImpUnit);
|
---|
| 35 | }
|
---|
| 36 | }
|
---|
| 37 |
|
---|
| 38 | /**
|
---|
| 39 | * Update opponent map. Increases the meanWeightSum of the values of this
|
---|
| 40 | * bid.
|
---|
| 41 | *
|
---|
| 42 | * @param receivedOfferBid tbe received opponent bid.
|
---|
| 43 | */
|
---|
| 44 | public void opponent_update(Bid receivedOfferBid) {
|
---|
| 45 | for (String issue : receivedOfferBid.getIssues()) {
|
---|
| 46 | ValueSet values = domain.getValues(issue);
|
---|
| 47 | List<impUnit> currentIssueList = this.get(issue);
|
---|
| 48 | for (impUnit currentUnit : currentIssueList) {
|
---|
| 49 | if (currentUnit.valueOfIssue
|
---|
| 50 | .equals(receivedOfferBid.getValue(issue))) {
|
---|
| 51 | currentUnit.meanWeightSum += 1;
|
---|
| 52 | break;
|
---|
| 53 | }
|
---|
| 54 | }
|
---|
| 55 | }
|
---|
| 56 | for (List<impUnit> impUnitList : this.values()) {
|
---|
| 57 | impUnitList.sort(new impUnit.meanWeightSumComparator());
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | /**
|
---|
| 62 | * Update your own importance map Traverse the known bidOrder and update the
|
---|
| 63 | * "weight sum" and "number of times" in the import table.
|
---|
| 64 | *
|
---|
| 65 | * @param bids a list of ordered bids, worst bid first, best bid last
|
---|
| 66 | */
|
---|
| 67 | public void self_update(List<Bid> bidOrdering) {
|
---|
| 68 | int currentWeight = 0;
|
---|
| 69 | for (Bid bid : bidOrdering) {
|
---|
| 70 | currentWeight += 1;
|
---|
| 71 | for (String issue : bid.getIssues()) {
|
---|
| 72 | List<impUnit> currentIssueList = this.get(issue);
|
---|
| 73 | for (impUnit currentUnit : currentIssueList) {
|
---|
| 74 | if (currentUnit.valueOfIssue.toString()
|
---|
| 75 | .equals(bid.getValue(issue).toString())) {
|
---|
| 76 | currentUnit.weightSum += currentWeight;
|
---|
| 77 | currentUnit.count += 1;
|
---|
| 78 | break;
|
---|
| 79 | }
|
---|
| 80 | }
|
---|
| 81 | }
|
---|
| 82 | }
|
---|
| 83 | // Calculate weights
|
---|
| 84 | for (List<impUnit> impUnitList : this.values()) {
|
---|
| 85 | for (impUnit currentUnit : impUnitList) {
|
---|
| 86 | if (currentUnit.count == 0) {
|
---|
| 87 | currentUnit.meanWeightSum = 0.0;
|
---|
| 88 | } else {
|
---|
| 89 | currentUnit.meanWeightSum = (double) currentUnit.weightSum
|
---|
| 90 | / (double) currentUnit.count;
|
---|
| 91 | }
|
---|
| 92 | }
|
---|
| 93 | }
|
---|
| 94 | // Sort
|
---|
| 95 | for (List<impUnit> impUnitList : this.values()) {
|
---|
| 96 | impUnitList.sort(new impUnit.meanWeightSumComparator());
|
---|
| 97 | }
|
---|
| 98 | // Find the minimum
|
---|
| 99 | double minMeanWeightSum = Double.POSITIVE_INFINITY;
|
---|
| 100 | for (Map.Entry<String, List<impUnit>> entry : this.entrySet()) {
|
---|
| 101 | double tempMeanWeightSum = entry.getValue()
|
---|
| 102 | .get(entry.getValue().size() - 1).meanWeightSum;
|
---|
| 103 | if (tempMeanWeightSum < minMeanWeightSum) {
|
---|
| 104 | minMeanWeightSum = tempMeanWeightSum;
|
---|
| 105 | }
|
---|
| 106 | }
|
---|
| 107 | // Minus all values
|
---|
| 108 | for (List<impUnit> impUnitList : this.values()) {
|
---|
| 109 | for (impUnit currentUnit : impUnitList) {
|
---|
| 110 | currentUnit.meanWeightSum -= minMeanWeightSum;
|
---|
| 111 | }
|
---|
| 112 | }
|
---|
| 113 | }
|
---|
| 114 |
|
---|
| 115 | /**
|
---|
| 116 | * @param bid the bid to get the importance (utility?) of.
|
---|
| 117 | * @return the importance value of bid. CHECK is this inside [0,1]?
|
---|
| 118 | */
|
---|
| 119 | public double getImportance(Bid bid) {
|
---|
| 120 | double bidImportance = 0.0;
|
---|
| 121 | for (String issue : bid.getIssues()) {
|
---|
| 122 | Value value = bid.getValue(issue);
|
---|
| 123 | double valueImportance = 0.0;
|
---|
| 124 | for (impUnit i : this.get(issue)) {
|
---|
| 125 | if (i.valueOfIssue.equals(value)) {
|
---|
| 126 | valueImportance = i.meanWeightSum;
|
---|
| 127 | break;
|
---|
| 128 | }
|
---|
| 129 | }
|
---|
| 130 | bidImportance += valueImportance;
|
---|
| 131 | }
|
---|
| 132 | return bidImportance;
|
---|
| 133 | }
|
---|
| 134 | }
|
---|