Print

Print


Hi,

How about using a hash table to implement the variable lookup? i.e. your 
Variable class just holds a single String and calls 
myProblem.getVariable(stringName) etc. to retrieve a value, or 
myProblem.setVariable(stringName,newValue) to modify the value.

Not as fast as an array but maybe easier to debug?

Is it also possible to make this parameter-based:

e.g.

ec.problem.MyProblem.num_variables = 10
ec.problem.MyProblem.variables.0 = tmp_i
ec.problem.MyProblem.variables.1 = loop_index
...
ec.problem.MyProblem.variables.9 = etc.

...and then modify ECJ to add instances of your Variable class for each 
variable name before a run begins?  I guess Sean would know the place 
best way of doing this.

If you're using strong typing, you'll need a separate hash table for 
each type of variable you're using, and then either one Variable class 
per type or else a "type" parameter and corresponding changes to your 
Variable and Problem classes.

David

Sean Luke wrote:
> Vlad Palnik wrote:
>
>> 1 Has anyone found a solution which avoids
>> building a unique class for every variable in
>> a problem.  Say you have over a thousand
>> variables, is there a way to define a single
>> class which returns different variables ???
>> (I believe this is partly due to how java works)
>
> I'm not sure what you mean by 'variable' here, but let's assume you 
> mean something like the 'X' in Symbolic Regression.  The answer is: 
> sure, of course.  Instead of an X.java and Y.java etc., just make a 
> Variable.java file.  In this file, make a subclass of ERC.java.
>
> You're responsible for creating at least the resetNode(), encode(), 
> and nodeEquals() methods, and probably will want to define the 
> toString() method too.  Your ERC's value will be an integer from 
> 0..N-1 where N is the number of variables.  You'd store that value as 
> an instance variable.  Your toString() method etc. would likely print 
> out not the number but a pretty version of the variable (printing out 
> 'X' instead of 1, 'Y' instead of 2, etc.).
>
> Now we just have a global array, of size N, stored in your Problem 
> class.  Each slot holds the current value of one of the variables.  
> When your method is evaluated, you just go to that slot and return its 
> value.
>
> Sean

-- 
David R White
Research Student
Dept. of Computer Science
University of York, 
Heslington, YO10 5DD