This is what I did to make ECJ run multiple times :
Following the instructions of Gabriel Balan:
In Log.java
protected void finalize() throws Throwable
{
// rarely happens though... :-(
super.finalize();
//if (writer!=null) writer.close();
}
In Output.java
public synchronized void close()
{
// just in case
flush();
/* Enumeration e = logs.elements();
while(e.hasMoreElements())
{
Log log = (Log)e.nextElement();
log.writer.close();
} */
}
And this is what I did instead of commenting the "has been defined "test":
In Evolve.java, make() :
ec.gp.GPNodeConstraints.constraints = new
ec.gp.GPNodeConstraints[128];
ec.gp.GPNodeConstraints.all.clear();
ec.gp.GPNodeConstraints.numConstraints = 0 ;
ec.gp.GPTreeConstraints.constraints = new
ec.gp.GPTreeConstraints[ec.gp.GPTreeConstraints.SIZE_OF_BYTE];
ec.gp.GPTreeConstraints.all.clear();
ec.gp.GPTreeConstraints.numConstraints = 0 ;
ec.gp.GPFunctionSet.all.clear();
ec.gp.GPType.all.clear();
ec.gp.GPType.numAtomicTypes = ec.gp.GPType.numSetTypes = 0;
ec.rule.RuleConstraints.all.clear();
ec.rule.RuleConstraints.constraints = new
ec.rule.RuleConstraints[ec.rule.RuleConstraints.SIZE_OF_BYTE];
ec.rule.RuleConstraints.numConstraints = 0;
ec.rule.RuleSetConstraints.all.clear();
ec.rule.RuleSetConstraints.constraints = new
ec.rule.RuleSetConstraints[ec.rule.RuleSetConstraints.SIZE_OF_BYTE];
ec.rule.RuleSetConstraints.numConstraints = 0;
That's all, the only disadvantage is that out.stat only gets the last run,
but that's probably fixed if you change in the code to append. In my project
I don't need the out.stat, so, If I want to see what's going on, I just type
tail -f out.stat
The simplicity of the fix (just cleaning the static hashtables and counters)
makes me think that's not all I need to do, however, I made a test program
that runs 20 times "ec/app/regression/erc.params", in the 20 runs I got the
same results:
Fitness: Raw=0.46352753 Adjusted=0.6832806 Hits=7
Fitness: Raw=0.46352753 Adjusted=0.6832806 Hits=7
Fitness: Raw=0.46352753 Adjusted=0.6832806 Hits=7
..
..
Fitness: Raw=0.46352753 Adjusted=0.6832806 Hits=7
And also the same best individual.
So? Is there any other side effects of thing this?
Can we now parallelize the process?
|