/** * @see * edu.virginia.cs.geneticalgorithm.fitness.FitnessFactory#createFitness(edu.virginia.cs.geneticalgorithm.gene.Genotype) */ @Override public Fitness createFitness(final Genotype individual) { final ProxyFitness preFit = _preFit.createFitness(individual); final Fitness postFit = preFit.generatesPostFitness() ? preFit.getPostFitness() : _postFit.createFitness(individual); final ShortCircuitFitness retval = new ShortCircuitFitness(preFit, _preThreshold, postFit, _postFitLen); retval.setPostScale(_postScale); return retval; }
/** * @param preFactory {@link FitnessFactory} that generates {@link Fitness} functions requiring * less time to run than those generated by postFactory and can often act as a reasonable * proxy * @param preThreshold {@link java.util.List List} of threshold values for multi-objective fitness * which must all be passed for the postFit {@link Fitness} function to be evaluated * @param postFactory {@link FitnessFactory} that generates {@link Fitness} function to run if * threshold is met * @param postFitLen Number of fitness values returned by the postFit {@link Fitness} function */ public ShortCircuitFitnessFactory( final ProxyFitnessFactory preFactory, final List<Double> preThreshold, final FitnessFactory postFactory, final int postFitLen) { _preFit = preFactory; _preThreshold = preThreshold; _postFit = postFactory; _postFitLen = postFitLen; if (postFactory == null && !preFactory.generatesPostFitness()) throw new IllegalArgumentException( "If the proxy fitness factory cannot generate a post " + "fitness function, one must be provided!"); }
@Override public void ready() { _preFit.ready(); if (_postFit != null) _postFit.ready(); }