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