forked from sudheesh001/YahooHackIndia
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSimulator.java
More file actions
107 lines (90 loc) · 2.78 KB
/
Simulator.java
File metadata and controls
107 lines (90 loc) · 2.78 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
103
104
105
106
107
package gpfinance;
import gpfinance.algorithm.GP;
import gpfinance.datatypes.*;
import gpfinance.tree.*;
/**
* @date 14-July-2013
* @author Sudheesh Singanamalla
*/
public class Simulator extends Thread {
private String[] args = null;
public Simulator(String[] args) { this.args = args; }
@Override
public void run() {
// Parse
// TODO parse this.args and create appropriate GP() and run it
// Dispatch
GP algorithm = new GP();
algorithm.run();
}
public void test() {
Test test = new Test(args);
}
private class Test {
public Test(String[] args) {
// Parse args
String c = "";
for (String s : args) {
c += s + " ";
}
// Dispatch
if (c.contains("all")) {
testDataTypes();
testTree();
testRandomGenerators();
}
if (c.contains("datatypes")) {
testDataTypes();
}
if (c.contains("tree")) {
testTree();
}
if (c.contains("random")) {
testRandomGenerators();
}
}
private void testDataTypes() {
U.m("\n*** Testing data types");
Decision[] decisions = {Decision.BUY, Decision.SELL};
for (Decision d : decisions) {
U.m(d);
}
Indicator[] techInd = {Tech.EXAMPLE};
Indicator[] fundInd = {Fund.RAD};
for (int i = 0; i < 5; ++i) {
U.m(Fund.getRandom());
}
for (Indicator d : techInd) {
U.m(d);
}
for (Indicator d : fundInd) {
U.m(d);
}
}
private void testTree() {
// init tree
U.m("\n*** Testing trees");
DecisionTree tree = new DecisionTree('F', 5);
// size
U.m("Size: " + tree.size());
U.m("Avg depth: " + tree.avgDepth());
// print
U.m("Print tree");
tree.print();
U.m("Finding random positions in tree...");
Node[] nodes;
for (int i = 0; i < 3; ++i){
nodes = tree.getRandomNonTerminalNode();
U.m(i + " - FINAL FOUND: prev=\"" + nodes[0] + "\", node=\"" + nodes[1] + "\"");
}
//trunc
//
}
private void testRandomGenerators() {
U.m("\n*** Testing random");
for (int i = 0; i < 10; ++i) {
U.m(U.randomVal());
}
}
}
}