Cosmetics (Moving F21Problem to F15)
This commit is contained in:
parent
ba2cd9c8ca
commit
a37f030756
@ -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();
|
||||
@ -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);
|
||||
buttonPan.add(ClearButton);
|
||||
buttonPan.add(LOGButton);
|
||||
buttonPan.add(DumpButton);
|
||||
buttonPan.add(ExportButton);
|
||||
// m_ButtonPanel.add(PrintButton);
|
||||
// m_ButtonPanel.add(OpenButton);
|
||||
// m_ButtonPanel.add(SaveButton);
|
||||
m_ButtonPanel.add(SaveJPGButton);
|
||||
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
|
||||
|
@ -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,6 +64,23 @@ 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
|
||||
@ -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;
|
||||
|
||||
public F15Problem(F15Problem f15Problem) {
|
||||
iterations = f15Problem.iterations;
|
||||
}
|
||||
|
||||
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.
|
||||
/**
|
||||
* 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(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[] c = new double[2];
|
||||
double t=0, s=0, sum=0;
|
||||
|
||||
// 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;
|
||||
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);
|
||||
}
|
||||
|
||||
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]);
|
||||
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 4;
|
||||
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 double getRangeLowerBound(int dim) {
|
||||
// return -1;
|
||||
if (dim == 0) return -2.5;
|
||||
else return -1.5;
|
||||
public String globalInfo() {
|
||||
return "The Levy-function, from Levy, A., and Montalvo, A. (1985)";
|
||||
}
|
||||
|
||||
public double getRangeUpperBound(int dim) {
|
||||
// return 1;
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user