1 | package agents.anac.y2018.shiboy.etc;
|
---|
2 |
|
---|
3 | import java.util.HashMap;
|
---|
4 | import java.util.Map;
|
---|
5 |
|
---|
6 | import genius.core.list.Tuple;
|
---|
7 | import genius.core.parties.NegotiationInfo;
|
---|
8 | import genius.core.persistent.PersistentDataContainer;
|
---|
9 | import genius.core.persistent.PersistentDataType;
|
---|
10 | import genius.core.persistent.StandardInfo;
|
---|
11 | import genius.core.persistent.StandardInfoList;
|
---|
12 |
|
---|
13 | /**
|
---|
14 | * Created by shota_suzuki on 2018/05/16.
|
---|
15 | */
|
---|
16 |
|
---|
17 | public class NegoHistory {
|
---|
18 | private NegotiationInfo info;
|
---|
19 | private StandardInfoList history;
|
---|
20 | private boolean historyAnalyzed = false;
|
---|
21 |
|
---|
22 | private boolean isPrinting = false; // デバッグ用
|
---|
23 | private boolean isPrinting_History = false;
|
---|
24 |
|
---|
25 | /**
|
---|
26 | * @param info
|
---|
27 | * @param isPrinting
|
---|
28 | * @param pData public PersistentDataContainer getData(): persistent data
|
---|
29 | */
|
---|
30 | public NegoHistory(NegotiationInfo info, boolean isPrinting, PersistentDataContainer pData) {
|
---|
31 | this.info = info;
|
---|
32 | this.isPrinting = isPrinting;
|
---|
33 |
|
---|
34 | // PersistentDataType が Standard の場合
|
---|
35 | if (pData.getPersistentDataType() == PersistentDataType.STANDARD) {
|
---|
36 | history = (StandardInfoList) pData.get();
|
---|
37 |
|
---|
38 | if (!history.isEmpty()) {
|
---|
39 | // example of using the history. Compute for each party the maximum
|
---|
40 | // utility of the bids in last session.
|
---|
41 | Map<String, Double> maxutils = new HashMap<String, Double>();
|
---|
42 | StandardInfo lastinfo = history.get(history.size() - 1);
|
---|
43 | for (Tuple<String, Double> offered : lastinfo.getUtilities()) {
|
---|
44 | String party = offered.get1();
|
---|
45 | Double util = offered.get2();
|
---|
46 | maxutils.put(party, maxutils.containsKey(party) ? Math.max(maxutils.get(party), util) : util);
|
---|
47 | }
|
---|
48 | System.out.println(maxutils); // notice tournament suppresses all
|
---|
49 | // output.
|
---|
50 | }
|
---|
51 | }
|
---|
52 |
|
---|
53 | if (this.isPrinting) {
|
---|
54 | System.out.println("[isPrinting] NegoHistory: success");
|
---|
55 | }
|
---|
56 |
|
---|
57 | }
|
---|
58 |
|
---|
59 | public void analyzeHistory() {
|
---|
60 | historyAnalyzed = true;
|
---|
61 |
|
---|
62 | // from recent to older history records
|
---|
63 | for (int h = history.size() - 1; h >= 0; h--) {
|
---|
64 |
|
---|
65 | System.out.println("History index: " + h);
|
---|
66 |
|
---|
67 | StandardInfo lastinfo = history.get(h);
|
---|
68 |
|
---|
69 | int counter = 0;
|
---|
70 | for (Tuple<String, Double> offered : lastinfo.getUtilities()) {
|
---|
71 | counter++;
|
---|
72 |
|
---|
73 | String party = offered.get1(); // get partyID -> example: ConcederParty@15
|
---|
74 | Double util = offered.get2(); // get the offer utility
|
---|
75 |
|
---|
76 | System.out.println("PartyID: " + party + " utilityForMe: " + util);
|
---|
77 | System.out.println();
|
---|
78 | //just print first 3 bids, not the whole history
|
---|
79 | if (counter == 3)
|
---|
80 | break;
|
---|
81 | }
|
---|
82 |
|
---|
83 | System.out.println("\n");
|
---|
84 |
|
---|
85 | }
|
---|
86 |
|
---|
87 | }
|
---|
88 | }
|
---|