import java.awt.*; import java.lang.*; import java.util.*; /** * This class shows the statistic of best and mean values through all * generations of the GA. * * coding: h.sarg * modified: 01/98 */ public class StatisticCanvas extends java.awt.Canvas { private boolean fontSet= false; private Font f; private FontMetrics fm; private int fw, fh; /** * draw a new image */ private boolean drawnew = false; /** * image buffer */ private Image buffered_image = null; /** * list for the best fitness per generation */ private Vector best = new Vector(100,200); /** * list for mean fitness per generation */ private Vector mean = new Vector(100,200); /** * scale value for the Canvas height */ private double maxval = -1.0; /** * assosiated ScrollPane */ private ScrollPane scroll=null; /** * length of the actual canvas */ private int length =0; /** * actual canvas changed */ private boolean changed=false; /** * actual canvas dimension */ private Dimension dim; /** * StatisticCanvas constructor comment. */ public StatisticCanvas() { super(); dim= new Dimension(10,10); drawnew=true; } /** * gets the statistic vector of the best individuals * @return statistic best vector */ public Vector getBest() { return best; } /** * gets the statistic vector of the mean individuals * @return statistic mean vector */ public Vector getMean() { return mean; } /** * sets the scrollpane data * @param s the associated scrollpane */ public void setData(ScrollPane s) { scroll = s; dim=scroll.getViewportSize(); this.setSize(length, dim.height-2); scroll.doLayout(); } /** * stores the best and mean values of each generation in vectors * @param best best fitness * @param mv mean fitness */ public void setValues(double best, double mv) { if(maxval0) { x=vsize*3; y=dim.height; if(changed==false) { if (scroll.getViewportSize().height!= dim.height) { dim=scroll.getViewportSize(); y=dim.height; changed=true; } } while(x>(length-33)) { if(length==0) { length+=200; } else length+=100; changed=true; } if(changed) { this.setSize(length, y-2); scroll.doLayout(); if (scroll.getViewportSize().height!= dim.height) { dim=scroll.getViewportSize(); y=dim.height; this.setSize(length, y-2); scroll.doLayout(); } scroll.setScrollPosition(length,0); changed=false; } buffered_image = this.createImage(this.getSize().width, this.getSize().height); Graphics gbuff = buffered_image.getGraphics(); setFont(gbuff); gbuff.setFont(f); y=y-2*fh; skal=(y-2)/maxval; gbuff.setColor(java.awt.Color.black); gbuff.drawLine(30,2,30,y+1); gbuff.drawLine(30,y+1,length,y+1); i=0; j=0; while(j450) delta=200; if(maxval>1400) delta=500; i=0; j=0; while(j