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.functions;
017
018 import java.awt.BorderLayout;
019 import java.awt.Frame;
020
021 import javax.swing.JFrame;
022 import javax.swing.WindowConstants;
023
024 import de.kumpe.hadooptimizer.EaOptimizerConfiguration;
025 import de.kumpe.hadooptimizer.Evaluator;
026 import de.kumpe.hadooptimizer.examples.OptimizerExample;
027 import de.kumpe.hadooptimizer.impl.GaussianMutator;
028
029 public class MinimumInGraph extends OptimizerExample<double[]> {
030
031 @Override
032 protected EaOptimizerConfiguration<double[]> createEaOptimizerConfiguration() {
033 final EaOptimizerConfiguration<double[]> configuration = new EaOptimizerConfiguration<double[]>();
034 initConfiguration(configuration, new double[] { 100, 100 });
035
036 final Evaluator<double[]> evaluator = new Evaluator<double[]>() {
037 private static final long serialVersionUID = 1L;
038
039 @Override
040 public double evaluate(final double[] individual) {
041 final double x = individual[0];
042 // return Math.cos(x * 4) * 0.7 + Math.cos(x * 2 - 0.01)+
043 // Math.abs(x / 10);
044 return Math.cos(x * 2) + Math.abs(x / 1000) - 0.01;
045 }
046 };
047 addReporter(new HistoryPanelReporter(evaluator));
048 configuration.setMutator(new GaussianMutator());
049 configuration.setEvaluator(evaluator);
050
051 final JFrame jFrame = new JFrame("Optimizer");
052 jFrame.setSize(640, 480);
053 jFrame.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
054 jFrame.setVisible(true);
055 jFrame.setExtendedState(Frame.MAXIMIZED_BOTH);
056 jFrame.add(new HistoryPanelReporter(evaluator), BorderLayout.CENTER);
057
058 return configuration;
059 }
060
061 @Override
062 protected String getVersionInfo() {
063 return "$Id: MinimumInGraph.java 3890 2011-04-20 14:58:14Z baumbart $";
064 }
065 }