source: src/main/java/agents/anac/y2015/JonnyBlack/Functions.java@ 1

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

Initial import : Genius 9.0.0

File size: 3.6 KB
Line 
1package agents.anac.y2015.JonnyBlack;
2
3import java.util.Vector;
4
5import genius.core.Bid;
6import genius.core.issue.IssueDiscrete;
7import genius.core.issue.ValueDiscrete;
8import genius.core.utility.AdditiveUtilitySpace;
9
10public class Functions {
11 public static int[] calcOrderOfIssues(AdditiveUtilitySpace us) {
12 int noOfIssues = us.getNrOfEvaluators();
13 int[] issueOrder = new int[noOfIssues];
14 for (int i = 0; i < issueOrder.length; i++) {
15 issueOrder[i] = i;
16 }
17 for (int i = 0; i < issueOrder.length; i++) {
18 for (int j = i + 1; j < issueOrder.length; j++) {
19 if (us.getWeight(issueOrder[i]) < us.getWeight(issueOrder[j])) {
20 int temp = issueOrder[i];
21 issueOrder[i] = issueOrder[j];
22 issueOrder[j] = temp;
23 }
24 }
25 }
26 return issueOrder;
27 }
28
29 public static int[][] calcOrderOfIssueVals(AdditiveUtilitySpace us) {
30 int noOfIssues = us.getNrOfEvaluators();
31 int[][] orderOfVals = new int[noOfIssues][];
32 for (int i = 0; i < noOfIssues; i++) {
33 int noVals = ((IssueDiscrete) (us.getIssue(i))).getNumberOfValues();
34 orderOfVals[i] = new int[noVals];
35 }
36 for (int i = 0; i < orderOfVals.length; i++) {
37 for (int j = 0; j < orderOfVals[i].length; j++) {
38 orderOfVals[i][j] = j + 1;
39 }
40 }
41 // TODO Not Ordering
42 for (int i = 0; i < orderOfVals.length; i++) {
43 for (int j = 0; j < orderOfVals[i].length; j++) {
44 double value1 = getValueOfIssueVal(us, i, j);
45 for (int k = j; k < orderOfVals[i].length; k++) {
46 double value2 = getValueOfIssueVal(us, i, k);
47 if (value1 < value2) {
48 int t = orderOfVals[i][j];
49 orderOfVals[i][j] = orderOfVals[i][k];
50 orderOfVals[i][k] = t;
51 }
52 }
53 }
54 }
55 return orderOfVals;
56 }
57
58 public static double getValueOfIssueVal(AdditiveUtilitySpace us, int issue, int val) {
59 Bid temp = getCopyOfBestBid(us);
60 ValueDiscrete vd = getVal(us, issue, val);
61 temp = temp.putValue(issue + 1, vd);
62 double value = evaluateOneIssue(us, issue, temp);
63 return value;
64 }
65
66 public static ValueDiscrete getVal(AdditiveUtilitySpace us, int issue, int valID) {
67 IssueDiscrete is = (IssueDiscrete) us.getIssue(issue);
68 return is.getValue(valID);
69 }
70
71 public static double evaluateOneIssue(AdditiveUtilitySpace us, int issue, Bid b) {
72 try {
73 return us.getEvaluator(issue + 1).getEvaluation(us, b, issue + 1);
74 } catch (Exception e) {
75 e.printStackTrace();
76 }
77 return -1;
78 }
79
80 public static Bid getCopyOfBestBid(AdditiveUtilitySpace us) {
81 try {
82 return new Bid(us.getMaxUtilityBid());
83 } catch (Exception e) {
84 e.printStackTrace();
85 }
86 return null;
87 }
88
89 public static double getBidValue(AdditiveUtilitySpace us, Bid b) {
90 try {
91 return us.getUtility(b);
92 } catch (Exception e) {
93 // TODO Auto-generated catch block
94 e.printStackTrace();
95 }
96 return -1;
97 }
98
99 public static double calcStopVal(Vector<Party> parties, int n,
100 AdditiveUtilitySpace us) {
101 for (Party p : parties) {
102 p.orderBids(us);
103 }
104 Vector<BidHolder> topNbids = new Vector<BidHolder>();
105 for (int i = 0; i < n && i < parties.get(0).orderedBids.size(); i++) {
106 topNbids.add(parties.get(0).orderedBids.get(i));
107 }
108 for (int i = 0; i < topNbids.size(); i++) {
109 for (Party p : parties) {
110 if (p.orderedBids.indexOf(topNbids.get(i)) > n
111 || p.orderedBids.indexOf(topNbids.get(i)) == -1) {
112 topNbids.remove(i);
113 i--;
114 break;
115 }
116 }
117 }
118 System.out.println("Common Bids : " + topNbids.size());
119 double max = 0;
120 for (BidHolder b : topNbids) {
121 double v = Functions.getBidValue(us, b.b);
122 if (v > max)
123 max = v;
124 }
125 return Math.max(max, 0.6);
126 }
127}
Note: See TracBrowser for help on using the repository browser.