Duke icon indicating copy to clipboard operation
Duke copied to clipboard

Let genetic algorithm use custom comparators

Open larsga opened this issue 11 years ago • 2 comments

From ztsmith: "Having the ability to use declared comparators. At the moment any comparators declared at the top of the config (as nodes) are ignored. I'm guessing that custom comparators are ignored as well. It would be great if any comparators declared at the top were included."

larsga avatar Aug 07 '14 19:08 larsga

The trouble with implementing this one is that the config loading is so generic we really have no idea what's declared as s. It may be that reading the config again to extract those is the easiest way to do it.

One you have the additional comparators, the rest is easy. Inject those into the list in the ComparatorAspect object and you're done. The genetic algorithm will then include those when choosing what comparator to set.

larsga avatar Aug 07 '14 19:08 larsga

I've submitted the pull request. It wasn't immediately obvious how to attach the pull request to this issue, so it's created a new one (#170). My testing shows that it is working, but the custom comparators are still not used in the configuration output. I noticed a FIXME comment in the ConfigWriter.java that discussed doing it, but that the API doesn't support it. I would like to work on this next. To make it happen I was thinking we would need to add an optional Name field to the Comparator interface, as well as something to return parameters that can be serialized (e.g. min-ratio). What do you think?

I moved the comparator list initialization into the GeneticConfiguration.java to make the ComparatorAspect a little easier to test. I thought it would be nice to just dynamically load all classes that implement the Comparator interface. But there didn't seem to be an easy way to do this (unlike in .NET). It doesn't feel right to have to maintain a separate list of strings for this. I also noticed one missing: JaccardIndexComparator. I didn't add this as I was weary of putting too much in one pull request. But I don't see any reason why it shouldn't be included?

Also, I've done very little Java coding and none in the last 6 years. So please let me know if there is anything I should be doing differently - I'm very open to feedback.

ztsmith avatar Aug 08 '14 23:08 ztsmith