Hello Eric, I've managed to solve the issue with your help. For your information, I've created a singleton class with the problem information, which is instanciated before the population is initialized.

Thanks for your help.

2016-12-30 18:15 GMT-03:00 Eric 'Siggy' Scott <[log in to unmask]>:
Hello Enzo,

I created a minimum working example based on your parameter file, which allowed me to isolate the problem:

When the setup() method for VectorSpecies runs (this happens during subpopulation initialization), it initializes a "prototype" individual, which is used to create all future individuals by cloning.  What is happening is that, as the prototype is initialized, the Gene.reset() method is called on each gene.  But since the neither the species nor the population has finished being initialized, your reset() method throws NPE when it tries to access state.population.species.

I would recommend putting the special functionality you need for your data somewhere other than in the species.  I often put custom data-related functions in a custom copy or subclass of SimpleEvolutionState, for instance.  All you have to do is make sure that the object(s) that hold your data are initialized before the Population.

Siggy

On Fri, Dec 30, 2016 at 1:45 PM, Enzo Fabbiani <[log in to unmask]> wrote:
Here is my parameter file:

parent.0 = ../moosuite/moosuite.params
eval.problem = ec.app.BusStopRelocationProblem.BusStopRelocationProblem

generations = 10000
quit-on-run-complete = true

pop.subpop.0.size =                     50

pop.subpop.0.species = ec.vector.GeneVectorSpecies
pop.subpop.0.species.ind = ec.vector.GeneVectorIndividual
pop.subpop.0.species.gene = ec.app.BusStopRelocationProblem.BusProblemLine

pop.subpop.0.species.fitness.num-objectives = 2
pop.subpop.0.species.fitness.maximize = false

pop.subpop.0.species.genome-size = 7800
pop.subpop.0.species.crossover-type = one
pop.subpop.0.species.mutation-type = reset
pop.subpop.0.species.mutation-prob = 0.01

pop.subpop.0.species.pipe     = ec.vector.breed.VectorMutationPipeline
pop.subpop.0.species.pipe.likelihood         = 1.0
pop.subpop.0.species.pipe.source.0 = ec.vector.breed.VectorCrossoverPipeline
pop.subpop.0.species.pipe.source.0.likelihood = 0.75
pop.subpop.0.species.pipe.source.0.source.0 = ec.select.TournamentSelection
pop.subpop.0.species.pipe.source.0.source.1 = same
select.tournament.size = 2

seed.0 = time

Logging step by step state.population it seems to be null. However, this is the code of my reset method (inside my BusProblemLine class with extends from Gene):

setK(), getK() and addStop() are functions from the class and I believe is nos important in the NPE.


public void reset(EvolutionState state, int thread) {
final GeneVectorSpecies species = (GeneVectorSpecies) state.population.subpops[0].species;
DTMatrix[][] matrix = species.getMatrix();
Map<Integer, DTCoordinates> coordinates = species.getCoordinates();
Map<Integer, Integer> lines = species.getCorrelation();
for (Entry<Integer, Integer> entry : lines.entrySet()) {
int line = entry.getKey();
int posicion = entry.getValue();

this.line = line;
this.k = Parameters.getParameterInt("MaxQuantity");
Iterator<Integer> order = species.getorder().get(line).iterator();
while(order.hasNext()){
int aux = order.next();
if(matrix[posicion][aux] != null){
BusStop bps;
int down = 0;
int on = 0;
if (matrix[posicion][aux].getdown() > 0)
down = mt.nextInt(matrix[posicion][aux].getdown());
if (matrix[posicion][aux].geton() > 0)
on = mt.nextInt(matrix[posicion][aux].geton());
if(getK() >= (on - down)){
bps = new BusStop(on,down,aux,coordinates.get(aux).getLatitud(),coordinates.get(aux).getLogitud(),0); 
} else {
bps = new BusStop(getK() + down,down,aux,coordinates.get(aux).getLatitud(),coordinates.get(aux).getLogitud(),0); 
}
setK(getK()  + bps.getdown());
setK(getK()  - bps.geton());
addStop(bps);
}
}
}
}

Thanks a lot for your support.



2016-12-30 12:44 GMT-03:00 Eric 'Siggy' Scott <[log in to unmask]>:
Hmm.  That is odd, because, from what I can see, ECJ only calls the Gene.reset() method via the VectorSpecies class—so state.population.subpops[0].species should not be null at the time your method is called.

If you share your parameter file and the code for your reset() method I can see if any obvious issue jumps out to me as the cause for the NPE.

On Thu, Dec 29, 2016 at 4:08 PM, Enzo Fabbiani <[log in to unmask]> wrote:
Eric,

I was able to get access to problem information by adding those sentence in my code in the reset function (not setup), but I'm getting null pointer exception when trying to retrieve the Species object.

2016-12-28 21:54 GMT-03:00 Eric 'Siggy' Scott <[log in to unmask]>:
Enzo,

Were you able to solve your problem?  Or could you still use assistance?

The usual way to access information in another class when initializing an object in ECJ is to use the global EvolutionState object to walk through the program's state and find what you want.

So, in the 'setup()' method of your BusProblemLine class, you would retrieve the Species object with something like this:

final GeneVectorSpecies species = (GeneVectorSpecies) state.population.subpops[0].species;

On Mon, Dec 19, 2016 at 9:11 AM, Enzo Fabbiani <[log in to unmask]> wrote:

Hi there, I'm facing some trouble when trying to initialize population.


My custom class BusProblemLine (which extends from Gene) implements reset function.

In order to do that, some problem information is needed. This info is read from files and loaded into atributes in the setup function in GeneVectorSpecies and can be accessed from evaluate function in my problem class.

How can I access to this information in BusProblemLine to initialize the population (as well as mutate and crossover).

I've tried to read data in the reset function but it explodes for out of memory. What is more, it gets initializing more times than the population size, is this ok?

Regards,
Enzo



--

Ph.D student in Computer Science, George Mason University
CFO and Web Director, Journal of Mason Graduate Research




--

Ph.D student in Computer Science, George Mason University
CFO and Web Director, Journal of Mason Graduate Research




--

Ph.D student in Computer Science, George Mason University
CFO and Web Director, Journal of Mason Graduate Research