Cosmetics (Moving F21Problem to F15)
This commit is contained in:
		@@ -98,22 +98,8 @@ public class Plot implements PlotInterface, Serializable {
 | 
			
		||||
		m_PlotName = PlotName;
 | 
			
		||||
		init();
 | 
			
		||||
	}
 | 
			
		||||
	/**
 | 
			
		||||
	 *
 | 
			
		||||
	 */
 | 
			
		||||
	public void init() {
 | 
			
		||||
		m_Frame = new JEFrame("Plot: "+m_PlotName);
 | 
			
		||||
		BasicResourceLoader  loader  = BasicResourceLoader.instance();
 | 
			
		||||
		byte[] bytes   = loader.getBytesFromResourceLocation(EvAInfo.iconLocation);
 | 
			
		||||
		try {
 | 
			
		||||
			m_Frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
 | 
			
		||||
		} catch (java.lang.NullPointerException e) {
 | 
			
		||||
			System.err.println("Could not find EvA2 icon, please move resources folder to working directory!");
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		m_ButtonPanel = new JPanel();
 | 
			
		||||
		m_PlotArea = new FunctionArea(m_xname,m_yname);
 | 
			
		||||
		m_ButtonPanel.setLayout( new FlowLayout(FlowLayout.LEFT, 10,10));
 | 
			
		||||
	protected void installButtons(JPanel buttonPan) {
 | 
			
		||||
		JButton ClearButton = new JButton ("Clear");
 | 
			
		||||
		ClearButton.addActionListener(new ActionListener() {
 | 
			
		||||
			public void actionPerformed(ActionEvent e) {
 | 
			
		||||
@@ -142,8 +128,8 @@ public class Plot implements PlotInterface, Serializable {
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		JButton SaveJPGButton = new JButton ("Save as PNG...");
 | 
			
		||||
		SaveJPGButton.addActionListener(new ActionListener() {
 | 
			
		||||
		JButton saveImageButton = new JButton ("Save as PNG...");
 | 
			
		||||
		saveImageButton.addActionListener(new ActionListener() {
 | 
			
		||||
			public void actionPerformed(ActionEvent e) {
 | 
			
		||||
				try {
 | 
			
		||||
					Robot       robot = new Robot();
 | 
			
		||||
@@ -152,31 +138,31 @@ public class Plot implements PlotInterface, Serializable {
 | 
			
		||||
					BufferedImage   bufferedImage   = robot.createScreenCapture(area);
 | 
			
		||||
					JFileChooser    fc              = new JFileChooser();
 | 
			
		||||
					if (fc.showSaveDialog(m_Frame) != JFileChooser.APPROVE_OPTION) return;
 | 
			
		||||
//					System.out.println("Name " + outfile);
 | 
			
		||||
					//				System.out.println("Name " + outfile);
 | 
			
		||||
					try {
 | 
			
		||||
						/* Old version
 | 
			
		||||
						FileOutputStream fos = new FileOutputStream(fc.getSelectedFile().getAbsolutePath()+".jpeg");
 | 
			
		||||
						BufferedOutputStream bos = new BufferedOutputStream(fos);
 | 
			
		||||
						JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
 | 
			
		||||
						encoder.encode(bufferedImage);
 | 
			
		||||
						bos.close();*/
 | 
			
		||||
					FileOutputStream fos = new FileOutputStream(fc.getSelectedFile().getAbsolutePath()+".jpeg");
 | 
			
		||||
					BufferedOutputStream bos = new BufferedOutputStream(fos);
 | 
			
		||||
					JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(bos);
 | 
			
		||||
					encoder.encode(bufferedImage);
 | 
			
		||||
					bos.close();*/
 | 
			
		||||
						File file = new File(fc.getSelectedFile().getAbsolutePath()+".png"); 
 | 
			
		||||
						ImageIO.write(bufferedImage, "png", file); 
 | 
			
		||||
						/* JPEG version with javax.imageio
 | 
			
		||||
					    float compression = 0.8f;
 | 
			
		||||
						FileImageOutputStream out = new FileImageOutputStream(new File(fc.getSelectedFile().getAbsolutePath()+".jpeg"));
 | 
			
		||||
						ImageWriter encoder = (ImageWriter)ImageIO.getImageWritersByFormatName("JPEG").next();
 | 
			
		||||
						JPEGImageWriteParam param = new JPEGImageWriteParam(null);
 | 
			
		||||
				    float compression = 0.8f;
 | 
			
		||||
					FileImageOutputStream out = new FileImageOutputStream(new File(fc.getSelectedFile().getAbsolutePath()+".jpeg"));
 | 
			
		||||
					ImageWriter encoder = (ImageWriter)ImageIO.getImageWritersByFormatName("JPEG").next();
 | 
			
		||||
					JPEGImageWriteParam param = new JPEGImageWriteParam(null);
 | 
			
		||||
 | 
			
		||||
						param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
 | 
			
		||||
						param.setCompressionQuality(compression);
 | 
			
		||||
					param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
 | 
			
		||||
					param.setCompressionQuality(compression);
 | 
			
		||||
 | 
			
		||||
						encoder.setOutput(out);
 | 
			
		||||
						encoder.write((IIOMetadata) null, new IIOImage(bufferedImage,null,null), param);
 | 
			
		||||
					encoder.setOutput(out);
 | 
			
		||||
					encoder.write((IIOMetadata) null, new IIOImage(bufferedImage,null,null), param);
 | 
			
		||||
 | 
			
		||||
					out.close();
 | 
			
		||||
						 */
 | 
			
		||||
 | 
			
		||||
						out.close();
 | 
			
		||||
*/
 | 
			
		||||
						
 | 
			
		||||
					} catch (Exception eee) {
 | 
			
		||||
						System.err.println("Error on exporting PNG: " + eee.getMessage());
 | 
			
		||||
					}
 | 
			
		||||
@@ -187,14 +173,34 @@ public class Plot implements PlotInterface, Serializable {
 | 
			
		||||
			}
 | 
			
		||||
		});
 | 
			
		||||
 | 
			
		||||
		m_ButtonPanel.add(ClearButton);
 | 
			
		||||
		m_ButtonPanel.add(LOGButton);
 | 
			
		||||
		m_ButtonPanel.add(DumpButton);
 | 
			
		||||
		m_ButtonPanel.add(ExportButton);
 | 
			
		||||
//		m_ButtonPanel.add(PrintButton);
 | 
			
		||||
//		m_ButtonPanel.add(OpenButton);
 | 
			
		||||
//		m_ButtonPanel.add(SaveButton);
 | 
			
		||||
		m_ButtonPanel.add(SaveJPGButton);
 | 
			
		||||
		buttonPan.add(ClearButton);
 | 
			
		||||
		buttonPan.add(LOGButton);
 | 
			
		||||
		buttonPan.add(DumpButton);
 | 
			
		||||
		buttonPan.add(ExportButton);
 | 
			
		||||
		//	m_ButtonPanel.add(PrintButton);
 | 
			
		||||
		//	m_ButtonPanel.add(OpenButton);
 | 
			
		||||
		//	m_ButtonPanel.add(SaveButton);
 | 
			
		||||
		buttonPan.add(saveImageButton);
 | 
			
		||||
	}
 | 
			
		||||
	/**
 | 
			
		||||
	 *
 | 
			
		||||
	 */
 | 
			
		||||
	public void init() {
 | 
			
		||||
		m_Frame = new JEFrame("Plot: "+m_PlotName);
 | 
			
		||||
		BasicResourceLoader  loader  = BasicResourceLoader.instance();
 | 
			
		||||
		byte[] bytes   = loader.getBytesFromResourceLocation(EvAInfo.iconLocation);
 | 
			
		||||
		try {
 | 
			
		||||
			m_Frame.setIconImage(Toolkit.getDefaultToolkit().createImage(bytes));
 | 
			
		||||
		} catch (java.lang.NullPointerException e) {
 | 
			
		||||
			System.err.println("Could not find EvA2 icon, please move resources folder to working directory!");
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		m_ButtonPanel = new JPanel();
 | 
			
		||||
		m_PlotArea = new FunctionArea(m_xname,m_yname);
 | 
			
		||||
		m_ButtonPanel.setLayout( new FlowLayout(FlowLayout.LEFT, 10,10));
 | 
			
		||||
 | 
			
		||||
		installButtons(m_ButtonPanel);
 | 
			
		||||
 | 
			
		||||
		//  getContentPane().smultetLayout( new GridLayout(1, 4) );
 | 
			
		||||
		m_Frame.getContentPane().add(m_ButtonPanel,"South");
 | 
			
		||||
		m_Frame.getContentPane().add(m_PlotArea,"Center"); // north was not so nice
 | 
			
		||||
@@ -216,12 +222,12 @@ public class Plot implements PlotInterface, Serializable {
 | 
			
		||||
	 * @param prefix
 | 
			
		||||
	 * @param pop
 | 
			
		||||
	 */
 | 
			
		||||
    public void drawPopulation(String prefix, Population pop) {
 | 
			
		||||
	public void drawPopulation(String prefix, Population pop) {
 | 
			
		||||
		for (int i=0; i<pop.size(); i++) {
 | 
			
		||||
			drawIndividual(1, 2, prefix, pop.getEAIndividual(i));
 | 
			
		||||
		}
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * Draw an individual to the Plot instance. It is annotated with the
 | 
			
		||||
	 * given prefix and its fitness.
 | 
			
		||||
@@ -230,10 +236,10 @@ public class Plot implements PlotInterface, Serializable {
 | 
			
		||||
	 * @param pop
 | 
			
		||||
	 * @see FunctionArea.drawIcon
 | 
			
		||||
	 */
 | 
			
		||||
    public void drawIndividual(int iconType, int graphID, String prefix, AbstractEAIndividual indy) {
 | 
			
		||||
    	getFunctionArea().drawIcon(iconType, prefix+" "+indy.getFitness(0), indy.getDoublePosition(), graphID);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
	public void drawIndividual(int iconType, int graphID, String prefix, AbstractEAIndividual indy) {
 | 
			
		||||
		getFunctionArea().drawIcon(iconType, prefix+" "+indy.getFitness(0), indy.getDoublePosition(), graphID);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setPreferredSize(Dimension prefSize) {
 | 
			
		||||
		if (m_Frame != null) {
 | 
			
		||||
			m_Frame.setPreferredSize(prefSize);
 | 
			
		||||
@@ -401,7 +407,7 @@ public class Plot implements PlotInterface, Serializable {
 | 
			
		||||
	public String getName() {
 | 
			
		||||
		return this.m_PlotName;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 *
 | 
			
		||||
	 */
 | 
			
		||||
@@ -427,23 +433,23 @@ public class Plot implements PlotInterface, Serializable {
 | 
			
		||||
		setUnconnectedPoint(range[0][1], range[1][1], graphLabel);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
//	/**
 | 
			
		||||
//	 * Just for testing the Plot class.
 | 
			
		||||
//	 */
 | 
			
		||||
//	public static void main( String[] args ){
 | 
			
		||||
//		Plot plot = new Plot("Plot-Test","x-value","y-value");
 | 
			
		||||
//		plot.init();
 | 
			
		||||
//		double x;
 | 
			
		||||
//		for  (x= 0; x <6000; x++) {
 | 
			
		||||
//			//double y = SpecialFunction.getnormcdf(x);
 | 
			
		||||
//			// double yy = 0.5*SpecialFunction.getnormpdf(x);
 | 
			
		||||
//			double n = Math.sin(((double)x/1000*Math.PI));
 | 
			
		||||
//			//plot.setConnectedPoint(x,Math.sin(x),0);
 | 
			
		||||
//			//plot.setConnectedPoint(x,Math.cos(x),1);
 | 
			
		||||
//			//plot.setConnectedPoint(x,y,0);
 | 
			
		||||
//			plot.setConnectedPoint(x,n,1);
 | 
			
		||||
//		}
 | 
			
		||||
//		//plot.addGraph(1,2);
 | 
			
		||||
//	}
 | 
			
		||||
	//	/**
 | 
			
		||||
	//	 * Just for testing the Plot class.
 | 
			
		||||
	//	 */
 | 
			
		||||
	//	public static void main( String[] args ){
 | 
			
		||||
	//		Plot plot = new Plot("Plot-Test","x-value","y-value");
 | 
			
		||||
	//		plot.init();
 | 
			
		||||
	//		double x;
 | 
			
		||||
	//		for  (x= 0; x <6000; x++) {
 | 
			
		||||
	//			//double y = SpecialFunction.getnormcdf(x);
 | 
			
		||||
	//			// double yy = 0.5*SpecialFunction.getnormpdf(x);
 | 
			
		||||
	//			double n = Math.sin(((double)x/1000*Math.PI));
 | 
			
		||||
	//			//plot.setConnectedPoint(x,Math.sin(x),0);
 | 
			
		||||
	//			//plot.setConnectedPoint(x,Math.cos(x),1);
 | 
			
		||||
	//			//plot.setConnectedPoint(x,y,0);
 | 
			
		||||
	//			plot.setConnectedPoint(x,n,1);
 | 
			
		||||
	//		}
 | 
			
		||||
	//		//plot.addGraph(1,2);
 | 
			
		||||
	//	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -14,6 +14,8 @@ package eva2.gui;
 | 
			
		||||
 *==========================================================================*/
 | 
			
		||||
import java.awt.Color;
 | 
			
		||||
 | 
			
		||||
import javax.swing.JPanel;
 | 
			
		||||
 | 
			
		||||
import eva2.server.go.problems.Interface2DBorderProblem;
 | 
			
		||||
import eva2.server.go.problems.InterfaceFirstOrderDerivableProblem;
 | 
			
		||||
import eva2.tools.chart2d.DRectangle;
 | 
			
		||||
@@ -28,7 +30,9 @@ import eva2.tools.math.Mathematics;
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
public class TopoPlot extends Plot {
 | 
			
		||||
 | 
			
		||||
  Interface2DBorderProblem prob=null;
 | 
			
		||||
  double[][] range=null;
 | 
			
		||||
  boolean withGrads=false;
 | 
			
		||||
  private int gridx = 50;
 | 
			
		||||
  private int gridy = 50;
 | 
			
		||||
  int colorScale = ColorBarCalculator.BLUE_TO_RED;
 | 
			
		||||
@@ -60,7 +64,24 @@ public class TopoPlot extends Plot {
 | 
			
		||||
    colorScale = color_scale;
 | 
			
		||||
  }
 | 
			
		||||
 | 
			
		||||
  /**
 | 
			
		||||
  
 | 
			
		||||
  
 | 
			
		||||
  @Override
 | 
			
		||||
  protected void installButtons(JPanel buttonPan) {
 | 
			
		||||
	  super.installButtons(buttonPan);
 | 
			
		||||
	  // TODO this actually works, but it is horribly slow
 | 
			
		||||
//	  JButton refineButton = new JButton ("Refine");
 | 
			
		||||
//	  refineButton.setToolTipText("Refine the graph resolution");
 | 
			
		||||
//	  refineButton.addActionListener(new ActionListener() {
 | 
			
		||||
//		  public void actionPerformed(ActionEvent e) {
 | 
			
		||||
//			  gridx=(int)(Math.sqrt(2.)*gridx);
 | 
			
		||||
//			  gridy=(int)(Math.sqrt(2.)*gridy);
 | 
			
		||||
//			  setTopology(prob, range, withGrads);
 | 
			
		||||
//		  }
 | 
			
		||||
//	  });
 | 
			
		||||
//	  buttonPan.add(refineButton);
 | 
			
		||||
  }
 | 
			
		||||
/**
 | 
			
		||||
   * Defines parameters used for drawing the topology.
 | 
			
		||||
   * @param gridX the x-resolution of the topology, higher value means higher resolution
 | 
			
		||||
   * @param gridY the y-resolution of the topology, higher value means higher resolution
 | 
			
		||||
@@ -79,6 +100,9 @@ public class TopoPlot extends Plot {
 | 
			
		||||
   * Defines the topology (by setting a specific problem) and draws the topology
 | 
			
		||||
   */
 | 
			
		||||
  public void setTopology(Interface2DBorderProblem problem, double[][] border, boolean withGradientsIfAvailable) {
 | 
			
		||||
	  prob=problem;
 | 
			
		||||
	  range=border;
 | 
			
		||||
	  withGrads=withGradientsIfAvailable;
 | 
			
		||||
	double[] sizeXY=Mathematics.getAbsRange(border);
 | 
			
		||||
    double deltaX = sizeXY[0]/gridx;
 | 
			
		||||
    double deltaY = sizeXY[1]/gridy;
 | 
			
		||||
@@ -133,9 +157,5 @@ public class TopoPlot extends Plot {
 | 
			
		||||
    	} // for x
 | 
			
		||||
    }
 | 
			
		||||
    m_Frame.setVisible(true);
 | 
			
		||||
 | 
			
		||||
  } // setTopology
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
} // class
 | 
			
		||||
 
 | 
			
		||||
@@ -1,102 +1,77 @@
 | 
			
		||||
package eva2.server.go.problems;
 | 
			
		||||
 | 
			
		||||
import static java.lang.Math.PI;
 | 
			
		||||
import static java.lang.Math.sin;
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
 | 
			
		||||
public class F15Problem extends AbstractProblemDoubleOffset {
 | 
			
		||||
	int iterations = 100;
 | 
			
		||||
import eva2.server.go.operators.postprocess.SolutionHistogram;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The Levy-function, from Levy, A., and Montalvo, A. (1985). Also described in 
 | 
			
		||||
 * "A Trust-Region Algorithm for Global Optimization", Bernardetta Addisy and Sven Leyfferz, 2004/2006.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class F15Problem extends AbstractProblemDouble implements Serializable, InterfaceInterestingHistogram {
 | 
			
		||||
	private int dim=10;
 | 
			
		||||
    
 | 
			
		||||
	public F15Problem() {
 | 
			
		||||
		super();
 | 
			
		||||
		super.SetDefaultAccuracy(0.00001);
 | 
			
		||||
		setDefaultRange(10);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
    public F15Problem(F15Problem f15Problem) {
 | 
			
		||||
		iterations = f15Problem.iterations;
 | 
			
		||||
	public F15Problem(int d) {
 | 
			
		||||
		this();
 | 
			
		||||
		setProblemDimension(d);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public F15Problem(F15Problem o) {
 | 
			
		||||
		super(o);
 | 
			
		||||
		dim=o.getProblemDimension();
 | 
			
		||||
		setDefaultRange(o.getDefaultRange());
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public double[] eval(double[] x) {
 | 
			
		||||
		x = rotateMaybe(x);
 | 
			
		||||
		double t=0, s=0, sum=0;
 | 
			
		||||
 | 
			
		||||
	public Object clone() {
 | 
			
		||||
        return (Object) new F15Problem(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /** This method allows you to evaluate a double[] to determine the fitness
 | 
			
		||||
     * @param x     The n-dimensional input vector
 | 
			
		||||
     * @return  The m-dimensional output vector.
 | 
			
		||||
     */
 | 
			
		||||
    public double[] eval(double[] x) {
 | 
			
		||||
    	x = rotateMaybe(x);
 | 
			
		||||
    	double[] c = new double[2];
 | 
			
		||||
    	
 | 
			
		||||
//    	c[0]= (x[0])*getXOffSet();
 | 
			
		||||
//    	c[1]= (x[1])*Math.sin((Math.PI/2)*getYOffSet());
 | 
			
		||||
    	
 | 
			
		||||
		c[0] = x[0]*x[2];
 | 
			
		||||
		c[1] = x[1] * sin( PI / 2.0 * x[3]);
 | 
			
		||||
		for (int i=0; i<x.length-2; i++) {
 | 
			
		||||
			s=(x[i]-1.);
 | 
			
		||||
			t=Math.sin(Math.PI*x[i+1]);
 | 
			
		||||
			sum += (s*s)*(1+10.*t*t);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
//    	c[0]= (x[0]+(x[2]/10))*getXOffSet();
 | 
			
		||||
//    	c[1]= (x[1]+(x[3]/10))*Math.sin(Math.PI/2*getYOffSet());
 | 
			
		||||
//    	c[0]= (x[0]*(1-x[2]/10));
 | 
			
		||||
//    	c[1]= (x[1]*(1-x[3]/10));
 | 
			
		||||
        double[] result = new double[1];
 | 
			
		||||
        result[0] = flatten(evalRec(x, c, iterations));
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    private double[] evalRec(double[] x, double[] c, int n) {
 | 
			
		||||
        if (n==0) return x;
 | 
			
		||||
        else return evalRec(addComplex(squareComplex(x),c), c, n-1);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    private double[] squareComplex(double[] x) {
 | 
			
		||||
    	double[] result = new double[2];
 | 
			
		||||
    	result[0] = (x[0]*x[0])-(x[1]*x[1]);
 | 
			
		||||
    	result[1] = (2*x[0]*x[1]);
 | 
			
		||||
    	return result;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    private double[] addComplex(double[] x, double[] y) {
 | 
			
		||||
    	double[] result = new double[2];
 | 
			
		||||
    	result[0] = x[0] + y[0];
 | 
			
		||||
    	result[1] = x[1] + y[1];
 | 
			
		||||
    	return result;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    private double flatten(double[] x) {
 | 
			
		||||
    	
 | 
			
		||||
    	double len = Math.sqrt((x[0]*x[0])+(x[1]*x[1]));
 | 
			
		||||
    	double ang = Math.atan2(x[1],x[0]);
 | 
			
		||||
    	if (Double.isNaN(len) || (len > 1000.)) len = 1000.;
 | 
			
		||||
    	return len;
 | 
			
		||||
//    	return 0.5+0.5*t*(2*b*a*u(x/a));
 | 
			
		||||
//    	return 1/(2*Math.PI*ang);
 | 
			
		||||
//    	return +Math.abs(x[0])+Math.abs(x[1]);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public int getProblemDimension() {
 | 
			
		||||
    	return 4;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public String getName() {
 | 
			
		||||
    	return "F15-Problem";
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public double getRangeLowerBound(int dim) {
 | 
			
		||||
//    	return -1;
 | 
			
		||||
    	if (dim == 0) return -2.5;
 | 
			
		||||
    	else return -1.5;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public double getRangeUpperBound(int dim) {
 | 
			
		||||
//    	return 1;
 | 
			
		||||
    	return 1.5;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the iterations
 | 
			
		||||
	 */
 | 
			
		||||
	public int getIterations() {
 | 
			
		||||
		return iterations;
 | 
			
		||||
		s=Math.sin(Math.PI*x[0]);
 | 
			
		||||
		double[] y = new double[1];
 | 
			
		||||
		y[0] = 10.*s*s+sum+dim*(x[dim-1]-1)*(x[dim-1]-1);
 | 
			
		||||
		return y;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @param iterations the iterations to set
 | 
			
		||||
	 */
 | 
			
		||||
	public void setIterations(int iterations) {
 | 
			
		||||
		this.iterations = iterations;
 | 
			
		||||
	@Override
 | 
			
		||||
	public int getProblemDimension() {
 | 
			
		||||
		return dim;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setProblemDimension(int d) {
 | 
			
		||||
		dim=d;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public Object clone() {
 | 
			
		||||
		return new F15Problem(this);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public SolutionHistogram getHistogram() {
 | 
			
		||||
		if (getProblemDimension()<15) return new SolutionHistogram(0, 2, 16);
 | 
			
		||||
		else if (getProblemDimension()<25) return new SolutionHistogram(0, 4, 16);
 | 
			
		||||
		else return new SolutionHistogram(0, 8, 16);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public String getName() {
 | 
			
		||||
		return "F15-Problem";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public String globalInfo() {
 | 
			
		||||
		return "The Levy-function, from Levy, A., and Montalvo, A. (1985)";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -1,77 +0,0 @@
 | 
			
		||||
package eva2.server.go.problems;
 | 
			
		||||
 | 
			
		||||
import java.io.Serializable;
 | 
			
		||||
 | 
			
		||||
import eva2.server.go.operators.postprocess.SolutionHistogram;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * The Levy-function, from Levy, A., and Montalvo, A. (1985). Also described in 
 | 
			
		||||
 * "A Trust-Region Algorithm for Global Optimization", Bernardetta Addisy and Sven Leyfferz, 2004/2006.
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
public class F21Problem extends AbstractProblemDouble implements Serializable, InterfaceInterestingHistogram {
 | 
			
		||||
	private int dim=10;
 | 
			
		||||
    
 | 
			
		||||
	public F21Problem() {
 | 
			
		||||
		super();
 | 
			
		||||
		super.SetDefaultAccuracy(0.00001);
 | 
			
		||||
		setDefaultRange(10);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public F21Problem(int d) {
 | 
			
		||||
		this();
 | 
			
		||||
		setProblemDimension(d);
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public F21Problem(F21Problem f21Problem) {
 | 
			
		||||
		super(f21Problem);
 | 
			
		||||
		dim=f21Problem.getProblemDimension();
 | 
			
		||||
		setDefaultRange(f21Problem.getDefaultRange());
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public double[] eval(double[] x) {
 | 
			
		||||
		x = rotateMaybe(x);
 | 
			
		||||
		double t=0, s=0, sum=0;
 | 
			
		||||
 | 
			
		||||
		for (int i=0; i<x.length-2; i++) {
 | 
			
		||||
			s=(x[i]-1.);
 | 
			
		||||
			t=Math.sin(Math.PI*x[i+1]);
 | 
			
		||||
			sum += (s*s)*(1+10.*t*t);
 | 
			
		||||
		}
 | 
			
		||||
		
 | 
			
		||||
		s=Math.sin(Math.PI*x[0]);
 | 
			
		||||
		double[] y = new double[1];
 | 
			
		||||
		y[0] = 10.*s*s+sum+dim*(x[dim-1]-1)*(x[dim-1]-1);
 | 
			
		||||
		return y;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	@Override
 | 
			
		||||
	public int getProblemDimension() {
 | 
			
		||||
		return dim;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public void setProblemDimension(int d) {
 | 
			
		||||
		dim=d;
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	@Override
 | 
			
		||||
	public Object clone() {
 | 
			
		||||
		return new F21Problem(this);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public SolutionHistogram getHistogram() {
 | 
			
		||||
		if (getProblemDimension()<15) return new SolutionHistogram(0, 2, 16);
 | 
			
		||||
		else if (getProblemDimension()<25) return new SolutionHistogram(0, 4, 16);
 | 
			
		||||
		else return new SolutionHistogram(0, 8, 16);
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public String getName() {
 | 
			
		||||
		return "F21-Problem";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
	public String globalInfo() {
 | 
			
		||||
		return "The Levy-function, from Levy, A., and Montalvo, A. (1985)";
 | 
			
		||||
	}
 | 
			
		||||
	
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										113
									
								
								src/eva2/server/go/problems/FunnyProblem.java
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										113
									
								
								src/eva2/server/go/problems/FunnyProblem.java
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,113 @@
 | 
			
		||||
package eva2.server.go.problems;
 | 
			
		||||
 | 
			
		||||
import static java.lang.Math.PI;
 | 
			
		||||
import static java.lang.Math.sin;
 | 
			
		||||
 | 
			
		||||
/**
 | 
			
		||||
 * This is just an example function with no real use except that it has a
 | 
			
		||||
 * nice plot to it. It doesnt make much sense for optimization, so Ill
 | 
			
		||||
 * hide it for now.
 | 
			
		||||
 * If you wonder what this function actually represents, you may want to
 | 
			
		||||
 * try to display a cut with x[2]=1; x[3]=1.
 | 
			
		||||
 *
 | 
			
		||||
 * @author mkron
 | 
			
		||||
 *
 | 
			
		||||
 */
 | 
			
		||||
public class FunnyProblem extends AbstractProblemDoubleOffset {
 | 
			
		||||
	int iterations = 100;
 | 
			
		||||
//	public static final boolean hideFromGOE = true;
 | 
			
		||||
	
 | 
			
		||||
	public FunnyProblem() {}
 | 
			
		||||
	
 | 
			
		||||
    public FunnyProblem(FunnyProblem o) {
 | 
			
		||||
		iterations = o.iterations;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	public Object clone() {
 | 
			
		||||
        return (Object) new FunnyProblem(this);
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    /** This method allows you to evaluate a double[] to determine the fitness
 | 
			
		||||
     * @param x     The n-dimensional input vector
 | 
			
		||||
     * @return  The m-dimensional output vector.
 | 
			
		||||
     */
 | 
			
		||||
    public double[] eval(double[] x) {
 | 
			
		||||
    	x = rotateMaybe(x);
 | 
			
		||||
    	double[] c = new double[2];
 | 
			
		||||
    	
 | 
			
		||||
//    	c[0]= (x[0])*getXOffSet();
 | 
			
		||||
//    	c[1]= (x[1])*Math.sin((Math.PI/2)*getYOffSet());
 | 
			
		||||
    	
 | 
			
		||||
		c[0] = x[0]*x[2];
 | 
			
		||||
		c[1] = x[1] * sin( PI / 2.0 * x[3]);
 | 
			
		||||
		
 | 
			
		||||
//    	c[0]= (x[0]+(x[2]/10))*getXOffSet();
 | 
			
		||||
//    	c[1]= (x[1]+(x[3]/10))*Math.sin(Math.PI/2*getYOffSet());
 | 
			
		||||
//    	c[0]= (x[0]*(1-x[2]/10));
 | 
			
		||||
//    	c[1]= (x[1]*(1-x[3]/10));
 | 
			
		||||
        double[] result = new double[1];
 | 
			
		||||
        result[0] = flatten(evalRec(x, c, iterations));
 | 
			
		||||
        return result;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    private double[] evalRec(double[] x, double[] c, int n) {
 | 
			
		||||
        if (n==0) return x;
 | 
			
		||||
        else return evalRec(addComplex(squareComplex(x),c), c, n-1);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    private double[] squareComplex(double[] x) {
 | 
			
		||||
    	double[] result = new double[2];
 | 
			
		||||
    	result[0] = (x[0]*x[0])-(x[1]*x[1]);
 | 
			
		||||
    	result[1] = (2*x[0]*x[1]);
 | 
			
		||||
    	return result;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    private double[] addComplex(double[] x, double[] y) {
 | 
			
		||||
    	double[] result = new double[2];
 | 
			
		||||
    	result[0] = x[0] + y[0];
 | 
			
		||||
    	result[1] = x[1] + y[1];
 | 
			
		||||
    	return result;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    private double flatten(double[] x) {
 | 
			
		||||
    	
 | 
			
		||||
    	double len = Math.sqrt((x[0]*x[0])+(x[1]*x[1]));
 | 
			
		||||
    	double ang = Math.atan2(x[1],x[0]);
 | 
			
		||||
    	if (Double.isNaN(len) || (len > 1000.)) len = 1000.;
 | 
			
		||||
    	return len;
 | 
			
		||||
//    	return 0.5+0.5*t*(2*b*a*u(x/a));
 | 
			
		||||
//    	return 1/(2*Math.PI*ang);
 | 
			
		||||
//    	return +Math.abs(x[0])+Math.abs(x[1]);
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public int getProblemDimension() {
 | 
			
		||||
    	return 4;
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public String getName() {
 | 
			
		||||
    	return "FunnyProblem";
 | 
			
		||||
    }
 | 
			
		||||
    
 | 
			
		||||
    public double getRangeLowerBound(int dim) {
 | 
			
		||||
    	if (dim == 0) return -2.5;
 | 
			
		||||
    	else return -1.5;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    public double getRangeUpperBound(int dim) {
 | 
			
		||||
    	return 1.5;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @return the iterations
 | 
			
		||||
	 */
 | 
			
		||||
	public int getIterations() {
 | 
			
		||||
		return iterations;
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	/**
 | 
			
		||||
	 * @param iterations the iterations to set
 | 
			
		||||
	 */
 | 
			
		||||
	public void setIterations(int iterations) {
 | 
			
		||||
		this.iterations = iterations;
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
		Reference in New Issue
	
	Block a user