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.tutorial;
017    
018    import static java.lang.Double.*;
019    
020    import org.apache.commons.cli.ParseException;
021    
022    import de.kumpe.hadooptimizer.EaOptimizerConfiguration;
023    import de.kumpe.hadooptimizer.examples.OptimizerExample;
024    
025    public class MinimumInPolygon extends OptimizerExample<Double> {
026            @Override
027            protected String getVersionInfo() {
028                    return "Minimumsuche in einem Polygon; Version 1.0";
029            }
030    
031            @Override
032            protected EaOptimizerConfiguration<Double> createEaOptimizerConfiguration()
033                            throws ParseException {
034                    final String[] args = commandLine.getArgs();
035    
036                    final EaOptimizerConfiguration<Double> configuration = new EaOptimizerConfiguration<Double>();
037                    final double startIndividual = parseDouble(args[0]);
038                    initConfiguration(configuration, startIndividual);
039    
040                    final Number nrOfCycles = (Number) commandLine
041                                    .getParsedOptionValue(OPTION_CYCLES);
042                    configuration.setHalter(new CountingHalter<Double>(nrOfCycles
043                                    .intValue()));
044    
045                    configuration.setMutator(new GaussianMutator(parseDouble(args[1])));
046    
047                    final double[] roots = new double[args.length - 2];
048                    for (int i = 0; i < roots.length; i++) {
049                            roots[i] = parseDouble(args[i + 2]);
050                    }
051                    configuration.setEvaluator(new PolynomialEvaluator(0, 0));
052    
053                    return configuration;
054            }
055    }