-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAgent.java
More file actions
89 lines (71 loc) · 1.92 KB
/
Copy pathAgent.java
File metadata and controls
89 lines (71 loc) · 1.92 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
import java.util.ArrayList;
public class Agent {
private int myID;
private double amtWheat;
private double amtCash;
private double delta;
private double exponent;
public Agent(){}
public Agent(int id){
myID = id;
amtWheat = Math.random(); //usually replaced later
amtCash = 1 - amtWheat; //usually replaced later
delta = Math.random();
if(id<500){
exponent = 0.25;
} else {
exponent = 0.75;
}
}
public void setWheat(double wheat){
amtWheat = wheat;
}
public void setCash(double cash){
amtCash = cash;
}
public double getWheat(){
return amtWheat;
}
public double getCash(){
return amtCash;
}
public int getID(){
return myID;
}
public double getUtility(){
return findUtility(amtCash, amtWheat);
}
public double findUtility(double cash, double wheat){
return Math.pow(wheat, 1-exponent)*Math.pow(cash, exponent);
}
public double findChangeInUtility(double dCash, double dWheat, boolean buyer){
if(buyer){
return Math.pow(amtCash-dCash, exponent)*Math.pow(amtWheat+dWheat, 1-exponent);
} else {
return Math.pow(amtCash+dCash, exponent)*Math.pow(amtWheat-dWheat, 1-exponent);
}
}
public double getDelta(){
return delta;
}
public double getExponent(){
return exponent;
}
/**
* This method gives you the rounded amount of some divided amount of
* cash or wheat (depending on the argument).
* Ex. If you want half of the cash, it will give you the rounded amount
* of half of the cash
*/
public double getRoundedAmount(double numToDivide, boolean cash){
if(cash){
return ((double)Math.round(this.getCash()/numToDivide*10000.0))/10000.0;
} else {
return ((double)Math.round(this.getWheat()/numToDivide*10000.0))/10000.0;
}
}
public void printInfo(){
System.out.printf("Agent "+ this.getID() + " has %.4f amount of cash, %.4f amount of wheat, and a %.4f exponent.", this.getCash(), this.getWheat(), this.getExponent());
System.out.println();
}
}