1 | package agents.anac.y2016.farma.etc;
|
---|
2 |
|
---|
3 | import java.util.ArrayList;
|
---|
4 | import java.util.HashMap;
|
---|
5 |
|
---|
6 | public class CntBySender {
|
---|
7 | private int selectWeight; // どの重みを適用するか
|
---|
8 |
|
---|
9 | private ArrayList<Object> opponents;
|
---|
10 | private HashMap<Object, Integer> simpleCnt;
|
---|
11 | private int simpleSum;
|
---|
12 | private HashMap<Object, Double> weightedCnt;
|
---|
13 | private double weightedSum;
|
---|
14 |
|
---|
15 | public CntBySender(int selectweight) {
|
---|
16 | this.selectWeight = selectweight;
|
---|
17 |
|
---|
18 | this.opponents = new ArrayList<Object>();
|
---|
19 | this.simpleCnt = new HashMap<Object, Integer>();
|
---|
20 | this.simpleSum = 0;
|
---|
21 |
|
---|
22 | this.weightedCnt = new HashMap<Object, Double>();
|
---|
23 | this.weightedSum = 0.0;
|
---|
24 | }
|
---|
25 |
|
---|
26 | /**
|
---|
27 | * カウント情報の更新
|
---|
28 | *
|
---|
29 | * @param sender
|
---|
30 | * @param time
|
---|
31 | */
|
---|
32 | public void incrementCnt(Object sender, double time) {
|
---|
33 | simpleSum += 1;
|
---|
34 | if (!simpleCnt.containsKey(sender)) {
|
---|
35 | simpleCnt.put(sender, 1);
|
---|
36 | opponents.add(sender);
|
---|
37 | } else {
|
---|
38 | simpleCnt.put(sender, simpleCnt.get(sender) + 1);
|
---|
39 | }
|
---|
40 |
|
---|
41 | double addCnt = calWeightedIncrement(time);
|
---|
42 | weightedSum += addCnt;
|
---|
43 | if (!weightedCnt.containsKey(sender)) {
|
---|
44 | weightedCnt.put(sender, addCnt);
|
---|
45 | } else {
|
---|
46 | weightedCnt.put(sender, weightedCnt.get(sender) + addCnt);
|
---|
47 | }
|
---|
48 | }
|
---|
49 |
|
---|
50 | static final int DownLiner = 0;
|
---|
51 |
|
---|
52 | public double calWeightedIncrement(double time) {
|
---|
53 | double ans = 0.0;
|
---|
54 | switch (selectWeight) {
|
---|
55 | case DownLiner:
|
---|
56 | ans = 1.0 - time;
|
---|
57 | break;
|
---|
58 | default:
|
---|
59 | System.out.println("ERROR: 想定外の重み関数が指定されました。");
|
---|
60 | }
|
---|
61 | return ans;
|
---|
62 | }
|
---|
63 |
|
---|
64 | public int getSimpleCnt(Object sender) {
|
---|
65 | if (simpleCnt.containsKey(sender)) {
|
---|
66 | return simpleCnt.get(sender);
|
---|
67 | } else {
|
---|
68 | return 0;
|
---|
69 | }
|
---|
70 | }
|
---|
71 |
|
---|
72 | public int getSimpleSum() {
|
---|
73 | return simpleSum;
|
---|
74 | }
|
---|
75 |
|
---|
76 | public double getWeightedCnt(Object sender) {
|
---|
77 | if (weightedCnt.containsKey(sender)) {
|
---|
78 | return weightedCnt.get(sender);
|
---|
79 | } else {
|
---|
80 | return 0.0;
|
---|
81 | }
|
---|
82 | }
|
---|
83 |
|
---|
84 | public double getWeightedSum() {
|
---|
85 | return weightedSum;
|
---|
86 | }
|
---|
87 |
|
---|
88 | public boolean isContainOpponents(Object sender) {
|
---|
89 | return opponents.contains(sender);
|
---|
90 | }
|
---|
91 |
|
---|
92 | }
|
---|