Renamed StatsParameter to StatisticsParameter.

Refactored code. 

Added comments.
This commit is contained in:
Fabian Becker 2012-06-22 14:26:51 +00:00
parent 8582b79590
commit 00b6af14ff
14 changed files with 2306 additions and 2265 deletions

View File

@ -246,7 +246,7 @@ public class OptimizerRunnable implements Runnable {
* @param outp
*/
public void setOutputTo(int outp) {
((StatsParameter)proc.getStatistics().getStatisticsParameter()).setOutputTo(outp);
((StatisticsParameter)proc.getStatistics().getStatisticsParameter()).setOutputTo(outp);
}
/**

View File

@ -1,18 +1,16 @@
package eva2.gui;
/*
* Title: EvA2
* Description:
* Copyright: Copyright (c) 2003
* Company: University of Tuebingen, Computer Architecture
* @author Holger Ulmer, Felix Streichert, Hannes Planatscher
* @version: $Revision: 306 $
* $Date: 2007-12-04 14:22:52 +0100 (Tue, 04 Dec 2007) $
* $Author: mkron $
* Title: EvA2 Description: Copyright: Copyright (c) 2003 Company: University of
* Tuebingen, Computer Architecture @author Holger Ulmer, Felix Streichert,
* Hannes Planatscher @version: $Revision: 306 $ $Date: 2007-12-04 14:22:52
* +0100 (Tue, 04 Dec 2007) $ $Author: mkron $
*/
/*==========================================================================*
/*
* ==========================================================================*
* IMPORTS
*==========================================================================*/
*==========================================================================
*/
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
@ -49,44 +47,45 @@ import eva2.tools.chart2d.DPoint;
import eva2.tools.chart2d.DPointIcon;
import eva2.tools.chart2d.DPointSet;
import eva2.tools.chart2d.ScaledBorder;
import java.util.logging.Logger;
/*==========================================================================*
/*
* ==========================================================================*
* CLASS DECLARATION
*==========================================================================*/
*==========================================================================
*/
/**
*
*/
public class FunctionArea extends DArea implements Serializable {
/**
* Generated serial version identifier.
*/
private static final long serialVersionUID = 1238444548498667204L;
private static final Logger LOGGER = Logger.getLogger(FunctionArea.class.getName());
private GraphPointSetLegend legendBox = null;
private ScaledBorder m_Border;
private DPointIcon m_CurrentPointIcon;
private JFileChooser m_FileChooser;
private boolean m_legend = true;
private boolean m_log = false;
private ArrayList<GraphPointSet> m_PointSetContainer;
private InterfaceRefPointListener m_RefPointListener;
private int m_x;
private ScaledBorder scaledBorder;
private DPointIcon currentPointIcon;
private JFileChooser fileChooser;
private boolean legend = true;
private boolean log = false;
private ArrayList<GraphPointSet> pointSetContainer;
private InterfaceRefPointListener refPointListener;
private int xPos;
/**
*
*/
private int m_y;
private int yPos;
/**
*
*/
private boolean notifyNegLog = true;
/**
* Indicate whether graphs should be annotated with tool tips if pointed to
* with the mouse.
*/
private boolean doShowGraphToolTips = true;
/**
* Indicate whether graph legend entries should show their unique number.
*/
@ -111,13 +110,13 @@ public class FunctionArea extends DArea implements Serializable {
setMinRectangle(0, 0, 1, 1);
setBackground(new Color(253, 253, 253)); // not quite white
// setAutoFocus(true);
m_Border = new ScaledBorder();
m_Border.x_label = xname; // "App. " + Name + " func. calls";
m_Border.y_label = yname; // "fitness";
setBorder(m_Border);
scaledBorder = new ScaledBorder();
scaledBorder.x_label = xname; // "App. " + Name + " func. calls";
scaledBorder.y_label = yname; // "fitness";
setBorder(scaledBorder);
setAutoGrid(true);
setGridVisible(true);
m_PointSetContainer = new ArrayList<GraphPointSet>(20);
pointSetContainer = new ArrayList<GraphPointSet>(20);
// new DMouseZoom( this );
addPopup();
repaint();
@ -139,11 +138,13 @@ public class FunctionArea extends DArea implements Serializable {
sb.append(": ");
sb.append(getGraphInfo(gIndex));
return sb.toString();
} else
} else {
return null;
} else
}
} else {
return null;
}
}
/*
* (non-Javadoc)
@ -155,19 +156,20 @@ public class FunctionArea extends DArea implements Serializable {
if (isShowGraphToolTips()) {
int gIndex = getNearestGraphIndex(event.getX(), event.getY());
if (gIndex >= 0) {
DPoint pt = ((GraphPointSet) (m_PointSetContainer.get(gIndex)))
.getMedPoint();
DPoint pt = ((GraphPointSet) (pointSetContainer.get(gIndex))).getMedPoint();
Point pt2 = getDMeasures().getPoint(pt.x, pt.y);
pt2.x += (5 * (gIndex % 7)); // slight shift depending on index
// - easier distinction of very
// close graphs
pt2.y -= (10 + (gIndex % 3) * 5);
return pt2;
} else
} else {
return null;
} else
}
} else {
return null;
}
}
/**
*
@ -179,7 +181,7 @@ public class FunctionArea extends DArea implements Serializable {
}
public void addGraphPointSet(GraphPointSet d) {
this.m_PointSetContainer.add(d);
this.pointSetContainer.add(d);
}
/**
@ -193,13 +195,13 @@ public class FunctionArea extends DArea implements Serializable {
// do nothing
} else {
JPopupMenu graphPopupMenu = new JPopupMenu();
m_x = e.getX();
m_y = e.getY();
xPos = e.getX();
yPos = e.getY();
addMenuItem(graphPopupMenu, "Rename graph", new ActionListener() {
public void actionPerformed(ActionEvent ee) {
renameGraph(getNearestGraphIndex(FunctionArea.this.m_x, FunctionArea.this.m_y));
renameGraph(getNearestGraphIndex(FunctionArea.this.xPos, FunctionArea.this.yPos));
}
});
// General entries
@ -230,7 +232,7 @@ public class FunctionArea extends DArea implements Serializable {
}
});
if (FunctionArea.this.m_PointSetContainer.size() > 0) {
if (FunctionArea.this.pointSetContainer.size() > 0) {
addMenuItem(graphPopupMenu, "Recolor all graphs",
new ActionListener() {
@ -240,19 +242,19 @@ public class FunctionArea extends DArea implements Serializable {
});
}
if (m_RefPointListener != null) {
DPoint temp = getDMeasures().getDPoint(m_x, m_y);
if (refPointListener != null) {
DPoint temp = getDMeasures().getDPoint(xPos, yPos);
addMenuItem(graphPopupMenu, "Select Reference Point:("
+ temp.x + "/" + temp.y + ")",
new ActionListener() {
public void actionPerformed(ActionEvent ee) {
DPoint temp = getDMeasures().getDPoint(
m_x, m_y);
xPos, yPos);
double[] point = new double[2];
point[0] = temp.x;
point[1] = temp.y;
m_RefPointListener.refPointGiven(point);
refPointListener.refPointGiven(point);
}
});
}
@ -273,15 +275,15 @@ public class FunctionArea extends DArea implements Serializable {
new ActionListener() {
public void actionPerformed(ActionEvent ee) {
removePoint(FunctionArea.this.m_x,
FunctionArea.this.m_y);
removePoint(FunctionArea.this.xPos,
FunctionArea.this.yPos);
}
});
if (point.getIcon() instanceof InterfaceSelectablePointIcon) {
m_CurrentPointIcon = point.getIcon();
if (((InterfaceSelectablePointIcon) m_CurrentPointIcon).getSelectionListener() != null) {
AbstractEAIndividual indy = ((InterfaceSelectablePointIcon) m_CurrentPointIcon).getEAIndividual();
currentPointIcon = point.getIcon();
if (((InterfaceSelectablePointIcon) currentPointIcon).getSelectionListener() != null) {
AbstractEAIndividual indy = ((InterfaceSelectablePointIcon) currentPointIcon).getEAIndividual();
String selectTitle = indy.isMarked() ? " Deselect individual"
: " Select individual";
addMenuItem(graphPopupMenu, selectTitle,
@ -289,27 +291,27 @@ public class FunctionArea extends DArea implements Serializable {
public void actionPerformed(
ActionEvent ee) {
((InterfaceSelectablePointIcon) m_CurrentPointIcon).getSelectionListener().individualSelected(
((InterfaceSelectablePointIcon) m_CurrentPointIcon).getEAIndividual());
((InterfaceSelectablePointIcon) currentPointIcon).getSelectionListener().individualSelected(
((InterfaceSelectablePointIcon) currentPointIcon).getEAIndividual());
}
});
}
}
if (point.getIcon() instanceof InterfaceDPointWithContent) {
m_CurrentPointIcon = point.getIcon();
currentPointIcon = point.getIcon();
addMenuItem(graphPopupMenu, " Show individual",
new ActionListener() {
public void actionPerformed(
ActionEvent ee) {
((InterfaceDPointWithContent) m_CurrentPointIcon).showIndividual();
((InterfaceDPointWithContent) currentPointIcon).showIndividual();
}
});
}
}
if (FunctionArea.this.m_PointSetContainer.size() > 0) { // there
if (FunctionArea.this.pointSetContainer.size() > 0) { // there
// is
// at
// least
@ -324,8 +326,8 @@ public class FunctionArea extends DArea implements Serializable {
public void actionPerformed(ActionEvent ee) {
DPoint temp = FunctionArea.this.getDMeasures().getDPoint(
FunctionArea.this.m_x,
FunctionArea.this.m_y);
FunctionArea.this.xPos,
FunctionArea.this.yPos);
DPointIcon icon1 = new DPointIcon() {
public DBorder getDBorder() {
@ -346,8 +348,8 @@ public class FunctionArea extends DArea implements Serializable {
new ActionListener() {
public void actionPerformed(ActionEvent ee) {
clearGraph(FunctionArea.this.m_x,
FunctionArea.this.m_y);
clearGraph(FunctionArea.this.xPos,
FunctionArea.this.yPos);
}
});
@ -355,8 +357,8 @@ public class FunctionArea extends DArea implements Serializable {
new ActionListener() {
public void actionPerformed(ActionEvent ee) {
changeColorGraph(FunctionArea.this.m_x,
FunctionArea.this.m_y);
changeColorGraph(FunctionArea.this.xPos,
FunctionArea.this.yPos);
}
});
}
@ -404,11 +406,10 @@ public class FunctionArea extends DArea implements Serializable {
* This method allows to add a selection listener to the PointIcon it should
* need more than one listener to this abstruse event
*
* @param a
* The selection listener
* @param a The selection listener
*/
public void addRefPointSelectionListener(InterfaceRefPointListener a) {
this.m_RefPointListener = a;
this.refPointListener = a;
}
/**
@ -428,10 +429,10 @@ public class FunctionArea extends DArea implements Serializable {
*/
public void changeColorGraph(int x, int y) {
int index = getNearestGraphIndex(x, y);
if (index == -1)
if (index == -1) {
return;
int GraphLabel = ((GraphPointSet) (this.m_PointSetContainer.get(index)))
.getGraphLabel();
}
int GraphLabel = ((GraphPointSet) (this.pointSetContainer.get(index))).getGraphLabel();
changeColorGraph(GraphLabel);
updateLegend();
}
@ -442,9 +443,8 @@ public class FunctionArea extends DArea implements Serializable {
*/
public void recolorAllGraphsByIndex() {
int index = 0;
for (int i = 0; i < m_PointSetContainer.size(); i++) {
GraphPointSet gps = ((GraphPointSet) (this.m_PointSetContainer
.get(i)));
for (int i = 0; i < pointSetContainer.size(); i++) {
GraphPointSet gps = ((GraphPointSet) (this.pointSetContainer.get(i)));
if (gps.getPointCount() > 0) {
gps.setColorByIndex(index);
index++;
@ -459,31 +459,33 @@ public class FunctionArea extends DArea implements Serializable {
*/
public boolean checkLoggable() {
double minY = Double.MAX_VALUE;
for (int i = 0; i < m_PointSetContainer.size(); i++) {
DPointSet pSet = (m_PointSetContainer.get(i).getConnectedPointSet());
if (pSet.getSize() > 0)
for (int i = 0; i < pointSetContainer.size(); i++) {
DPointSet pSet = (pointSetContainer.get(i).getConnectedPointSet());
if (pSet.getSize() > 0) {
minY = Math.min(minY, pSet.getMinYVal());
}
}
// if (TRACE) System.out.println("min is " + minY);
return (minY > 0);
}
protected double getMinimalPositiveYValue() {
double minY = Double.MAX_VALUE;
for (int i = 0; i < m_PointSetContainer.size(); i++) {
DPointSet pSet = (m_PointSetContainer.get(i).getConnectedPointSet());
for (int i = 0; i < pointSetContainer.size(); i++) {
DPointSet pSet = (pointSetContainer.get(i).getConnectedPointSet());
if (pSet.getSize() > 0) {
double tmpMinY = Math.min(minY, pSet.getMinPositiveYValue());
if (tmpMinY > 0)
if (tmpMinY > 0) {
minY = tmpMinY;
}
}
}
return minY;
}
protected boolean checkLogValidYValue(double x, double y, int graphLabel) {
if (y <= 0.0) {
if (m_log && notifyNegLog) {
if (log && notifyNegLog) {
System.err.println("Warning: trying to plot value (" + x + "/"
+ y + ") with y <= 0 in logarithmic mode!");
notifyNegLog = false;
@ -502,11 +504,13 @@ public class FunctionArea extends DArea implements Serializable {
*/
public void clearAll() {
this.removeAllDElements();
for (int i = 0; i < m_PointSetContainer.size(); i++)
((GraphPointSet) (m_PointSetContainer.get(i))).removeAllPoints();
m_PointSetContainer.clear();
if (getYScale() instanceof Exp)
for (int i = 0; i < pointSetContainer.size(); i++) {
((GraphPointSet) (pointSetContainer.get(i))).removeAllPoints();
}
pointSetContainer.clear();
if (getYScale() instanceof Exp) {
setYScale(new Exp()); // to remove smallest seen value
}
notifyNegLog = true;
}
@ -515,7 +519,7 @@ public class FunctionArea extends DArea implements Serializable {
*/
public void clearGraph(int graphLabel) {
getGraphPointSet(graphLabel).removeAllPoints();
m_PointSetContainer.remove(getGraphPointSet(graphLabel));
pointSetContainer.remove(getGraphPointSet(graphLabel));
if (getYScale() instanceof Exp) {
((Exp) getYScale()).setMinValue(getMinimalPositiveYValue());
}
@ -528,10 +532,10 @@ public class FunctionArea extends DArea implements Serializable {
*/
public void clearGraph(int x, int y) {
int index = getNearestGraphIndex(x, y);
if (index == -1)
if (index == -1) {
return;
int GraphLabel = ((GraphPointSet) (this.m_PointSetContainer.get(index)))
.getGraphLabel();
}
int GraphLabel = ((GraphPointSet) (this.pointSetContainer.get(index))).getGraphLabel();
clearGraph(GraphLabel);
updateLegend();
}
@ -547,8 +551,8 @@ public class FunctionArea extends DArea implements Serializable {
*
*/
protected void createFileChooser() {
m_FileChooser = new JFileChooser(new File("/resources"));
m_FileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
fileChooser = new JFileChooser(new File("/resources"));
fileChooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
}
/**
@ -612,8 +616,7 @@ public class FunctionArea extends DArea implements Serializable {
popRep.addDPoint(new DPoint(position[0], position[1]));
DPointIcon icon = new Chart2DDPointIconText(label);
((Chart2DDPointIconText) icon).setIcon(theIcon);
((Chart2DDPointIconText) icon).setColor(getGraphPointSet(graphID)
.getColor());
((Chart2DDPointIconText) icon).setColor(getGraphPointSet(graphID).getColor());
popRep.setIcon(icon);
addDElement(popRep);
}
@ -631,7 +634,6 @@ public class FunctionArea extends DArea implements Serializable {
// getGraphPointSet(GraphLabel).addDPoint(x, y);
//
// }
/**
* Plot an icon to the function area which is annotated with a char and a
* double value. The color corresponds to the color of the graph with given
@ -685,52 +687,56 @@ public class FunctionArea extends DArea implements Serializable {
* Export contained data to a file or to standard out if null is given. The
* given File will be overwritten!
*
* @param file
* a File instance or null to export to standard out
* @param file a File instance or null to export to standard out
* @return true if the export succeeded, else false
*/
public boolean exportToAscii(File file) {
String[] s = null;
int maxSize = 0;
for (int i = 0; i < m_PointSetContainer.size(); i++) {
for (int i = 0; i < pointSetContainer.size(); i++) {
// find maximum length of all point sets
if (m_PointSetContainer.get(i).getConnectedPointSet().getSize() > maxSize) {
maxSize = m_PointSetContainer.get(i).getConnectedPointSet().getSize();
if (pointSetContainer.get(i).getConnectedPointSet().getSize() > maxSize) {
maxSize = pointSetContainer.get(i).getConnectedPointSet().getSize();
}
}
if (maxSize > 0) { // if there is any data, init string array and set x
// value column
s = new String[maxSize + 1];
for (int j = 0; j <= maxSize; j++) s[j] = "";
for (int j = 0; j <= maxSize; j++) {
s[j] = "";
}
} else {
System.err.println("Error: no data to export");
return true;
}
for (int i = 0; i < m_PointSetContainer.size(); i++) {
if (m_PointSetContainer.get(i) instanceof GraphPointSet) {
GraphPointSet set = (GraphPointSet) m_PointSetContainer.get(i);
for (int i = 0; i < pointSetContainer.size(); i++) {
if (pointSetContainer.get(i) instanceof GraphPointSet) {
GraphPointSet set = (GraphPointSet) pointSetContainer.get(i);
DPointSet pset = set.getConnectedPointSet();
// add column names
s[0] = s[0] + " t " + cleanBlanks(set.getInfoString(), '_');
for (int j = 1; j < s.length; j++) { // add column data of place
if ((j - 1) < pset.getSize())
if ((j - 1) < pset.getSize()) {
s[j] = s[j] + " " + pset.getDPoint(j - 1).x + " " + pset.getDPoint(j - 1).y;
else
} else {
s[j] += " ? ?"; // placeholder if no value in this set
}
} else
}
} else {
System.err.println("error in FunctionArea::exportToAscii");
}
}
if (file == null) {
for (int j = 0; j < s.length; j++) {
System.out.println(s[j]);
}
return true;
} else
} else {
try {
PrintWriter out = new PrintWriter(new FileOutputStream(file));
for (int j = 0; j < s.length; j++)
for (int j = 0; j < s.length; j++) {
out.println(s[j]);
}
out.flush();
out.close();
return true;
@ -739,12 +745,12 @@ public class FunctionArea extends DArea implements Serializable {
return false;
}
}
}
/**
* Export contained data to a file with a given String as prefix
*
* @param prefix
* file name prefix
* @param prefix file name prefix
* @return true if the export succeeded, else false
*/
public boolean exportToAscii(String prefix) {
@ -769,7 +775,7 @@ public class FunctionArea extends DArea implements Serializable {
* @return
*/
public int getContainerSize() {
return m_PointSetContainer.size();
return pointSetContainer.size();
}
/**
@ -780,34 +786,37 @@ public class FunctionArea extends DArea implements Serializable {
*/
public String getGraphInfo(int x, int y) {
String ret = "";
if ((m_PointSetContainer == null) || (m_PointSetContainer.size() == 0))
if ((pointSetContainer == null) || (pointSetContainer.size() == 0)) {
return ret;
}
int minindex = getNearestGraphIndex(x, y);
if (minindex >= 0)
return ((GraphPointSet) (m_PointSetContainer.get(minindex)))
.getInfoString();
else
if (minindex >= 0) {
return ((GraphPointSet) (pointSetContainer.get(minindex))).getInfoString();
} else {
return "none";
}
}
public String getGraphInfo(int graphIndex) {
String ret = "";
if ((m_PointSetContainer == null) || (m_PointSetContainer.size() == 0))
if ((pointSetContainer == null) || (pointSetContainer.size() == 0)) {
return ret;
}
if (graphIndex >= 0 && (graphIndex < m_PointSetContainer.size()))
return ((GraphPointSet) (m_PointSetContainer.get(graphIndex)))
.getInfoString();
else
if (graphIndex >= 0 && (graphIndex < pointSetContainer.size())) {
return ((GraphPointSet) (pointSetContainer.get(graphIndex))).getInfoString();
} else {
return "none";
}
}
public Color getGraphColor(int graphIndex) {
if (graphIndex >= 0)
return m_PointSetContainer.get(graphIndex).getColor();
else
if (graphIndex >= 0) {
return pointSetContainer.get(graphIndex).getColor();
} else {
return null;
}
}
/**
*
@ -817,9 +826,9 @@ public class FunctionArea extends DArea implements Serializable {
private GraphPointSet getGraphPointSet(int GraphLabel) {
// System.out.println("looping through " + m_PointSetContainer.size() +
// " point sets...");
for (int i = 0; i < m_PointSetContainer.size(); i++) {
if (m_PointSetContainer.get(i) instanceof GraphPointSet) {
GraphPointSet xx = (GraphPointSet) (m_PointSetContainer.get(i));
for (int i = 0; i < pointSetContainer.size(); i++) {
if (pointSetContainer.get(i) instanceof GraphPointSet) {
GraphPointSet xx = (GraphPointSet) (pointSetContainer.get(i));
// System.out.println("looking at "+xx.getGraphLabel());
if (xx.getGraphLabel() == GraphLabel) {
// System.out.println("match!");
@ -845,13 +854,13 @@ public class FunctionArea extends DArea implements Serializable {
DPoint point1 = getDMeasures().getDPoint(x, y);
DPoint point2 = null;
double dist = 0;
for (int i = 0; i < m_PointSetContainer.size(); i++) {
if (m_PointSetContainer.get(i) instanceof GraphPointSet) {
GraphPointSet pointset = (GraphPointSet) (m_PointSetContainer
.get(i));
for (int i = 0; i < pointSetContainer.size(); i++) {
if (pointSetContainer.get(i) instanceof GraphPointSet) {
GraphPointSet pointset = (GraphPointSet) (pointSetContainer.get(i));
point2 = pointset.getNearestDPoint(point1);
if (point2 == null)
if (point2 == null) {
continue;
}
dist = (point1.x - point2.x) * (point1.x - point2.x)
+ (point1.y - point2.y) * (point1.y - point2.y);
// System.out.println("dist="+dist+"i="+i);
@ -883,13 +892,15 @@ public class FunctionArea extends DArea implements Serializable {
DPoint point1 = getDMeasures().getDPoint(x, y);
DPoint point2 = null;
double dist = 0;
for (int i = 0; i < m_PointSetContainer.size(); i++) {
GraphPointSet pointset = m_PointSetContainer.get(i);
for (int i = 0; i < pointSetContainer.size(); i++) {
GraphPointSet pointset = pointSetContainer.get(i);
point2 = pointset.getNearestDPoint(point1);
if (point2 == null)
if (point2 == null) {
continue;
if (point1 == null)
}
if (point1 == null) {
System.err.println("point1 == null");
}
dist = (point1.x - point2.x) * (point1.x - point2.x)
+ (point1.y - point2.y) * (point1.y - point2.y);
@ -918,7 +929,7 @@ public class FunctionArea extends DArea implements Serializable {
* @return InterfaceSelectionListener
*/
public InterfaceRefPointListener getRefPointSelectionListener() {
return this.m_RefPointListener;
return this.refPointListener;
}
/**
@ -926,11 +937,11 @@ public class FunctionArea extends DArea implements Serializable {
*/
public boolean isStatisticsGraph(int x, int y) {
boolean ret = false;
if ((m_PointSetContainer == null) || (m_PointSetContainer.size() == 0))
if ((pointSetContainer == null) || (pointSetContainer.size() == 0)) {
return ret;
}
int minindex = getNearestGraphIndex(x, y);
ret = ((GraphPointSet) (m_PointSetContainer.get(minindex)))
.isStatisticsGraph();
ret = ((GraphPointSet) (pointSetContainer.get(minindex))).isStatisticsGraph();
return ret;
}
@ -939,15 +950,17 @@ public class FunctionArea extends DArea implements Serializable {
* position.
*/
public void jump() {
for (int i = 0; i < m_PointSetContainer.size(); i++)
((GraphPointSet) (m_PointSetContainer.get(i))).jump();
for (int i = 0; i < pointSetContainer.size(); i++) {
((GraphPointSet) (pointSetContainer.get(i))).jump();
}
}
@Override
public void paint(Graphics g) {
super.paint(g);
if (legendBox != null && m_legend)
legendBox.paintIn(g, m_Border.getInnerRect(this));
if (legendBox != null && legend) {
legendBox.paintIn(g, scaledBorder.getInnerRect(this));
}
}
/**
@ -955,12 +968,12 @@ public class FunctionArea extends DArea implements Serializable {
* @return
*/
public DPointSet[] printPoints() {
DPointSet[] ret = new DPointSet[m_PointSetContainer.size()];
for (int i = 0; i < m_PointSetContainer.size(); i++) {
DPointSet[] ret = new DPointSet[pointSetContainer.size()];
for (int i = 0; i < pointSetContainer.size(); i++) {
System.out.println("");
System.out.println("GraphPointSet No " + i);
ret[i] = ((GraphPointSet) m_PointSetContainer.get(i)).printPoints();
ret[i] = ((GraphPointSet) pointSetContainer.get(i)).printPoints();
}
return ret;
@ -976,7 +989,7 @@ public class FunctionArea extends DArea implements Serializable {
System.out.println("");
System.out.println("GraphPointSet No " + i);
return ((GraphPointSet) m_PointSetContainer.get(i)).printPoints();
return ((GraphPointSet) pointSetContainer.get(i)).printPoints();
// }
}
@ -988,10 +1001,10 @@ public class FunctionArea extends DArea implements Serializable {
public void removePoint(int x, int y) {
DPoint point = getNearestDPoint(x, y);
int index = getNearestGraphIndex(x, y);
if (index == -1 || point == null)
if (index == -1 || point == null) {
return;
GraphPointSet pointset = (GraphPointSet) (this.m_PointSetContainer
.get(index));
}
GraphPointSet pointset = (GraphPointSet) (this.pointSetContainer.get(index));
pointset.removePoint(point);
}
@ -999,13 +1012,14 @@ public class FunctionArea extends DArea implements Serializable {
* This method allows to remove the selection listener to the PointIcon
*/
public void removeRefPointSelectionListeners() {
this.m_RefPointListener = null;
this.refPointListener = null;
}
public void setConnectedPoint(double x, double y, int graphLabel) {
DFunction scF = getYScale();
if (scF instanceof Exp)
if (scF instanceof Exp) {
((Exp) scF).updateMinValue(y);
}
if (!checkLogValidYValue(x, y, graphLabel)) {
// if (m_log) toggleLog();
}
@ -1064,7 +1078,6 @@ public class FunctionArea extends DArea implements Serializable {
// }
// return null;
// }
// /**
// *
// */
@ -1094,7 +1107,6 @@ public class FunctionArea extends DArea implements Serializable {
// }
// }
// }
/**
*
* @param GraphLabel
@ -1122,9 +1134,10 @@ public class FunctionArea extends DArea implements Serializable {
*/
protected void setLegend(GraphPointSetLegend lBox) {
legendBox = lBox;
if (lBox != null && m_legend)
if (lBox != null && legend) {
repaint();
}
}
/**
*
@ -1134,8 +1147,9 @@ public class FunctionArea extends DArea implements Serializable {
*/
public void setUnconnectedPoint(double x, double y, int GraphLabel) {
DFunction scF = getYScale();
if (scF instanceof Exp)
if (scF instanceof Exp) {
((Exp) scF).updateMinValue(y);
}
if (!checkLogValidYValue(x, y, GraphLabel)) {
// if (m_log) toggleLog();
}
@ -1157,12 +1171,12 @@ public class FunctionArea extends DArea implements Serializable {
*
*/
private void toggleLegend() {
m_legend = !m_legend;
legend = !legend;
repaint();
}
public boolean isShowLegend() {
return m_legend;
return legend;
}
/**
@ -1171,21 +1185,21 @@ public class FunctionArea extends DArea implements Serializable {
* @param on
*/
public void setShowLegend(boolean on) {
m_legend = on;
legend = on;
if (!on) {
legendBox = null;
} else {
legendBox = new GraphPointSetLegend(m_PointSetContainer,
legendBox = new GraphPointSetLegend(pointSetContainer,
isAppendIndexInLegend());
}
repaint();
}
private boolean renameGraph(int graphIndex) {
if ((m_PointSetContainer == null) || (m_PointSetContainer.size() == 0)) {
if ((pointSetContainer == null) || (pointSetContainer.size() == 0)) {
return false;
}
if (graphIndex >= 0 && (graphIndex <m_PointSetContainer.size())) {
if (graphIndex >= 0 && (graphIndex < pointSetContainer.size())) {
String oldName = getGraphInfo(graphIndex);
String newName = ToolBoxGui.getInputPaneInitialVal(this, "Rename a graph", "Enter new name for graph " + graphIndex + ":", oldName);
if (newName != null) {
@ -1198,11 +1212,12 @@ public class FunctionArea extends DArea implements Serializable {
}
private boolean renameGraph(int graphIndex, String newName) {
if ((m_PointSetContainer == null) || (m_PointSetContainer.size() == 0))
if ((pointSetContainer == null) || (pointSetContainer.size() == 0)) {
return false;
}
if (graphIndex >= 0 && (graphIndex <m_PointSetContainer.size())) {
GraphPointSet gps = ((GraphPointSet) (m_PointSetContainer.get(graphIndex)));
if (graphIndex >= 0 && (graphIndex < pointSetContainer.size())) {
GraphPointSet gps = ((GraphPointSet) (pointSetContainer.get(graphIndex)));
gps.setInfoString(newName);
updateLegend();
return true;
@ -1217,32 +1232,31 @@ public class FunctionArea extends DArea implements Serializable {
public void toggleLog() {
// System.out.println("ToggleLog log was: "+m_log);
boolean setMinPos = false;
if (!m_log && !checkLoggable()) {
System.err
.println("Warning: toggling logarithmics scale with values <= 0! Some points will not be displayed.");
if (!log && !checkLoggable()) {
System.err.println("Warning: toggling logarithmics scale with values <= 0! Some points will not be displayed.");
setMinPos = true;
}
if (m_log == false) {
if (log == false) {
setMinRectangle(0.001, 0.001, 1, 1);
// setVisibleRectangle( 0.001, 0.001, 100000, 1000 );
Exp exp = new Exp();
if (setMinPos)
if (setMinPos) {
exp.setMinValue(getMinimalPositiveYValue());
}
setYScale(exp);
m_Border.setSrcdY(Math.log(10));
m_Border.setScientificPattern(false); // scientific on y axis
// m_Border.applyPattern(false, "0.###E0"); // replaced by the former line
m_log = true;
scaledBorder.setSrcdY(Math.log(10));
scaledBorder.setScientificPattern(false); // scientific on y axis
log = true;
} else {
m_log = false;
log = false;
setYScale(null);
ScaledBorder buffer = m_Border;
m_Border = new ScaledBorder();
m_Border.x_label = buffer.x_label; // "App. " + Name +
ScaledBorder buffer = scaledBorder;
scaledBorder = new ScaledBorder();
scaledBorder.x_label = buffer.x_label; // "App. " + Name +
// " func. calls";
m_Border.y_label = buffer.y_label; // "fitness";
m_Border.setStandardPattern(false); // default decimal pattern on y axis
setBorder(m_Border);
scaledBorder.y_label = buffer.y_label; // "fitness";
scaledBorder.setStandardPattern(false); // default decimal pattern on y axis
setBorder(scaledBorder);
}
repaint();
}
@ -1253,28 +1267,30 @@ public class FunctionArea extends DArea implements Serializable {
* @param immediateRepaint if true, a repaint event is scheduled immediately
*/
public void toggleScientificY(boolean immediateRepaint) {
m_Border.toggleDecPattern(false);
if (immediateRepaint) repaint();
scaledBorder.toggleDecPattern(false);
if (immediateRepaint) {
repaint();
}
}
/**
* Allows setting whether or not to paint the y-axis in logarithmic scale.
*
* @param log
* if true logarithmic scale is used, linear scale in case of
* @param log if true logarithmic scale is used, linear scale in case of
* false.
*/
public void toggleLog(boolean log) {
if (log != m_log)
if (log != log) {
toggleLog();
}
}
/**
* Recreate the legend object with the current point sets.
*
*/
public void updateLegend() {
GraphPointSetLegend lb = new GraphPointSetLegend(m_PointSetContainer,
GraphPointSetLegend lb = new GraphPointSetLegend(pointSetContainer,
isAppendIndexInLegend());
setLegend(lb);
}
@ -1282,8 +1298,7 @@ public class FunctionArea extends DArea implements Serializable {
/**
* Gives the info string for a graph label.
*
* @param j
* The graph label identifier.
* @param j The graph label identifier.
* @return The associated info string.
*/
public String getInfoString(int j) {

View File

@ -121,8 +121,8 @@ public class Plot implements PlotInterface, Serializable {
m_PlotArea.toggleLog();
}
});
JButton ExportButton = new JButton("Export...");
ExportButton.setToolTipText("Exports the graph data to a simple ascii file.");
JButton ExportButton = new JButton("Export to TSV");
ExportButton.setToolTipText("Exports the graph data to a simple TSV file.");
ExportButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {

View File

@ -33,7 +33,7 @@ import eva2.server.go.strategies.HillClimbing;
import eva2.server.go.strategies.NelderMeadSimplex;
import eva2.server.modules.GOParameters;
import eva2.server.stat.InterfaceTextListener;
import eva2.server.stat.StatsParameter;
import eva2.server.stat.StatisticsParameter;
import eva2.tools.Pair;
import eva2.tools.math.Mathematics;
import java.util.ArrayList;
@ -805,7 +805,7 @@ public class PostProcess {
*/
private static void runPP(OptimizerRunnable rnbl) {
rnbl.getGOParams().setDoPostProcessing(false);
rnbl.setVerbosityLevel(StatsParameter.VERBOSITY_NONE);
rnbl.setVerbosityLevel(StatisticsParameter.VERBOSITY_NONE);
ppRunnables.add(rnbl);
// System.err.println("Starting runbl " + rnbl);
rnbl.run();

View File

@ -188,7 +188,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
String startDate = getDateString();
// open the result file:
if (doFileOutput() // not "text-window only"
&& (m_StatsParams.getOutputVerbosity().getSelectedTagID() > StatsParameter.VERBOSITY_NONE)) { // verbosity accordingly high
&& (m_StatsParams.getOutputVerbosity().getSelectedTagID() > StatisticsParameter.VERBOSITY_NONE)) { // verbosity accordingly high
//!resFName.equalsIgnoreCase("none") && !resFName.equals("")) {
String fnameBase = makeOutputFileName(m_StatsParams.getResultFilePrefix(), infoString, startDate);
int cnt=0;
@ -1136,22 +1136,22 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
* @return
*/
private boolean printLineByVerbosity(int iteration) {
return (m_StatsParams.getOutputVerbosity().getSelectedTagID() > StatsParameter.VERBOSITY_KTH_IT)
|| ((m_StatsParams.getOutputVerbosity().getSelectedTagID() == StatsParameter.VERBOSITY_KTH_IT)
return (m_StatsParams.getOutputVerbosity().getSelectedTagID() > StatisticsParameter.VERBOSITY_KTH_IT)
|| ((m_StatsParams.getOutputVerbosity().getSelectedTagID() == StatisticsParameter.VERBOSITY_KTH_IT)
&& (isKthRun(iteration, m_StatsParams.getOutputVerbosityK())));
}
private boolean printRunIntroVerbosity() {
return (m_StatsParams.getOutputVerbosity().getSelectedTagID() >= StatsParameter.VERBOSITY_KTH_IT)
|| (optRunsPerformed==0 && (m_StatsParams.getOutputVerbosity().getSelectedTagID() >= StatsParameter.VERBOSITY_FINAL));
return (m_StatsParams.getOutputVerbosity().getSelectedTagID() >= StatisticsParameter.VERBOSITY_KTH_IT)
|| (optRunsPerformed==0 && (m_StatsParams.getOutputVerbosity().getSelectedTagID() >= StatisticsParameter.VERBOSITY_FINAL));
}
private boolean printRunStoppedVerbosity() {
return (m_StatsParams.getOutputVerbosity().getSelectedTagID() >= StatsParameter.VERBOSITY_KTH_IT);
return (m_StatsParams.getOutputVerbosity().getSelectedTagID() >= StatisticsParameter.VERBOSITY_KTH_IT);
}
private boolean printFinalVerbosity() {
return (m_StatsParams.getOutputVerbosity().getSelectedTagID() > StatsParameter.VERBOSITY_NONE);
return (m_StatsParams.getOutputVerbosity().getSelectedTagID() > StatisticsParameter.VERBOSITY_NONE);
}
private boolean isKthRun(int i, int k) {
@ -1166,7 +1166,7 @@ public abstract class AbstractStatistics implements InterfaceTextListener, Inter
}
private boolean printHeaderByVerbosity() {
return (m_StatsParams.getOutputVerbosity().getSelectedTagID() >= StatsParameter.VERBOSITY_KTH_IT);
return (m_StatsParams.getOutputVerbosity().getSelectedTagID() >= StatisticsParameter.VERBOSITY_KTH_IT);
}
private static void divideMean(Double[] mean, double d) {

View File

@ -12,52 +12,57 @@ package eva2.server.stat;
/*==========================================================================*
* IMPORTS
*==========================================================================*/
import java.io.Serializable;
import java.lang.reflect.Field;
import eva2.gui.DataViewer;
import eva2.gui.DataViewerInterface;
import eva2.gui.Graph;
import eva2.tools.jproxy.MainAdapterClient;
import java.io.Serializable;
import java.lang.reflect.Field;
import java.util.logging.Logger;
/**
*
*/
public class GenericStatistics implements Serializable {
public static boolean TRACE = false;
private static final Logger LOGGER = Logger.getLogger(GenericStatistics.class.getName());
//private Object m_target;
private int m_Test;
private String[] m_PropertyNames;
private boolean[] m_State;
private transient Field[] m_fields;
private DataViewerInterface m_Viewer;
private Graph m_Graph;
private static MainAdapterClient m_MainAdapterClient;
private int test;
private String[] propertyNames;
private boolean[] states;
private transient Field[] fields;
private DataViewerInterface viewer;
private Graph graph;
private static MainAdapterClient mainAdapterClient;
/**
*
*/
public static void setMainAdapterClient (MainAdapterClient x) {
m_MainAdapterClient = x;
public static void setMainAdapterClient(MainAdapterClient adapter) {
mainAdapterClient = adapter;
}
/**
*
*/
public GenericStatistics getClone() {
return new GenericStatistics(this);
}
/**
*
*/
private GenericStatistics(GenericStatistics Source) {
//m_target = Source.m_target;
m_Test = Source.m_Test;
m_PropertyNames = Source.m_PropertyNames;
m_State = Source.m_State;
m_fields = Source.m_fields;
m_Viewer = Source.m_Viewer;
m_Graph = Source.m_Graph;
test = Source.test;
propertyNames = Source.propertyNames;
states = Source.states;
fields = Source.fields;
viewer = Source.viewer;
graph = Source.graph;
}
/**
*
*/
@ -65,64 +70,71 @@ public class GenericStatistics implements Serializable{
//m_target = target;
//System.out.println("GenericStatistics-->");
try {
m_fields = getDeclaredFields(target);
fields = getDeclaredFields(target);
//if (TRACE) System.out.println("fields-->"+m_fields.length);
m_PropertyNames = new String [m_fields.length];
m_State = new boolean [m_fields.length];
for (int i=0;i<m_fields.length;i++) {
String desc = m_fields[i].toString(); //System.out.println("desc "+desc);
propertyNames = new String[fields.length];
states = new boolean[fields.length];
for (int i = 0; i < fields.length; i++) {
String desc = fields[i].toString(); //System.out.println("desc "+desc);
int istransient = desc.indexOf("transient");
//if (TRACE) System.out.println("Field :"+m_fields[i].getName() );
Object FieldValue = null;
if (istransient==-1 || m_fields[i].getName().equals("elementData")) { // the elementdatahack
m_fields[i].setAccessible(true);
FieldValue = m_fields[i].get(target);
if (istransient == -1 || fields[i].getName().equals("elementData")) { // the elementdatahack
fields[i].setAccessible(true);
FieldValue = fields[i].get(target);
}
m_PropertyNames[i] = m_fields[i].getName();
propertyNames[i] = fields[i].getName();
}
} catch (Exception ex) {
System.out.println("ERROR in GenericStatistics:" + ex.getMessage());
ex.printStackTrace();
}
}
/**
*
*/
public void setTest(int Test) {
m_Test = Test;
test = Test;
}
/**
*
*/
public int getTest() {
return m_Test;
return test;
}
/**
*
*/
public String[] getPropertyNames() {
return m_PropertyNames;
return propertyNames;
}
/**
*
*/
public boolean[] getState() {
return m_State;
return states;
}
/**
*
*/
public void setState(boolean[] x) {
System.out.println("in statistics setState !!!!!!!!!!!!!!!!!!");
m_State = x;
states = x;
}
/**
*
*/
public void initViewer() {
m_Viewer = DataViewer.getInstance(m_MainAdapterClient,"test");
m_Graph = m_Viewer.getNewGraph("test");
viewer = DataViewer.getInstance(mainAdapterClient, "test");
graph = viewer.getNewGraph("test");
}
/**
*
*/
@ -141,41 +153,52 @@ public class GenericStatistics implements Serializable{
}
return ret;
}
/**
*
*/
public void statechanged(Object target) {
int len = 0;
for (int i=0;i<m_State.length;i++)
if (m_State[i]==true) len++;
if (len==0) return;
if (m_Viewer == null) initViewer();
for (int i = 0; i < states.length; i++) {
if (states[i] == true) {
len++;
}
}
if (len == 0) {
return;
}
if (viewer == null) {
initViewer();
}
double[] data = new double[len];
try {
m_fields = getDeclaredFields(target);
fields = getDeclaredFields(target);
} catch (Exception ex) {
System.out.println("ERROR in GenericStatistics:" + ex.getMessage());
ex.printStackTrace();
}
int index = 0;
for (int i=0;i<m_fields.length;i++) {
for (int n=0;n<m_PropertyNames.length;n++) {
if (this.m_State[n]==false)
for (int i = 0; i < fields.length; i++) {
for (int n = 0; n < propertyNames.length; n++) {
if (this.states[n] == false) {
continue;
if (m_fields[i].getName().equals(m_PropertyNames[n])) {
String desc = m_fields[i].toString(); //System.out.println("desc "+desc);
}
if (fields[i].getName().equals(propertyNames[n])) {
String desc = fields[i].toString(); //System.out.println("desc "+desc);
int istransient = desc.indexOf("transient");
//if (TRACE) System.out.println("Field :"+m_fields[i].getName() );
Object FieldValue = null;
if (istransient==-1 || m_fields[i].getName().equals("elementData")) { // the elementdatahack
m_fields[i].setAccessible(true);
if (istransient == -1 || fields[i].getName().equals("elementData")) { // the elementdatahack
fields[i].setAccessible(true);
try {
FieldValue = m_fields[i].get(target);
FieldValue = fields[i].get(target);
//System.out.println("m_PropertyNames "+m_PropertyNames[n] +" value "+FieldValue.toString());
if (FieldValue instanceof Double)
if (FieldValue instanceof Double) {
data[index] = ((Double) FieldValue).doubleValue();
if (FieldValue instanceof Integer)
}
if (FieldValue instanceof Integer) {
data[index] = ((Integer) FieldValue).doubleValue();
}
index++;
} catch (Exception ex) {
System.out.println("ERROR in GenericStatistics:" + ex.getMessage());
@ -186,6 +209,6 @@ public class GenericStatistics implements Serializable{
}
}
}
m_Graph.setConnectedPoint(data[1],data[0]);
graph.setConnectedPoint(data[1], data[0]);
}
}

View File

@ -9,51 +9,48 @@ import eva2.tools.StringSelection;
* @see StatsParameter
*/
public interface InterfaceStatisticsParameter {
public String getName();
public void saveInstance();
// public String globalInfo();
// public void setTextoutput(int i);
// public void setPlotoutput(int i); // noone knows what these were useful for...
// public int GetPlotoutput();
// public int GetTextoutput();
// public String textoutputTipText();
// public String plotFrequencyTipText();
public void setMultiRuns(int x);
public int getMultiRuns();
public String multiRunsTipText();
String getName();
void saveInstance();
void setMultiRuns(int x);
int getMultiRuns();
String multiRunsTipText();
// public String GetInfoString();
// public void setInfoString(String s);
public boolean GetUseStatPlot(); // use averaged graph for multi-run plots or not
public void setUseStatPlot(boolean x); // activate averaged graph for multi-run plots
/**
* Use averaged graph for multi-run plots or not.
*
* @return If an average graph is used or not
*/
boolean getUseStatPlot();
// public List<String[]> getPlotDescriptions();
/**
* Activate averaged graph for multi-run plots.
*
* @param x If averaged graph should be activated.
*/
void setUseStatPlot(boolean x);
// public SelectedTag getPlotData();
// public void setPlotData(SelectedTag newMethod);
StringSelection getFieldSelection();
void setFieldSelection(StringSelection v);
public StringSelection getFieldSelection();
public void setFieldSelection(StringSelection v);
String getResultFilePrefix();
void setResultFilePrefix(String x);
public String getResultFilePrefix();
public void SetResultFilePrefix(String x);
void setConvergenceRateThreshold(double x);
double getConvergenceRateThreshold();
public void setConvergenceRateThreshold(double x);
public double getConvergenceRateThreshold();
void setShowTextOutput(boolean show);
boolean isShowTextOutput();
public void SetShowTextOutput(boolean show);
public boolean isShowTextOutput();
boolean isOutputAllFieldsAsText();
void setOutputAllFieldsAsText(boolean bShowFullText);
public boolean isOutputAllFieldsAsText();
public void setOutputAllFieldsAsText(boolean bShowFullText);
void setOutputVerbosity(SelectedTag sTag);
SelectedTag getOutputVerbosity();
public void setOutputVerbosity(SelectedTag sTag);
public SelectedTag getOutputVerbosity();
int getOutputVerbosityK();
void setOutputVerbosityK(int k);
public int getOutputVerbosityK();
public void setOutputVerbosityK(int k);
public void setOutputTo(SelectedTag sTag);
public SelectedTag getOutputTo();
void setOutputTo(SelectedTag sTag);
SelectedTag getOutputTo();
}

View File

@ -18,19 +18,19 @@ import eva2.server.go.strategies.InterfaceOptimizer;
*/
public class StatisticsDummy implements InterfaceStatistics, InterfaceTextListener {
boolean consoleOut = false;
StatsParameter sParams = null;
StatisticsParameter sParams = null;
AbstractEAIndividual bestCurrentIndividual, bestRunIndy, bestIndividualAllover;
public StatisticsDummy() {
bestIndividualAllover = null;
sParams = new StatsParameter();
sParams.setOutputVerbosityK(StatsParameter.VERBOSITY_NONE);
sParams = new StatisticsParameter();
sParams.setOutputVerbosityK(StatisticsParameter.VERBOSITY_NONE);
}
public StatisticsDummy(boolean doConsoleOut) {
bestIndividualAllover = null;
sParams = new StatsParameter();
sParams.setOutputVerbosityK(StatsParameter.VERBOSITY_NONE);
sParams = new StatisticsParameter();
sParams.setOutputVerbosityK(StatisticsParameter.VERBOSITY_NONE);
consoleOut = doConsoleOut;
}

View File

@ -0,0 +1,390 @@
package eva2.server.stat;
import eva2.gui.BeanInspector;
import eva2.gui.GenericObjectEditor;
import eva2.server.go.InterfaceNotifyOnInformers;
import eva2.server.go.problems.InterfaceAdditionalPopulationInformer;
import eva2.tools.EVAERROR;
import eva2.tools.SelectedTag;
import eva2.tools.Serializer;
import eva2.tools.StringSelection;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* A set of parameters for statistics in EvA2. Several data entries are provided by the AbstractStatistics class,
* others by the additional informers. This class allows customization of entries and frequency of data output.
* Data entries can be selected using a StringSelection instance.
* There is a switch called "output full data as text" which will be interpreted by AbstractStatistics showing
* all or only the selected entities.
*
* @see AbstractStatistics
* @author mkron
*/
public class StatisticsParameter implements InterfaceStatisticsParameter, InterfaceNotifyOnInformers, Serializable {
private static final long serialVersionUID = -8681061379203108390L;
private static final Logger LOGGER = Logger.getLogger(StatisticsParameter.class.getName());
public final static int VERBOSITY_NONE = 0;
public final static int VERBOSITY_FINAL = 1;
public final static int VERBOSITY_KTH_IT = 2;
public final static int VERBOSITY_ALL = 3;
SelectedTag outputVerbosity = new SelectedTag("No output", "Final results", "K-th iterations", "All iterations");
public final static int OUTPUT_FILE = 0;
public final static int OUTPUT_WINDOW = 1;
public final static int OUTPUT_FILE_WINDOW = 2;
SelectedTag outputTo = new SelectedTag("File (current dir.)", "Text-window", "Both file and text-window");
private int verboK = 10;
private int m_Textoutput = 0;
private int m_MultiRuns = 1;
private String m_ResultFilePrefix = "EvA2";
protected String m_Name = "not defined";
private boolean m_useStatPlot = true;
private boolean showAdditionalProblemInfo = false;
private double m_ConvergenceRateThreshold = 0.001;
private StringSelection graphSel = new StringSelection(GraphSelectionEnum.currentBest, GraphSelectionEnum.getInfoStrings());
/**
*
*/
public static StatisticsParameter getInstance(boolean loadDefaultSerFile) {
if (loadDefaultSerFile) {
return getInstance("Statistics.ser");
} else {
return new StatisticsParameter();
}
}
/**
* Load or create a new instance of the class.
*
* @return A loaded (from file) or new instance of the class.
*/
public static StatisticsParameter getInstance(String serFileName) {
StatisticsParameter instance = null;
try {
FileInputStream fileStream = new FileInputStream(serFileName);
instance = (StatisticsParameter) Serializer.loadObject(fileStream);
} catch (FileNotFoundException ex) {
LOGGER.log(Level.WARNING, "Could not store instance object.", ex);
}
if (instance == null) {
instance = new StatisticsParameter();
}
return instance;
}
/**
*
*/
public StatisticsParameter() {
m_Name = "Statistics";
outputVerbosity.setSelectedTag(VERBOSITY_KTH_IT);
outputTo.setSelectedTag(1);
}
/**
*
*/
@Override
public String toString() {
String ret = "\r\nStatisticsParameter (" + super.toString() + "):\r\nm_MultiRuns=" + m_MultiRuns
+ ", m_Textoutput=" + m_Textoutput
+ // ", m_Plotoutput=" + m_Plotoutput +
", verbosity= " + outputVerbosity.getSelectedString()
+ "\nTo " + outputTo.getSelectedString()
+ ", " + BeanInspector.toString(graphSel.getStrings());
return ret;
}
/**
*
*/
@Override
public void saveInstance() {
try {
FileOutputStream fileStream = new FileOutputStream("Statistics.ser");
Serializer.storeObject(fileStream, this);
} catch (FileNotFoundException ex) {
LOGGER.log(Level.WARNING, "Could not store instance object.", ex);
}
}
/**
*
*/
private StatisticsParameter(StatisticsParameter Source) {
m_ConvergenceRateThreshold = Source.m_ConvergenceRateThreshold;
m_useStatPlot = Source.m_useStatPlot;
m_Textoutput = Source.m_Textoutput;
// m_Plotoutput = Source.m_Plotoutput;
// m_PlotFitness = Source.m_PlotFitness;
m_MultiRuns = Source.m_MultiRuns;
m_ResultFilePrefix = Source.m_ResultFilePrefix;
verboK = Source.verboK;
}
/**
*
*/
public Object getClone() {
return new StatisticsParameter(this);
}
/**
*
*/
@Override
public String getName() {
return m_Name;
}
public static String globalInfo() {
return "Configure statistics and output of the optimization run. Changes to the data selection state will not take effect during a run.";
}
/**
*
*/
@Override
public void setMultiRuns(int x) {
m_MultiRuns = x;
}
/**
*
*/
@Override
public int getMultiRuns() {
return m_MultiRuns;
}
/**
*
*/
@Override
public String multiRunsTipText() {
return "Number of independent optimization runs to evaluate.";
}
/**
*
*/
public String infoStringTipText() {
return "Infostring displayed on fitness graph by prssing the right mouse button.";
}
/**
* Use averaged graph for multi-run plots or not
*/
@Override
public boolean getUseStatPlot() {
return m_useStatPlot;
}
/**
* Activate or deactivate averaged graph for multi-run plots
*/
@Override
public void setUseStatPlot(boolean x) {
m_useStatPlot = x;
}
public String useStatPlotTipText() {
return "Plotting each fitness graph separately if multiruns > 1.";
}
/**
*
*/
@Override
public void setResultFilePrefix(String x) {
if (x == null) {
m_ResultFilePrefix = "";
} else {
m_ResultFilePrefix = x;
}
}
/**
*
*/
@Override
public String getResultFilePrefix() {
return m_ResultFilePrefix;
}
@Override
public void setShowTextOutput(boolean show) {
// activate if not activated
if (show && outputTo.getSelectedTagID() == 0) {
outputTo.setSelectedTag(2);
} // deactivate if activated
else if (!show && outputTo.getSelectedTagID() > 0) {
outputTo.setSelectedTag(0);
}
}
@Override
public boolean isShowTextOutput() {
return outputTo.getSelectedTagID() > 0;
}
// /**
// *
// */
// public String resultFileNameTipText() {
// return "File name for the result file. If empty or 'none', no output file will be created.";
// }
public String convergenceRateThresholdTipText() {
return "Provided the optimal fitness is at zero, give the threshold below which it is considered as 'reached'";
}
/**
*
* @param x
*/
@Override
public void setConvergenceRateThreshold(double x) {
m_ConvergenceRateThreshold = x;
}
/**
*
*/
@Override
public double getConvergenceRateThreshold() {
return m_ConvergenceRateThreshold;
}
@Override
public boolean isOutputAllFieldsAsText() {
return showAdditionalProblemInfo;
}
@Override
public void setOutputAllFieldsAsText(boolean bShowFullText) {
showAdditionalProblemInfo = bShowFullText;
}
public String outputAllFieldsAsTextTipText() {
return "Output all available data fields or only the selected entries as text.";
}
public void hideHideable() {
setOutputVerbosity(getOutputVerbosity());
}
@Override
public void setOutputVerbosity(SelectedTag sTag) {
outputVerbosity = sTag;
GenericObjectEditor.setHideProperty(this.getClass(), "outputVerbosityK", sTag.getSelectedTagID() != VERBOSITY_KTH_IT);
}
public void setOutputVerbosity(int i) {
outputVerbosity.setSelectedTag(i);
GenericObjectEditor.setHideProperty(this.getClass(), "outputVerbosityK", outputVerbosity.getSelectedTagID() != VERBOSITY_KTH_IT);
}
@Override
public SelectedTag getOutputVerbosity() {
return outputVerbosity;
}
public String outputVerbosityTipText() {
return "Set the data output level.";
}
@Override
public int getOutputVerbosityK() {
return verboK;
}
@Override
public void setOutputVerbosityK(int k) {
verboK = k;
}
public String outputVerbosityKTipText() {
return "Set the interval of data output for intermediate verbosity (in generations).";
}
@Override
public SelectedTag getOutputTo() {
return outputTo;
}
@Override
public void setOutputTo(SelectedTag tag) {
outputTo = tag;
}
public void setOutputTo(int i) {
outputTo.setSelectedTag(i);
}
public String outputToTipText() {
return "Set the output destination; to deactivate output, set verbosity to none.";
}
@Override
public StringSelection getFieldSelection() {
return graphSel;
}
@Override
public void setFieldSelection(StringSelection v) {
graphSel = v;
}
public String fieldSelectionTipText() {
return "Select the data fields to be collected and plotted. Note that only simple types can be plotted to the GUI.";
}
/**
* May be called to dynamically alter the set of graphs that can be
* selected, using a list of informer instances, which usually are the
* problem and the optimizer instance.
*
* @see InterfaceAdditionalPopulationInformer
*/
public void setInformers(List<InterfaceAdditionalPopulationInformer> informers) {
ArrayList<String> headerFields = new ArrayList<String>();
ArrayList<String> infoFields = new ArrayList<String>();
// parse list of header elements, show additional Strings according to names.
for (InterfaceAdditionalPopulationInformer inf : informers) {
String[] dataHeader = inf.getAdditionalDataHeader();
headerFields.addAll(Arrays.asList(dataHeader));
if (infoFields.size() < headerFields.size()) { // add info strings for tool tips - fill up with null if none have been returned.
String[] infos = inf.getAdditionalDataInfo();
if (infos != null) {
if (infos.length != dataHeader.length) {
System.out.println(BeanInspector.toString(infos));
System.out.println(BeanInspector.toString(dataHeader));
EVAERROR.errorMsgOnce("Warning, mismatching number of headers and additional data fields for " + inf.getClass() + " (" + dataHeader.length + " vs. " + infos.length + ").");
}
infoFields.addAll(Arrays.asList(infos));
}
while (infoFields.size() < headerFields.size()) {
infoFields.add(null);
}
}
// header += inf.getAdditionalDataHeader(null); // lets hope this works with a null
}
// create additional fields to be selectable by the user, defined by the informer headers
// StringSelection ss = new StringSelection(GraphSelectionEnum.getAndAppendArray(headerFields.toArray(new String[headerFields.size()])));
StringSelection ss = new StringSelection(GraphSelectionEnum.currentBest, GraphSelectionEnum.getInfoStrings(),
headerFields, infoFields.toArray(new String[infoFields.size()]));
ss.takeOverSelection(graphSel);
// System.out.println("In " + this + ": setting new informers: " + BeanInspector.toString(ss.getStrings()));
// This works!
setFieldSelection(ss);
// System.out.println("After: " + this);
}
}

View File

@ -58,21 +58,21 @@ public class StatisticsStandalone extends AbstractStatistics implements Interfac
}
public StatisticsStandalone(String resultFileName) {
this(resultFileName, 1, resultFileName==null ? StatsParameter.VERBOSITY_NONE : StatsParameter.VERBOSITY_FINAL, false);
this(resultFileName, 1, resultFileName==null ? StatisticsParameter.VERBOSITY_NONE : StatisticsParameter.VERBOSITY_FINAL, false);
}
public StatisticsStandalone(String resultFileName, int multiRuns, int verbosity, boolean outputAllFieldsAsText) {
this(StatsParameter.getInstance(false));
this(StatisticsParameter.getInstance(false));
m_StatsParams.setMultiRuns(multiRuns);
m_StatsParams.setOutputVerbosity(m_StatsParams.getOutputVerbosity().setSelectedTag(verbosity));
m_StatsParams.SetResultFilePrefix(resultFileName);
m_StatsParams.setResultFilePrefix(resultFileName);
m_StatsParams.setOutputAllFieldsAsText(outputAllFieldsAsText);
if (resultFileName==null) m_StatsParams.getOutputTo().setSelectedTag(StatsParameter.OUTPUT_WINDOW);
else m_StatsParams.setOutputTo(m_StatsParams.getOutputTo().setSelectedTag(StatsParameter.OUTPUT_FILE));
if (resultFileName==null) m_StatsParams.getOutputTo().setSelectedTag(StatisticsParameter.OUTPUT_WINDOW);
else m_StatsParams.setOutputTo(m_StatsParams.getOutputTo().setSelectedTag(StatisticsParameter.OUTPUT_FILE));
}
public StatisticsStandalone() {
this(new StatsParameter());
this(new StatisticsParameter());
}
protected void initPlots(PopulationInterface pop, List<InterfaceAdditionalPopulationInformer> informerList) {

View File

@ -43,25 +43,23 @@ import java.util.logging.Logger;
* from AbstractStatistics.
*/
public class StatisticsWithGUI extends AbstractStatistics implements Serializable, InterfaceStatistics {
private static final long serialVersionUID = 3213603978877954103L;
private static final Logger LOGGER = Logger.getLogger(eva2.EvAInfo.defaultLogger);
private static final Logger LOGGER = Logger.getLogger(StatisticsWithGUI.class.getName());
// Plot frames:
private GraphWindow[] fitnessFrame; // frame for the fitness plots
private Graph[][] fitnessGraph;
private Graph[][] statGraph;
private String graphInfoString;
protected int plotCounter;
private MainAdapterClient mainAdapterClient; // the connection to the client MainAdapter
private JTextoutputFrameInterface proxyPrinter;
/* List of descriptor strings and optional indices. strictly its
* redundant since super.lastGraphSelection is always available.
* However it spares some time.
/*
* List of descriptor strings and optional indices. strictly its redundant
* since super.lastGraphSelection is always available. However it spares
* some time.
*/
private transient List<Pair<String, Integer>> graphDesc = null;
protected static String hostName = null;
/**
@ -82,17 +80,18 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
} catch (Exception ex) {
LOGGER.log(Level.WARNING, "Could not retrieve hostname.", ex);
}
} else hostName = "localhost";
} else {
hostName = "localhost";
}
if ((client == null) || client.getHostName().equals(hostName)) {
m_StatsParams = StatsParameter.getInstance(true);
m_StatsParams = StatisticsParameter.getInstance(true);
proxyPrinter = new JTextoutputFrame("TextOutput of " + hostName);
} else { // we use RMI
m_StatsParams = (InterfaceStatisticsParameter) RMIProxyLocal.newInstance(
StatsParameter.getInstance(true));
proxyPrinter = (JTextoutputFrameInterface) RMIProxyRemote.newInstance(new
JTextoutputFrame("TextOutput " + hostName),
StatisticsParameter.getInstance(true));
proxyPrinter = (JTextoutputFrameInterface) RMIProxyRemote.newInstance(new JTextoutputFrame("TextOutput " + hostName),
mainAdapterClient);
}
addTextListener(proxyPrinter);
@ -109,7 +108,9 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
// m_PlotCounter = m_StatsParams.GetPlotoutput();
if ((fitnessFrame != null) && (fitnessFrame[0] != null)) {
PlotInterface p = fitnessFrame[0].getPlotter();
if ((p!=null) && p.isValid()) ((Plot)p).getFunctionArea().clearLegend();
if ((p != null) && p.isValid()) {
((Plot) p).getFunctionArea().clearLegend();
}
}
}
@ -122,7 +123,9 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
}
int fullRuns = optRunsPerformed;
if (!normal) fullRuns--;
if (!normal) {
fullRuns--;
}
// unite the graphs only if the break was "normal"
if ((m_StatsParams.getMultiRuns() > 1) && (statGraph != null)) {
@ -156,8 +159,10 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
}
protected void initPlots(PopulationInterface pop, List<InterfaceAdditionalPopulationInformer> informerList) {
if (TRACE) System.out.println("initPlots");
if (m_StatsParams instanceof StatsParameter) {
if (TRACE) {
System.out.println("initPlots");
}
if (m_StatsParams instanceof StatisticsParameter) {
// StringSelection ss = ((StatsParameter)m_StatsParams).getGraphSelection();
graphDesc = lastFieldSelection.getSelectedWithIndex();
// for (int i=0; i<description.get(0).length; i++) graphDesc.add(description.get(0)[i]);
@ -189,8 +194,8 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
fitnessGraph[i][j].jump();
}
}
if (m_StatsParams.getMultiRuns() > 1 &&
m_StatsParams.GetUseStatPlot() == true) {
if (m_StatsParams.getMultiRuns() > 1
&& m_StatsParams.getUseStatPlot() == true) {
// String Info = m_StatsParams.GetInfoString();
statGraph = new Graph[windowCount][];
for (int i = 0; i < statGraph.length; i++) {
@ -237,10 +242,13 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
// boolean doPlotAdditionalInfo = m_StatsParams.isOutputAdditionalInfo();
for (int i = 0; i < graphDesc.size(); i++) {
Integer colIndex = i + 1; // always add one because the function calls are located in column zero
if (lastIsShowFull) colIndex = 1+graphDesc.get(i).tail;
if (lastIsShowFull) {
colIndex = 1 + graphDesc.get(i).tail;
}
// plot the column as indicated by the graph description
if (currentStatDoubleData[colIndex]!=null) plotFitnessPoint(0, subGraph++, functionCalls, currentStatDoubleData[colIndex]);
else {
if (currentStatDoubleData[colIndex] != null) {
plotFitnessPoint(0, subGraph++, functionCalls, currentStatDoubleData[colIndex]);
} else {
// EVAERROR.errorMsgOnce("Error, data field " + graphDesc.get(i).head + " does not contain primitive data and cannot be plotted.");
subGraph++; // increase index anyways or the name assignment gets inconsistent
}
@ -249,8 +257,9 @@ public class StatisticsWithGUI extends AbstractStatistics implements Serializabl
}
/**
* This method is more or less deprecated. The current standard population does not
* define specific data. However its used by the ES module implementation.
* This method is more or less deprecated. The current standard population
* does not define specific data. However its used by the ES module
* implementation.
*/
public void plotSpecificData(PopulationInterface pop, List<InterfaceAdditionalPopulationInformer> informer) {
double[] specificData = pop.getSpecificData();

View File

@ -1,419 +0,0 @@
package eva2.server.stat;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import eva2.gui.BeanInspector;
import eva2.gui.GenericObjectEditor;
import eva2.server.go.InterfaceNotifyOnInformers;
import eva2.server.go.problems.InterfaceAdditionalPopulationInformer;
import eva2.tools.EVAERROR;
import eva2.tools.SelectedTag;
import eva2.tools.Serializer;
import eva2.tools.StringSelection;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.util.logging.Level;
import java.util.logging.Logger;
/**
* A set of parameters for statistics in EvA2. Several data entries are provided by the AbstractStatistics class,
* others by the additional informers. This class allows customization of entries and frequency of data output.
* Data entries can be selected using a StringSelection instance.
* There is a switch called "output full data as text" which will be interpreted by AbstractStatistics showing
* all or only the selected entities.
*
* @see AbstractStatistics
* @author mkron
*/
public class StatsParameter implements InterfaceStatisticsParameter, InterfaceNotifyOnInformers, Serializable {
private static final long serialVersionUID = -8681061379203108390L;
private static boolean TRACE = false;
private static final Logger LOGGER = Logger.getLogger(eva2.EvAInfo.defaultLogger);
public final static int VERBOSITY_NONE = 0;
public final static int VERBOSITY_FINAL = 1;
public final static int VERBOSITY_KTH_IT = 2;
public final static int VERBOSITY_ALL = 3;
SelectedTag outputVerbosity = new SelectedTag("No output", "Final results", "K-th iterations", "All iterations");
public final static int OUTPUT_FILE = 0;
public final static int OUTPUT_WINDOW = 1;
public final static int OUTPUT_FILE_WINDOW = 2;
SelectedTag outputTo = new SelectedTag("File (current dir.)", "Text-window", "Both file and text-window");
private int verboK = 10;
// private int m_PlotFitness = PLOT_BEST;
private int m_Textoutput = 0;
// private int m_Plotoutput = 1;
private int m_MultiRuns = 1;
private String m_ResultFilePrefix = "EvA2";
protected String m_Name = "not defined";
// protected String m_InfoString = "";
private boolean m_useStatPlot = true;
private boolean showAdditionalProblemInfo = false;
private double m_ConvergenceRateThreshold=0.001;
private StringSelection graphSel = new StringSelection(GraphSelectionEnum.currentBest, GraphSelectionEnum.getInfoStrings());
/**
*
*/
public static StatsParameter getInstance(boolean loadDefaultSerFile) {
if (loadDefaultSerFile) {
return getInstance("Statistics.ser");
} else {
return new StatsParameter();
}
}
/**
* Load or create a new instance of the class.
*
* @return A loaded (from file) or new instance of the class.
*/
public static StatsParameter getInstance(String serFileName) {
StatsParameter instance = null;
try {
FileInputStream fileStream = new FileInputStream(serFileName);
instance = (StatsParameter) Serializer.loadObject(fileStream);
} catch (FileNotFoundException ex) {
LOGGER.log(Level.WARNING, "Could not store instance object.", ex);
}
if (instance == null) {
instance = new StatsParameter();
}
return instance;
}
/**
*
*/
public StatsParameter() {
m_Name = "Statistics";
outputVerbosity.setSelectedTag(VERBOSITY_KTH_IT);
outputTo.setSelectedTag(1);
}
/**
*
*/
public String toString() {
String ret = "\r\nStatParameter (" + super.toString() + "):\r\nm_MultiRuns=" + m_MultiRuns +
", m_Textoutput=" + m_Textoutput +
// ", m_Plotoutput=" + m_Plotoutput +
", verbosity= " + outputVerbosity.getSelectedString() +
"\nTo " + outputTo.getSelectedString() +
", " + BeanInspector.toString(graphSel.getStrings());
return ret;
}
/**
*
*/
public void saveInstance() {
try {
FileOutputStream fileStream = new FileOutputStream("Statistics.ser");
Serializer.storeObject(fileStream, this);
} catch (FileNotFoundException ex) {
LOGGER.log(Level.WARNING, "Could not store instance object.", ex);
}
}
/**
*
*/
private StatsParameter(StatsParameter Source) {
m_ConvergenceRateThreshold = Source.m_ConvergenceRateThreshold;
m_useStatPlot = Source.m_useStatPlot;
m_Textoutput = Source.m_Textoutput;
// m_Plotoutput = Source.m_Plotoutput;
// m_PlotFitness = Source.m_PlotFitness;
m_MultiRuns = Source.m_MultiRuns;
m_ResultFilePrefix = Source.m_ResultFilePrefix;
verboK = Source.verboK;
}
/**
*
*/
public Object getClone() {
return new StatsParameter(this);
}
/**
*
*/
public String getName() {
return m_Name;
}
public static String globalInfo() {
return "Configure statistics and output of the optimization run. Changes to the data selection state will not take effect during a run.";
}
// /**
// *
// */
// public String plotFrequencyTipText() {
// return "Frequency how often the fitness plot gets an update. plotoutput=1 -> there is a output every generation. plotoutput<0 -> there is no plot output";
// }
// /**
// *
// */
// public String printMeanTipText() {
// return "Prints the mean of the fitness plot. Makes only sense when multiRuns > 1;";
// }
/**
*
*/
public void setMultiRuns(int x) {
m_MultiRuns = x;
}
/**
*
*/
public int getMultiRuns() {
return m_MultiRuns;
}
/**
*
*/
public String multiRunsTipText() {
return "Number of independent optimization runs to evaluate.";
}
// /**
// *
// */
// public String GetInfoString() {
// return m_InfoString;
// }
//
// /**
// *
// */
// public void setInfoString(String s) {
// m_InfoString = s;
// }
/**
*
*/
public String infoStringTipText() {
return "Infostring displayed on fitness graph by prssing the right mouse button.";
}
/**
* Use averaged graph for multi-run plots or not
*/
public boolean GetUseStatPlot() {
return m_useStatPlot;
}
/**
* Activate or deactivate averaged graph for multi-run plots
*/
public void setUseStatPlot(boolean x) {
m_useStatPlot = x;
}
public String useStatPlotTipText() {
return "Plotting each fitness graph separately if multiruns > 1.";
}
/**
*
*/
public void SetResultFilePrefix(String x) {
if (x==null) m_ResultFilePrefix = "";
else m_ResultFilePrefix = x;
}
/**
*
*/
public String getResultFilePrefix() {
return m_ResultFilePrefix;
}
public void SetShowTextOutput(boolean show) {
// activate if not activated
if (show && outputTo.getSelectedTagID() == 0) outputTo.setSelectedTag(2);
// deactivate if activated
else if (!show && outputTo.getSelectedTagID()>0) outputTo.setSelectedTag(0);
}
public boolean isShowTextOutput() {
return outputTo.getSelectedTagID()>0;
}
// /**
// *
// */
// public String resultFileNameTipText() {
// return "File name for the result file. If empty or 'none', no output file will be created.";
// }
public String convergenceRateThresholdTipText() {
return "Provided the optimal fitness is at zero, give the threshold below which it is considered as 'reached'";
}
/**
*
* @param x
*/
public void setConvergenceRateThreshold(double x) {
m_ConvergenceRateThreshold = x;
}
/**
*
*/
public double getConvergenceRateThreshold() {
return m_ConvergenceRateThreshold;
}
// /**
// * @return the showOutputData
// */
// public boolean isShowTextOutput() {
// return showTextOutput;
// }
// /**
// *
// * @param showOutputData the showOutputData to set
// */
// public void setShowTextOutput(boolean bShow) {
// this.showTextOutput = bShow;
// }
// public String showTextOutputTipText() {
// return "Indicates whether further text output should be printed";
// }
public boolean isOutputAllFieldsAsText() {
return showAdditionalProblemInfo;
}
public void setOutputAllFieldsAsText(boolean bShowFullText) {
showAdditionalProblemInfo = bShowFullText;
}
public String outputAllFieldsAsTextTipText() {
return "Output all available data fields or only the selected entries as text.";
}
public void hideHideable() {
setOutputVerbosity(getOutputVerbosity());
}
public void setOutputVerbosity(SelectedTag sTag) {
outputVerbosity = sTag;
GenericObjectEditor.setHideProperty(this.getClass(), "outputVerbosityK", sTag.getSelectedTagID() != VERBOSITY_KTH_IT);
}
public void setOutputVerbosity(int i) {
outputVerbosity.setSelectedTag(i);
GenericObjectEditor.setHideProperty(this.getClass(), "outputVerbosityK", outputVerbosity.getSelectedTagID() != VERBOSITY_KTH_IT);
}
public SelectedTag getOutputVerbosity() {
return outputVerbosity;
}
public String outputVerbosityTipText() {
return "Set the data output level.";
}
public int getOutputVerbosityK() {
return verboK;
}
public void setOutputVerbosityK(int k) {
verboK = k;
}
public String outputVerbosityKTipText() {
return "Set the interval of data output for intermediate verbosity (in generations).";
}
public SelectedTag getOutputTo() {
return outputTo;
}
public void setOutputTo(SelectedTag tag) {
outputTo = tag;
}
public void setOutputTo(int i) {
outputTo.setSelectedTag(i);
}
public String outputToTipText() {
return "Set the output destination; to deactivate output, set verbosity to none.";
}
public StringSelection getFieldSelection() {
return graphSel;
}
public void setFieldSelection(StringSelection v) {
graphSel = v;
}
public String fieldSelectionTipText() {
return "Select the data fields to be collected and plotted. Note that only simple types can be plotted to the GUI.";
}
/**
* May be called to dynamically alter the set of graphs that can be selected,
* using a list of informer instances, which usually are the problem and the
* optimizer instance.
*
* @see InterfaceAdditionalPopulationInformer
*/
public void setInformers(
List<InterfaceAdditionalPopulationInformer> informers) {
ArrayList<String> headerFields = new ArrayList<String>();
ArrayList<String> infoFields = new ArrayList<String>();
// parse list of header elements, show additional Strings according to names.
for (InterfaceAdditionalPopulationInformer inf : informers) {
String[] dataHeader = inf.getAdditionalDataHeader();
headerFields.addAll(Arrays.asList(dataHeader));
if (infoFields.size()<headerFields.size()) { // add info strings for tool tips - fill up with null if none have been returned.
String[] infos = inf.getAdditionalDataInfo();
if (infos!=null) {
if (infos.length!=dataHeader.length) {
System.out.println(BeanInspector.toString(infos));
System.out.println(BeanInspector.toString(dataHeader));
EVAERROR.errorMsgOnce("Warning, mismatching number of headers and additional data fields for " + inf.getClass() + " ("+dataHeader.length+ " vs. " + infos.length + ").");
}
infoFields.addAll(Arrays.asList(infos));
}
while (infoFields.size()<headerFields.size()) infoFields.add(null);
}
// header += inf.getAdditionalDataHeader(null); // lets hope this works with a null
}
// create additional fields to be selectable by the user, defined by the informer headers
// StringSelection ss = new StringSelection(GraphSelectionEnum.getAndAppendArray(headerFields.toArray(new String[headerFields.size()])));
StringSelection ss = new StringSelection(GraphSelectionEnum.currentBest, GraphSelectionEnum.getInfoStrings(),
headerFields, infoFields.toArray(new String[infoFields.size()]));
ss.takeOverSelection(graphSel);
// System.out.println("In " + this + ": setting new informers: " + BeanInspector.toString(ss.getStrings()));
// This works!
setFieldSelection(ss);
// System.out.println("After: " + this);
}
}

View File

@ -18,6 +18,7 @@ import eva2.gui.BeanInspector;
*
*/
public class StringSelection implements Serializable {
private static final long serialVersionUID = -1512329288445831907L;
private String[] strObjects;
private String[] toolTips;
@ -26,7 +27,8 @@ public class StringSelection implements Serializable {
private transient Class<? extends Enum> enumClass = null;
/**
* Constructor with a String array of selectable strings and optional descriptions.
* Constructor with a String array of selectable strings and optional
* descriptions.
*
* @param sArr a String array of selectable strings
* @param tips descriptive strings of same length or null
@ -40,8 +42,9 @@ public class StringSelection implements Serializable {
}
/**
* Constructor with a String array of selectable strings and optional descriptions.
* A single element is preselected by index, all others deselected.
* Constructor with a String array of selectable strings and optional
* descriptions. A single element is preselected by index, all others
* deselected.
*
* @param sArr a String array of selectable strings
* @param tips descriptive strings of same length or null
@ -49,7 +52,9 @@ public class StringSelection implements Serializable {
*/
public StringSelection(String[] sArr, String[] tips, int initialSel) {
this(sArr, tips);
if (initialSel<getLength()) setSelected(initialSel, true);
if (initialSel < getLength()) {
setSelected(initialSel, true);
}
enumClass = null;
}
@ -85,8 +90,9 @@ public class StringSelection implements Serializable {
}
/**
* Construct a string selection that allows all enum fields of the given type plus a list of additional
* strings to be selected. The enum fields will be first in the selection list.
* Construct a string selection that allows all enum fields of the given
* type plus a list of additional strings to be selected. The enum fields
* will be first in the selection list.
*
* @param e
* @param headerFields
@ -117,8 +123,11 @@ public class StringSelection implements Serializable {
* @return a descriptive String for element i or null
*/
public String getElementInfo(int i) {
if (toolTips!=null && (toolTips.length>i)) return toolTips[i];
else return null;
if (toolTips != null && (toolTips.length > i)) {
return toolTips[i];
} else {
return null;
}
}
/**
@ -157,8 +166,9 @@ public class StringSelection implements Serializable {
// return e.toString().equals(strObjects[e.ordinal()]);
// } else return false;
if (enumClass != null) {
if (e.getClass().equals(enumClass)) return isSelected(e.ordinal());
else {
if (e.getClass().equals(enumClass)) {
return isSelected(e.ordinal());
} else {
System.err.println("Error, the string selection was constructed with a different enum class - invalid request (StringSelection.isSelected(Enum)");
return false;
}
@ -169,8 +179,8 @@ public class StringSelection implements Serializable {
}
/**
* Check if a given string is selected within this instance. If the
* String is not found, false is returned.
* Check if a given string is selected within this instance. If the String
* is not found, false is returned.
*
* @param str
* @return
@ -186,7 +196,8 @@ public class StringSelection implements Serializable {
if (selIndex == null) {
System.err.println("Error, unknown string for StringSelection: " + str + ", selectable were " + BeanInspector.toString(getStrings()));
return false;
} return isSelected(selIndex);
}
return isSelected(selIndex);
// for (int i=0; i<strObjects.length; i++) {
// if (strObjects[i].equals(str)) return isSelected(i);
// }
@ -194,8 +205,8 @@ public class StringSelection implements Serializable {
}
/**
* Return the ordinal of the given String within the StringSelection. If
* the string could not be found, -1 is returned.
* Return the ordinal of the given String within the StringSelection. If the
* string could not be found, -1 is returned.
*
* @param str
* @return
@ -208,8 +219,11 @@ public class StringSelection implements Serializable {
}
}
Integer selIndex = stringToIndexHash.get(str);
if (selIndex==null) return -1;
else return selIndex.intValue();
if (selIndex == null) {
return -1;
} else {
return selIndex.intValue();
}
}
/**
@ -225,7 +239,7 @@ public class StringSelection implements Serializable {
if (index >= 0) {
setSelected(index, v);
} else {
System.err.println("Error, unknown string " + str + " cant be selected in " + this.getClass());
System.err.println("Error, unknown string " + str + " can't be selected in " + this.getClass());
}
}
@ -249,8 +263,8 @@ public class StringSelection implements Serializable {
}
/**
* Apply the selection state of the given instance to this instance. Compares
* Strings and takes over the selection state if they are equal.
* Apply the selection state of the given instance to this instance.
* Compares Strings and takes over the selection state if they are equal.
*
* @param sel
*/
@ -289,30 +303,42 @@ public class StringSelection implements Serializable {
*/
public String[] getSelected() {
ArrayList<String> ret = new ArrayList<String>();
for (int i=0; i<getLength(); i++) if (isSelected(i)) ret.add(getElement(i));
for (int i = 0; i < getLength(); i++) {
if (isSelected(i)) {
ret.add(getElement(i));
}
}
return ret.toArray(new String[ret.size()]);
}
/**
* Return a sub-list of the selected items paired up with the respective index.
* Return a sub-list of the selected items paired up with the respective
* index.
*
* @return
*/
public List<Pair<String, Integer>> getSelectedWithIndex() {
ArrayList<Pair<String, Integer>> ret = new ArrayList<Pair<String, Integer>>();
for (int i=0; i<getLength(); i++) if (isSelected(i)) ret.add(new Pair<String,Integer>(getElement(i), i));
for (int i = 0; i < getLength(); i++) {
if (isSelected(i)) {
ret.add(new Pair<String, Integer>(getElement(i), i));
}
}
return ret;
}
/**
* Return only those selected fields which are members of the given enum.
*
* @param e
* @return
*/
public Enum[] getSelectedEnum(Enum[] e) {
LinkedList<Integer> selectedList = new LinkedList<Integer>();
for (int i = 0; i < e.length; i++) {
if (isSelected(e[i])) selectedList.add(i);
if (isSelected(e[i])) {
selectedList.add(i);
}
}
Enum[] ret = (Enum[]) java.lang.reflect.Array.newInstance(e[0].getClass(), selectedList.size());
Iterator<Integer> iter = selectedList.iterator();

View File

@ -786,7 +786,7 @@ public class DArea extends JComponent implements DParent, Printable {
System.out.println("DArea.setVisibleRectangle(DRectangle)");
if (rect.isEmpty())
throw new IllegalArgumentException(
"You shopuld never try to set an empty rectangle\n"
"You should never try to set an empty rectangle\n"
+ "as the visible rectangle of an DArea");
if (!rect.equals(visible_rect) && rect.getWidth() > 0