source: src/main/java/agents/ai2014/group3/BidGenerator.java@ 126

Last change on this file since 126 was 126, checked in by Aron Hammond, 6 years ago

Added function to calculate opposition to MultiLateralAnalysis.java

Moved code to add RLBOA listeners to RLBOAUtils is misc package

Added input for strategyParameters to SessionPanel (gui)

!! close SessionInfo after tournament; this caused /tmp/ to fill up with GeniusData files

Our own package:

  • Added opponents and strategies that are mentioned in the report
  • Change class hierarchy, agents can now extend from RLBOAagentBilateral to inherit RL functionality.
  • States extend from AbstractState
File size: 4.3 KB
Line 
1package agents.ai2014.group3;
2
3import java.util.ArrayList;
4import java.util.HashMap;
5import java.util.List;
6import java.util.Set;
7
8import genius.core.Bid;
9import genius.core.issue.Issue;
10import genius.core.issue.IssueDiscrete;
11import genius.core.issue.Value;
12import genius.core.issue.ValueDiscrete;
13import genius.core.utility.AdditiveUtilitySpace;
14import genius.core.utility.EvaluatorDiscrete;
15
16public class BidGenerator {
17
18 // Just static methods
19 private BidGenerator() {
20 super();
21 }
22
23 // Unused
24 // retreives the value with the highest evaluation for this Issue
25 public static Value getMaxValue(EvaluatorDiscrete Eval) {
26 double currentValue = 0;
27 ValueDiscrete maxvalue = null;
28 double maxevaluated = 0;
29
30 Set<ValueDiscrete> valueSet = Eval.getValues();
31 for (ValueDiscrete value : valueSet) {
32 try {
33 currentValue = Eval.getEvaluation(value);
34 if (maxevaluated < currentValue) {
35 maxevaluated = currentValue;
36 maxvalue = value;
37 }
38 } catch (Exception e) {
39 e.printStackTrace();
40 }
41 }
42 return maxvalue;
43 }
44
45 // Generates a List with the utility of the list of bids it receives
46 public static double[] utilitylist(ArrayList<Bid> bids, Group3 info) {
47
48 double[] utilityarray = new double[bids.size()];
49
50 for (int i = 0; i < bids.size(); i++) {
51 utilityarray[i] = info.getUtility(bids.get(i));
52 }
53
54 return utilityarray;
55 }
56
57 // Generates a List of all possible bids in this UtilitySpace
58 public static ArrayList<Bid> BidList(AdditiveUtilitySpace utilitySpace) {
59 List<Issue> issueList = utilitySpace.getDomain().getIssues();
60 ArrayList<ArrayList<ValueDiscrete>> listValueList = new ArrayList<ArrayList<ValueDiscrete>>();
61 ArrayList<Bid> bidList = new ArrayList<Bid>();
62 int bidListsize = 1;
63 int nIssues = issueList.size();
64 int[] nValues = new int[nIssues];
65 for (int i = 0; i < issueList.size(); i++) {
66 listValueList
67 .add((ArrayList<ValueDiscrete>) ((IssueDiscrete) issueList
68 .get(i)).getValues());
69 nValues[i] = listValueList.get(i).size();
70 bidListsize = bidListsize * nValues[i];
71 }
72 ValueDiscrete[][] valueMatrix = new ValueDiscrete[bidListsize][nIssues];
73 for (int i = 0; i < nIssues; i++) {
74 int before = 1, actual = nValues[i], after = 1;
75 for (int k = 0; k < i; k++) {
76 before = before * nValues[k];
77 }
78 for (int k = nIssues - 1; k > i; k--) {
79 after = after * nValues[k];
80 }
81 for (int j = 0; j < before; j++) {
82 for (int k = 0; k < actual; k++) {
83 for (int l = 0; l < after; l++) {
84 valueMatrix[l + actual * after * j + k * after][i] = listValueList
85 .get(i).get(k);
86 }
87 }
88 }
89
90 }
91 for (int i = 0; i < bidListsize; i++) {
92 HashMap<Integer, Value> bidMap = new HashMap<Integer, Value>();
93 for (int j = 0; j < nIssues; j++) {
94 bidMap.put(issueList.get(j).getNumber(), valueMatrix[i][j]);
95 }
96 Bid currentBid;
97 try {
98 currentBid = new Bid(utilitySpace.getDomain(), bidMap);
99 bidList.add(currentBid);
100 } catch (Exception e) {
101 e.printStackTrace();
102 }
103 }
104 return bidList;
105 }
106
107 /*
108 * Returns ArrayList of Bids within the range given, if there isn't any
109 * returns closest Bid with higher utility, If still there isn't any will
110 * return Bid with closest lower utility. If there isn't any will return an
111 * empty ArrayList
112 */
113 public static ArrayList<Bid> getBidsInRange(ArrayList<Bid> bids,
114 double low_bound, double up_bound, Group3 info) {
115 ArrayList<Bid> bidsInRange = new ArrayList<Bid>();
116 // No bids
117 if (bids.isEmpty())
118 return bidsInRange;
119 for (int i = 0; i < bids.size(); i++) {
120 if (low_bound < info.getUtility(bids.get(i))
121 && up_bound > info.getUtility(bids.get(i))) {
122 bidsInRange.add(bids.get(i));
123 }
124 }
125 if (bidsInRange.isEmpty()) {
126 // There are none within range, search for larger than range
127 for (int i = 0; i < bids.size(); i++) {
128 if (low_bound < info.getUtility(bids.get(i))) {
129 bidsInRange.add(bids.get(i));
130 }
131 }
132 }
133 if (bidsInRange.isEmpty()) {
134 // There are none inside or larger than range, search for closest
135 // smaller
136 double distance = Double.MAX_VALUE;
137 Bid closestBid = null;
138 for (int i = 0; i < bids.size(); i++) {
139 if (distance > low_bound - info.getUtility(bids.get(i))) {
140 closestBid = bids.get(i);
141 distance = low_bound - info.getUtility(bids.get(i));
142 }
143 }
144 bidsInRange.add(closestBid);
145 }
146 return bidsInRange;
147
148 }
149}
Note: See TracBrowser for help on using the repository browser.