source: src/main/java/agents/anac/y2018/agentherb/VectorConverter.java@ 345

Last change on this file since 345 was 343, checked in by Tim Baarslag, 4 years ago

Fixed all errors in all 2018 agents

File size: 3.2 KB
Line 
1package agents.anac.y2018.agentherb;
2
3import java.util.List;
4
5import genius.core.Bid;
6import genius.core.Domain;
7import genius.core.issue.Issue;
8import genius.core.issue.IssueDiscrete;
9import genius.core.issue.IssueInteger;
10import genius.core.issue.ValueDiscrete;
11import genius.core.issue.ValueInteger;
12
13public class VectorConverter {
14 /**
15 * Convert a bid to vector
16 *
17 * First add to vector a value of one (bias)
18 *
19 * Then for each issue of the bid if its an integer change it to range between 0 to 1 and add it to the vector
20 * if it is discrete for each possible value add a value to the vector -
21 * 0 if the issue is not the value and 1 if it is the value
22 * For example discrete issue of color with possible value blue, green and yellow and the real value is green
23 * we will add to the vector [0,1,0]
24 *
25 * @param bid The bid to convert
26 * @return The vector from the bid
27 */
28 public Vector convert(Bid bid) {
29 List<Issue> issues = bid.getIssues();
30 Vector vector = new Vector();
31 vector.add(1.0);
32 for (Issue issue : issues) {
33 if (issue instanceof IssueInteger) {
34 vector.add(this.convertInteger((IssueInteger) issue, bid));
35 } else {
36 vector.addAll(this.convertDiscrete((IssueDiscrete) issue, bid));
37 }
38 }
39
40 return vector;
41 }
42
43 /**
44 * @param domain The domain of the negotiation
45 * @return The size of the vector
46 */
47 public int getVectorSize(Domain domain) {
48 int vectorSize = 1;
49 for (Issue issue : domain.getIssues()) {
50 if (issue instanceof IssueInteger) {
51 vectorSize++;
52 } else {
53 IssueDiscrete issueDiscrete = (IssueDiscrete) issue;
54 vectorSize += issueDiscrete.getNumberOfValues();
55 }
56 }
57 return vectorSize;
58 }
59
60 /**
61 * @param value The value to normalize
62 * @param upperBound The upper bound of the value
63 * @param lowerBound The lower bound of the value
64 * @return The value between 0 to 1
65 */
66 private double normalize(int value, int upperBound, int lowerBound) {
67 return (double)(value - lowerBound) / (double)(upperBound - lowerBound);
68 }
69
70 /**
71 * @param issue The issue to convert
72 * @param bid The bid of the issue
73 * @return The converted integer
74 */
75 private double convertInteger(IssueInteger issue, Bid bid) {
76 ValueInteger valueInteger = (ValueInteger) bid.getValue(issue.getNumber());
77 return this.normalize(valueInteger.getValue(), issue.getUpperBound(),
78 issue.getLowerBound());
79 }
80
81 /**
82 * @param issueDiscrete The issue to convert
83 * @param bid The bid of the issue
84 * @return The converted discrete
85 */
86 private Vector convertDiscrete(IssueDiscrete issueDiscrete, Bid bid) {
87 Vector vector = new Vector();
88 for (ValueDiscrete valueDiscrete : issueDiscrete.getValues()) {
89 if (bid.getValue(issueDiscrete.getNumber()).equals(valueDiscrete)) {
90 vector.add(1.0);
91 }
92 else {
93 vector.add(0.0);
94 }
95 }
96 return vector;
97 }
98}
Note: See TracBrowser for help on using the repository browser.