Pass aditional data in Evaluate function

#42 · closed · 10 comments

View on GitHub ↗

franzon

Hi I need to access some data (which is not contained in Genome) to compute fitness. I looked in the documentation but didn't find a way to pass additional data to the Evaluate function. One option would be using global variables, but i think that is not the best way. Do you have any ideas?

Comments

MaxHalford

Hey, what kind of data do you need to access? Can you describe a bit more specifically what you're trying to do?

franzon

I'm trying to find the best schedulling of matches of a tournament based on some constraints. I have a **list of slots**, a **list of players** (and which slots they can play) and a **list of matches** (consisting of two players). I'm using the total number of times that the genome breaks the contraints as fitness value, and this depends on the highlighted data. I got very good results using eaopt! But now i want to move this to a http server, so i need some way to pass these data to the Evaluate function.

MaxHalford

I'm not sure I understand everything because I'm tired :). Typically I would proceed by adding properties to your genome. That is, the genome would have 3 properties which are your lists (in Go they're called slices).

franzon

Oh sorry, didn't know it would be too simple. Thanks for help!

franzon

Sorry for reopening, i just have one more question: i also need access to this data in GenomeFactory function, but it also doesn't accept additional parameters.

MaxHalford

No worries mate! Well a solution would to create a struct with the parameters of your experiment. You could then assign a method to this struct which would create random `Genome`s. Do you see what I mean?

franzon

It worked! The only bad point is that the data is repeated in every Genome. But thanks for the help!

MaxHalford

Normally that should not be an issue because each genome has a slice, which is a pointer to a data array. That is, the data is not duplicated. If you change one of the lists it will be modified across each genome.

franzon

Thanks for clarify! I'm learning Go as i do this project.

MaxHalford

No worries! Feel free to open other issues. I'll close this one for now, but you can keep commenting and I'll answer.