source: src/main/java/agents/anac/y2015/TUDMixedStrategyAgent/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.anac.y2015.TUDMixedStrategyAgent;
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,
47 TUDMixedStrategyAgent info) {
48
49 double[] utilityarray = new double[bids.size()];
50
51 for (int i = 0; i < bids.size(); i++) {
52 utilityarray[i] = info.getUtility(bids.get(i));
53 }
54
55 return utilityarray;
56 }
57
58 // Generates a List of all possible bids in this UtilitySpace
59 public static ArrayList<Bid> BidList(AdditiveUtilitySpace utilitySpace) {
60 List<Issue> issueList = utilitySpace.getDomain().getIssues();
61 ArrayList<ArrayList<ValueDiscrete>> listValueList = new ArrayList<ArrayList<ValueDiscrete>>();
62 ArrayList<Bid> bidList = new ArrayList<Bid>();
63 int bidListsize = 1;
64 int nIssues = issueList.size();
65 int[] nValues = new int[nIssues];
66 for (int i = 0; i < issueList.size(); i++) {
67 listValueList
68 .add((ArrayList<ValueDiscrete>) ((IssueDiscrete) issueList
69 .get(i)).getValues());
70 nValues[i] = listValueList.get(i).size();
71 bidListsize = bidListsize * nValues[i];
72 }
73 ValueDiscrete[][] valueMatrix = new ValueDiscrete[bidListsize][nIssues];
74 for (int i = 0; i < nIssues; i++) {
75 int before = 1, actual = nValues[i], after = 1;
76 for (int k = 0; k < i; k++) {
77 before = before * nValues[k];
78 }
79 for (int k = nIssues - 1; k > i; k--) {
80 after = after * nValues[k];
81 }
82 for (int j = 0; j < before; j++) {
83 for (int k = 0; k < actual; k++) {
84 for (int l = 0; l < after; l++) {
85 valueMatrix[l + actual * after * j + k * after][i] = listValueList
86 .get(i).get(k);
87 }
88 }
89 }
90
91 }
92 for (int i = 0; i < bidListsize; i++) {
93 HashMap<Integer, Value> bidMap = new HashMap<Integer, Value>();
94 for (int j = 0; j < nIssues; j++) {
95 bidMap.put(issueList.get(j).getNumber(), valueMatrix[i][j]);
96 }
97 Bid currentBid;
98 try {
99 currentBid = new Bid(utilitySpace.getDomain(), bidMap);
100 bidList.add(currentBid);
101 } catch (Exception e) {
102 e.printStackTrace();
103 }
104 }
105 return bidList;
106 }
107
108 /*
109 * Returns ArrayList of Bids within the range given, if there isn't any
110 * returns closest Bid with higher utility, If still there isn't any will
111 * return Bid with closest lower utility. If there isn't any will return an
112 * empty ArrayList
113 */
114 public static ArrayList<Bid> getBidsInRange(ArrayList<Bid> bids,
115 double low_bound, double up_bound, TUDMixedStrategyAgent info) {
116 ArrayList<Bid> bidsInRange = new ArrayList<Bid>();
117 // No bids
118 if (bids.isEmpty())
119 return bidsInRange;
120 for (int i = 0; i < bids.size(); i++) {
121 if (low_bound < info.getUtility(bids.get(i))
122 && up_bound > info.getUtility(bids.get(i))) {
123 bidsInRange.add(bids.get(i));
124 }
125 }
126 if (bidsInRange.isEmpty()) {
127 // There are none within range, search for larger than range
128 for (int i = 0; i < bids.size(); i++) {
129 if (low_bound < info.getUtility(bids.get(i))) {
130 bidsInRange.add(bids.get(i));
131 }
132 }
133 }
134 if (bidsInRange.isEmpty()) {
135 // There are none inside or larger than range, search for closest
136 // smaller
137 double distance = Double.MAX_VALUE;
138 Bid closestBid = null;
139 for (int i = 0; i < bids.size(); i++) {
140 if (distance > low_bound - info.getUtility(bids.get(i))) {
141 closestBid = bids.get(i);
142 distance = low_bound - info.getUtility(bids.get(i));
143 }
144 }
145 bidsInRange.add(closestBid);
146 }
147 return bidsInRange;
148
149 }
150}
Note: See TracBrowser for help on using the repository browser.