1 | package agents.anac.y2015.xianfa;
|
---|
2 |
|
---|
3 | import java.io.BufferedWriter;
|
---|
4 | import java.io.File;
|
---|
5 | import java.io.FileWriter;
|
---|
6 | import java.io.IOException;
|
---|
7 | import java.util.ArrayList;
|
---|
8 |
|
---|
9 | import agents.anac.y2015.xianfa.XianFaAgent;
|
---|
10 | import genius.core.issue.Value;
|
---|
11 | import genius.core.parties.AbstractNegotiationParty;
|
---|
12 |
|
---|
13 | public class Statistician {
|
---|
14 | private XianFaAgent myAgent;
|
---|
15 | private String record = "record";
|
---|
16 |
|
---|
17 | public Statistician(AbstractNegotiationParty myAgent) {
|
---|
18 | this.myAgent = (XianFaAgent) myAgent;
|
---|
19 | }
|
---|
20 |
|
---|
21 | public void log() {
|
---|
22 | write(analyse());
|
---|
23 | }
|
---|
24 |
|
---|
25 | public String analyse() {
|
---|
26 | String c = "";
|
---|
27 | String n = System.getProperty("line.separator");
|
---|
28 |
|
---|
29 | ArrayList<AIssue> issues = myAgent.issuesA;
|
---|
30 | ArrayList<AIssue> issuesB = myAgent.issuesB;
|
---|
31 |
|
---|
32 | for (int i=0; i<issues.size(); i++) {
|
---|
33 | c += String.valueOf(issues.get(i).issnr);
|
---|
34 | c += n;
|
---|
35 |
|
---|
36 | for (Value val : issues.get(i).getValues().keySet()) {
|
---|
37 | c += val.toString();
|
---|
38 | c += " - ";
|
---|
39 | c += String.valueOf(issues.get(i).getValues().get(val));
|
---|
40 | c += " / ";
|
---|
41 | c += String.valueOf(issuesB.get(i).getValues().get(val));
|
---|
42 | c += n;
|
---|
43 | }
|
---|
44 | }
|
---|
45 |
|
---|
46 | c += n;
|
---|
47 | c += "Number of offers accepted by opponent A: " + String.valueOf(myAgent.stat_goodBids);
|
---|
48 | c += n;
|
---|
49 | c += "Number of offers accepted by opponent B: " + String.valueOf(myAgent.stat_BAccepts);
|
---|
50 |
|
---|
51 | c += n;
|
---|
52 | //c += "Failed attempts to find a good enough bid: " + String.valueOf(myAgent.stat_bidsNotInList);
|
---|
53 | //c += n;
|
---|
54 | //c += "Successful attempts at findding a good enough bid: " + String.valueOf(myAgent.stat_bidsInList);
|
---|
55 | //c += n;
|
---|
56 |
|
---|
57 | c += n;
|
---|
58 | c += "Average time per round: " + myAgent.avgRdTime;
|
---|
59 | c += n;
|
---|
60 | c += "Reservation value is: " + myAgent.resValue;
|
---|
61 | c += n;
|
---|
62 | c += "Number of times offered history best bid: " + String.valueOf(myAgent.stat_offerHistBest);
|
---|
63 | c += n;
|
---|
64 | if (myAgent.opponentABest != null) {
|
---|
65 | c += "Opponent A's best bid is: " + myAgent.opponentABest.toString();
|
---|
66 | c += n;
|
---|
67 | try {
|
---|
68 | c += "Utility of opponent A's best bid is: " + String.valueOf(myAgent.getUtilitySpace().getUtility(myAgent.opponentABest));
|
---|
69 | } catch (Exception e) {
|
---|
70 | e.printStackTrace();
|
---|
71 | }
|
---|
72 | c += n;
|
---|
73 | }
|
---|
74 | c += "My total unique offers: " + String.valueOf(myAgent.myUniqueOffers);
|
---|
75 | c += n;
|
---|
76 | c += "Number of unique offers made by A: " + String.valueOf(myAgent.bidSet.size());
|
---|
77 | c += n;
|
---|
78 | c += "Number of unique offers made by B: " + String.valueOf(myAgent.bidSetB.size());
|
---|
79 |
|
---|
80 | c += n;
|
---|
81 | c += "this is round ";
|
---|
82 | c += String.valueOf(myAgent.rounds);
|
---|
83 | c += n;
|
---|
84 | c += "Normalized time at which session has ended: ";
|
---|
85 | c += myAgent.getTimeLine().getTime();
|
---|
86 |
|
---|
87 | return c;
|
---|
88 | }
|
---|
89 |
|
---|
90 | public void write(String content) {
|
---|
91 | try {
|
---|
92 |
|
---|
93 | //String content = "This is the content to write into file";
|
---|
94 |
|
---|
95 | File file = new File("C:\\Users\\Kevin\\Research Papers\\" +
|
---|
96 | "record.txt");
|
---|
97 |
|
---|
98 | // if file doesnt exists, then create it
|
---|
99 | if (!file.exists()) {
|
---|
100 | file.createNewFile();
|
---|
101 | }
|
---|
102 |
|
---|
103 | FileWriter fw = new FileWriter(file.getAbsoluteFile());
|
---|
104 | BufferedWriter bw = new BufferedWriter(fw);
|
---|
105 | bw.write(content);
|
---|
106 | bw.close();
|
---|
107 |
|
---|
108 | } catch (IOException e) {
|
---|
109 | e.printStackTrace();
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|