1 | package parties.in4010.q12015.group12;
|
---|
2 |
|
---|
3 | import java.util.HashMap;
|
---|
4 | import java.util.List;
|
---|
5 |
|
---|
6 | import genius.core.Bid;
|
---|
7 | import genius.core.BidHistory;
|
---|
8 | import genius.core.bidding.BidDetails;
|
---|
9 | import genius.core.issue.ISSUETYPE;
|
---|
10 | import genius.core.issue.Issue;
|
---|
11 | import genius.core.issue.IssueDiscrete;
|
---|
12 | import genius.core.issue.Value;
|
---|
13 | import genius.core.issue.ValueDiscrete;
|
---|
14 |
|
---|
15 | public class OtherAgent {
|
---|
16 |
|
---|
17 | private double[] weights;
|
---|
18 | private BidHistory historyAgent;
|
---|
19 | private HashMap<Value, Integer> values;
|
---|
20 | private boolean agent;
|
---|
21 |
|
---|
22 | // constructor of agent
|
---|
23 | OtherAgent(String ID, int amountIssues) {
|
---|
24 | historyAgent = new BidHistory();
|
---|
25 | weights = new double[amountIssues];
|
---|
26 | values = new HashMap<Value, Integer>();
|
---|
27 | agent = false;
|
---|
28 |
|
---|
29 | for (int i = 0; i < amountIssues - 1; i++) {
|
---|
30 | weights[i] = (double) (1 / amountIssues);
|
---|
31 | }
|
---|
32 | }
|
---|
33 |
|
---|
34 | public double[] getWeights() {
|
---|
35 | return weights;
|
---|
36 | }
|
---|
37 |
|
---|
38 | public void setWeights(double[] newWeights, boolean bid) {
|
---|
39 | agent = bid;
|
---|
40 | weights = newWeights;
|
---|
41 | }
|
---|
42 |
|
---|
43 | // updates values by using received bid
|
---|
44 | // amount of time bided so far is in values (hashmap)
|
---|
45 | // increase when it is bided again
|
---|
46 | public void setValues(Bid bid) {
|
---|
47 | for (int i = 1; i < bid.getValues().size(); i++) {
|
---|
48 | Value v;
|
---|
49 | try {
|
---|
50 | v = bid.getValue(i);
|
---|
51 | if (!values.containsKey(v)) {
|
---|
52 | values.put(v, 1);
|
---|
53 | } else {
|
---|
54 | int amount = values.get(v);
|
---|
55 | amount++;
|
---|
56 | values.put(v, amount);
|
---|
57 | }
|
---|
58 | } catch (Exception e) {
|
---|
59 | e.printStackTrace();
|
---|
60 | }
|
---|
61 | }
|
---|
62 | }
|
---|
63 |
|
---|
64 | public BidHistory getHistory() {
|
---|
65 | if (historyAgent == null)
|
---|
66 | System.out.println("null");
|
---|
67 | return historyAgent;
|
---|
68 | }
|
---|
69 |
|
---|
70 | public void addBidDetails(BidDetails newDetails) {
|
---|
71 | historyAgent.add(newDetails);
|
---|
72 | }
|
---|
73 |
|
---|
74 | // we know for sure that this is an agent (because of doing a bid)
|
---|
75 | public boolean isAgent() {
|
---|
76 | return agent;
|
---|
77 | }
|
---|
78 |
|
---|
79 | // returns number of issue with highest believed weight for this agent
|
---|
80 | public int heighWeight() {
|
---|
81 | int issueNmr = 0;
|
---|
82 | double weight = 0.0;
|
---|
83 |
|
---|
84 | for (int i = 0; i < weights.length - 1; i++) {
|
---|
85 | if (weights[i] > weight) {
|
---|
86 | issueNmr = i;
|
---|
87 | weight = weights[i];
|
---|
88 | }
|
---|
89 | }
|
---|
90 | return issueNmr;
|
---|
91 | }
|
---|
92 |
|
---|
93 | // gets highest believed value for a certain issue
|
---|
94 | public Value getBestValue(int issueNmr, List<Issue> issues) {
|
---|
95 | Value vHighest = null;
|
---|
96 | int highest = 0;
|
---|
97 |
|
---|
98 | if (issues.get(issueNmr).getType() == ISSUETYPE.DISCRETE) {
|
---|
99 | IssueDiscrete dIssue = (IssueDiscrete) issues.get(issueNmr);
|
---|
100 | List<ValueDiscrete> valuesOfIssue = dIssue.getValues();
|
---|
101 |
|
---|
102 | vHighest = valuesOfIssue.get(0);
|
---|
103 |
|
---|
104 | for (ValueDiscrete v : valuesOfIssue) {
|
---|
105 | if (values.containsKey(v)) {
|
---|
106 | if (highest < values.get(v)) {
|
---|
107 | vHighest = v;
|
---|
108 | highest = values.get(v);
|
---|
109 | }
|
---|
110 | }
|
---|
111 | }
|
---|
112 | }
|
---|
113 |
|
---|
114 | return vHighest;
|
---|
115 | }
|
---|
116 |
|
---|
117 | }
|
---|