001    /*
002     * Copyright 2011 Christian Kumpe http://kumpe.de/christian/java
003     *
004     * Licensed under the Apache License, Version 2.0 (the "License");
005     * you may not use this file except in compliance with the License.
006     * You may obtain a copy of the License at
007     *
008     *     http://www.apache.org/licenses/LICENSE-2.0
009     *
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS,
012     * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
013     * See the License for the specific language governing permissions and
014     * limitations under the License.
015     */
016    package de.kumpe.hadooptimizer.examples.benchmark;
017    
018    import org.apache.commons.math.random.RandomGenerator;
019    
020    import de.kumpe.hadooptimizer.EaOptimizerConfiguration;
021    import de.kumpe.hadooptimizer.Evaluator;
022    import de.kumpe.hadooptimizer.NeedsRandomGenerator;
023    import de.kumpe.hadooptimizer.examples.OptimizerExample;
024    import de.kumpe.hadooptimizer.impl.IdentityMutator;
025    
026    /**
027     * A benchmark example which returns an uniformly distributed randomGenerator
028     * value in the evaluator.
029     * 
030     * @author <a href="http://kumpe.de/christian/java">Christian Kumpe</a>
031     */
032    public class NoOp extends OptimizerExample<double[]> {
033            private final static class NoOpEvaluator implements Evaluator<double[]>,
034                            NeedsRandomGenerator {
035                    private static final long serialVersionUID = 1L;
036    
037                    private RandomGenerator randomGenerator;
038    
039                    @Override
040                    public void setRandomGenerator(final RandomGenerator randomGenerator) {
041                            this.randomGenerator = randomGenerator;
042                    }
043    
044                    @Override
045                    public double evaluate(final double[] individual) {
046                            return randomGenerator.nextDouble();
047                    }
048            }
049    
050            @Override
051            protected EaOptimizerConfiguration<double[]> createEaOptimizerConfiguration() {
052                    final EaOptimizerConfiguration<double[]> conf = new EaOptimizerConfiguration<double[]>();
053                    initConfiguration(conf, new double[] { 100, 100 });
054    
055                    conf.setMutator(new IdentityMutator<double[]>());
056                    conf.setEvaluator(new NoOpEvaluator());
057                    return conf;
058            }
059    
060            @Override
061            protected String getVersionInfo() {
062                    return "$Id: NoOp.java 3890 2011-04-20 14:58:14Z baumbart $";
063            }
064    }