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