Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public abstract class Solution {
- abstract double fitness();
- boolean isCorrect() {
- return true;
- }
- }
- public abstract class Generation extends ArrayList<Solution>{
- abstract public Solution getBest();
- }
- public class Context {
- }
- public interface Initializator {
- Generation getInitialGeneration();
- }
- public interface Mutator {
- //По данному решению получает новое допустимое
- Solution mutate(Solution s);
- }
- public interface NextGenerator {
- //Получает новое поколение по текущему. Зависим от алгоритма
- Generation next(Generation current);
- }
- public interface Selector {
- Generation keepTheBestSolutions(Generation generation);
- }
- public interface StoppingCriteria {
- boolean isStop(Generation generation);
- }
- public class Algorithm {
- Initializator i;
- NextGenerator ng;
- StoppingCriteria stop;
- Selector eval;
- public Algorithm(Initializator i, NextGenerator ng, StoppingCriteria stop, Selector eval) {
- this.i = i;
- this.ng = ng;
- this.stop = stop;
- this.eval = eval;
- }
- Solution run() {
- Generation gen = i.getInitialGeneration();
- while(!stop.isStop(gen)) {
- Generation ngen = ng.next(gen);
- ngen = eval.keepTheBestSolutions(ngen);
- }
- return gen.getBest();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement