source: src/main/java/parties/in4010/q12015/group12/OtherAgent.java@ 126

Last change on this file since 126 was 1, checked in by Wouter Pasman, 6 years ago

Initial import : Genius 9.0.0

File size: 2.6 KB
Line 
1package parties.in4010.q12015.group12;
2
3import java.util.HashMap;
4import java.util.List;
5
6import genius.core.Bid;
7import genius.core.BidHistory;
8import genius.core.bidding.BidDetails;
9import genius.core.issue.ISSUETYPE;
10import genius.core.issue.Issue;
11import genius.core.issue.IssueDiscrete;
12import genius.core.issue.Value;
13import genius.core.issue.ValueDiscrete;
14
15public 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}
Note: See TracBrowser for help on using the repository browser.