-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSealed.java
More file actions
102 lines (73 loc) · 2.21 KB
/
Sealed.java
File metadata and controls
102 lines (73 loc) · 2.21 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
package bid;
public class Sealed {
public static double roundDec(double num) {
num = (double) Math.round(num*100)/100;
return num;
}
public static void toString(double[] bids) {
String str = "[";
for(int i=0; i<bids.length-1; i++) {
str += bids[i] + ", ";
}
str += bids[bids.length-1] + "]";
System.out.println(str);
}
public static double[] randPrivateVal() {
// each index represents one bidder
double[] bids = new double[5];
// each bidder's private valuation generated
// independently over [0,10]
for(int i=0; i<bids.length; i++) {
double valuation = roundDec(Math.random()*11);
bids[i] = valuation;
}
return bids;
}
public static double[] shadeBid(double[] privateVal, double x) {
double[] shaded = new double[5];
for(int i=0; i<privateVal.length; i++) {
shaded[i] = roundDec(privateVal[i]*x);
//System.out.println("Originally " + privateVal[i] + " bid " + x +" of valuation at " + shaded[i]);
}
return shaded;
}
public static int maxBidder(double[] valuations) {
double privateVal = 0;
int winner = 0;
for(int i=0; i<valuations.length; i++) {
if(valuations[i] >= privateVal) {
privateVal = valuations[i];
winner = i;
}
}
//System.out.println("Max bidder is " + winner + " of " + privateVal);
return winner;
}
public static void simulation(double[] perc) {
double revenue = 0;
double bidderSurplus = 0;
for(int j=0; j<perc.length; j++) {
System.out.println("When x is " + perc[j]);
for(int i=0; i<500; i++) {
//System.out.println("Simulation " + i);
double[] privVal = randPrivateVal();
double[] shaded = shadeBid(privVal, perc[j]);
//toString(shaded);
int winner = maxBidder(shaded);
double surplus = privVal[winner] - shaded[winner];
bidderSurplus += surplus;
revenue += shaded[winner];
// System.out.println("");
}
bidderSurplus = roundDec((bidderSurplus/500));
revenue = roundDec((revenue/500));
System.out.println("Average total bidder surplus " + bidderSurplus);
System.out.println("Average total seller revenue " + revenue);
System.out.println("");
}
}
public static void main(String[] args) {
double[] per = {0.90, 0.80, 0.70, 0.60, 0.50};
simulation(per);
}
}