1 | This package contains auxillary utility classes and functions used by ECJ, but |
---|
2 | which can easily be used by other Java libraries and are not specific to ECJ. |
---|
3 | |
---|
4 | |
---|
5 | LOGGING FACILITY |
---|
6 | ---------------- |
---|
7 | |
---|
8 | When ECJ was first developed (in 1998) there was no Java logging facility, no |
---|
9 | log4j, etc. So I rolled my own, largely a copy of the one in lil-gp. The |
---|
10 | facility has proven fairly robust, so we've kept it over the years. The |
---|
11 | facility has a basic class: |
---|
12 | |
---|
13 | ec.util.Output |
---|
14 | |
---|
15 | ... which does most of the logging work. Output holds one or more *logs*, |
---|
16 | defined by |
---|
17 | |
---|
18 | ec.util.Log |
---|
19 | |
---|
20 | ... which are largely (but not required to be) wrappers around streams to |
---|
21 | standard out, standard err, or various files. Output then allows you to print |
---|
22 | to these logs, or to issue "announcements" to them. An announcement is |
---|
23 | different from an ordinary print statement in that it is also stored in memory |
---|
24 | permanently, and so gets checkpointed. When a log is restarted from |
---|
25 | checkpoint, all of its announcements can be reissued to the log; that's how |
---|
26 | ECJ prints all of its stuff out to the terminal again when restarting from |
---|
27 | checkpoint. Beware that because announcements are stored in memory as well as |
---|
28 | printed out, if you issue too many of them, you'll fill up memory excessively. |
---|
29 | Announcements are all subclasses |
---|
30 | |
---|
31 | ec.util.Announcement |
---|
32 | |
---|
33 | Logs restart themselves from checkpoint using a small class: |
---|
34 | |
---|
35 | ec.util.LogRestarter |
---|
36 | |
---|
37 | When output generates exceptions, usually pertaining to writing to Logs, it |
---|
38 | does so with an OutputException |
---|
39 | |
---|
40 | ec.util.OutputExcption |
---|
41 | |
---|
42 | |
---|
43 | |
---|
44 | RANDOM NUMBER GENERATORS |
---|
45 | ------------------------ |
---|
46 | |
---|
47 | ECJ's random number generator is a Java implementation of the Mersenne Twister |
---|
48 | random number generator which I wrote in 1998. It's still a popular |
---|
49 | implementation of the Mersenne Twister algorithm, largely because it's quite |
---|
50 | fast. ECJ has two versions of the algorithm but only uses one: |
---|
51 | MersenneTwisterFast: |
---|
52 | |
---|
53 | ec.util.MersenneTwister |
---|
54 | |
---|
55 | A drop-in subclass replacement for java.util.Random which uses the |
---|
56 | Mersenne Twister algorithm instead. |
---|
57 | |
---|
58 | ec.util.MersenneTwisterFast |
---|
59 | |
---|
60 | Algorithmically identical to ec.util.MersenneTwister, but without |
---|
61 | synchronization, and with a lot of hard-code-inlined methods. As |
---|
62 | a result much harder to read and understand, but over twice as fast. |
---|
63 | |
---|
64 | |
---|
65 | PARAMETER DATABASE |
---|
66 | ------------------ |
---|
67 | |
---|
68 | ECJ's parameter database facility was also built from scratch at a time when |
---|
69 | Java had no other built-in facilities available. The parameter database is |
---|
70 | built on top of Java's Properties class, but adds the additional functionality |
---|
71 | of multiple files with inheritance, plus command-line properties and dynamic |
---|
72 | properties. The primary class is |
---|
73 | |
---|
74 | ec.util.ParameterDatabase |
---|
75 | |
---|
76 | ... which loads properties from various files and stores them internally for |
---|
77 | you to query at runtime. To query for a property, you create a Parameter |
---|
78 | (a wrapper for String, used instead of String for entirely historical reasons). |
---|
79 | You then issue the Parameter to the ParameterDatabase and get the corresponding |
---|
80 | value. Parameters are defined with: |
---|
81 | |
---|
82 | ec.util.Parameter |
---|
83 | |
---|
84 | When there is an exception upon creating a Parameter, a BadParameterException |
---|
85 | is thrown: |
---|
86 | |
---|
87 | ec.util.BadParameterException |
---|
88 | |
---|
89 | When you use a Parameter to attempt to load and and initialize a class from |
---|
90 | the ParameterDatabase, and something failed on that attempt, a |
---|
91 | ParamClassLoadException is called: |
---|
92 | |
---|
93 | ec.util.ParamClassLoadException |
---|
94 | |
---|
95 | The GUI facility of ECJ has additional classes meant to access parameters |
---|
96 | programmatically in Swing. Generally you wouldn't play with these: |
---|
97 | |
---|
98 | ec.util.ParameterDatabaseEvent |
---|
99 | ec.util.ParameterDatabaseTreeModel |
---|
100 | ec.util.ParameterDatabaseTreeNode |
---|
101 | ec.util.ReflectedObject |
---|
102 | |
---|
103 | |
---|
104 | |
---|
105 | READING, WRITING, CHECKPOINTING, AND NETWORKING |
---|
106 | ----------------------------------------------- |
---|
107 | |
---|
108 | Many ECJ objects (notably Individuals) have the ability to write themselves |
---|
109 | out to a stream in a fashion that is both readable by humans (more or less) |
---|
110 | *and* can be read back in a way that maintains integrity. To do this they |
---|
111 | rely on ECJ's "Code" facility to encode and decode basic data elements. To |
---|
112 | encode data, you can use the Code class: |
---|
113 | |
---|
114 | ec.util.Code |
---|
115 | |
---|
116 | To decode data, you use the Code class in conjunction with a special object |
---|
117 | which gives you additional information about the decoded data. This special |
---|
118 | object is called a DecodeReturn: |
---|
119 | |
---|
120 | ec.util.DecodeReturn |
---|
121 | |
---|
122 | In certain rare situations ECJ finds that it needs to be able to hook a |
---|
123 | DataOutputStream directly to a DataInputStream. Surprisingly, Java cannot |
---|
124 | provide this facility without using two threads (to enable the PipedInputStream |
---|
125 | and PipedOutputStream). ECJ's solution is a buffered single-thread pipe called |
---|
126 | DataPipe: |
---|
127 | |
---|
128 | ec.util.DataPipe |
---|
129 | |
---|
130 | ECJ implements checkpointing of runs via Java's serialization facility. The |
---|
131 | cover class which handles this work is called Checkpoint: |
---|
132 | |
---|
133 | ec.util.Checkpoint |
---|
134 | |
---|
135 | Last, a long-standing bug in Java prevents proper lookup of localhost sockets. |
---|
136 | This is fixed using a class from Jakarta called LocalHost: |
---|
137 | |
---|
138 | ec.util.LocalHost |
---|
139 | |
---|
140 | |
---|
141 | |
---|
142 | MANIPULATING ARRAYS |
---|
143 | ------------------- |
---|
144 | |
---|
145 | Largely for historical reasons, ECJ has its own quicksort facilities. We keep |
---|
146 | these facilities because, quite surprisingly, Java's current sorting facilities |
---|
147 | are very much insufficient. ECJ's basic class for sorting is QuickSort: |
---|
148 | |
---|
149 | ec.util.QuickSort |
---|
150 | |
---|
151 | QuickSort relies on a special Comparator object for determining whether two |
---|
152 | objects are greater or less than one another. This is mostly for historical |
---|
153 | reasons. There is also a special version of this object for longs: |
---|
154 | |
---|
155 | ec.util.SortComparator |
---|
156 | ec.util.SortComparatorL |
---|
157 | |
---|
158 | ECJ can convert arrays of floats, doubles, or arbitrary objects, into |
---|
159 | distributions and then select random numbers under them (treating the |
---|
160 | values in the arrays as actual prenormalized probabilities). The primary class |
---|
161 | for this is RandomChoice: |
---|
162 | |
---|
163 | ec.util.RandomChoice |
---|
164 | |
---|
165 | RandomChoice can work with arrays of Objects as long as there's a provided |
---|
166 | object a RandomChoiceChooser, which provides the "probability" value for a |
---|
167 | given Object. There are two versions of RandomChoiceChooser, one which |
---|
168 | assumes probabilities are floats, and the other which assumes they are doubles |
---|
169 | (again, mostly for historical reasons): |
---|
170 | |
---|
171 | ec.util.RandomChoiceChooser |
---|
172 | ec.util.RandomChoiceChooserD |
---|
173 | |
---|
174 | |
---|
175 | |
---|
176 | SIMPLE LEXING (TOKENIZING) |
---|
177 | -------------------------- |
---|
178 | |
---|
179 | ECJ's Grammatical Evolution facility needs to lex simple rulesets, one per line, |
---|
180 | from a file. The following class makes regular-expression-based lexing simpler: |
---|
181 | |
---|
182 | ec.util.Lexer |
---|
183 | |
---|
184 | |
---|
185 | |
---|
186 | ECJ'S VERSION |
---|
187 | ------------- |
---|
188 | |
---|
189 | Information regarding the current version of ECJ is located in: |
---|
190 | |
---|
191 | ec.util.Version |
---|