import java.applet.*; import java.awt.*; import java.lang.*; import ResultProcessor; /** * This class includes the main class and handels the dialogs and frames. * * coding: h.sarg * modified: 01/98 */ public class TSPGA extends Applet implements java.awt.event.ActionListener, java.awt.event.AdjustmentListener, java.awt.event.ItemListener, java.awt.event.WindowListener, java.awt.event.ComponentListener, Runnable, ResultProcessor { /** * hold the actual step in a generation * this means: 0 start position of the GA * 1 the selection is done * 2 the recombination is done * 3 the mutation is done * 4 the mutated individuals becoms evaluated */ private int step = 0; /** * hold the actual generation */ private int generation = 0; /** * Thread, when running the GA */ Thread TspThread = null; /** * reserve Individual */ private Individual helpindiv= null; /** * stop the running Thread */ private boolean stop=false; /** * only used to store the aktual individual number to show the recombination */ private int aktindivnr = 0; /** * only used to store the aktual step to show the recombination */ private int aktstep = 0; /** * array to hold result frames */ private FinalFrame[] finalarray = new FinalFrame[20]; /** * result frame counter */ private int finalcount = 0; //--------------------ABOUT DIALOG-------------------------------------------- private AboutDialog ivjAboutDialog = null; //--------------------RUN DIALOG---------------------------------------------- private RunDialog ivjRunDialog = null; //--------------------Grid DIALOG------------------------------------------- private Dialog ivjGridDialog = null; private Panel ivjGridPanel2 = null; private Button ivjGridClose = null; private Label ivjGridGenLabel = null; private Button ivjGridOk = null; private Panel ivjGridPanel1 = null; private IntTextField ivjGridText = null; private Label ivjGridTextLabel = null; //--------------------TOWN DIALOG--------------------------------------------- private Dialog ivjTownDialog = null; private Panel ivjTownPanel2 = null; private Button ivjTownClose = null; private Label ivjTownGenLabel = null; private Button ivjTownOk = null; private Panel ivjTownPanel1 = null; private IntTextField ivjTownText = null; private Label ivjTownTextLabel = null; //---------------------ERX FRAME---------------------------------------------- private ErxCanvas ivjErxCanvas = null; private Button ivjErxClose = null; private Frame ivjErxFrame = null; private Panel ivjErxPanel = null; private Button ivjErxStep = null; private Button ivjErxResult = null; private Button ivjErxTrace = null; //-------------------GA START------------------------------------------------- private Button ivjGaStart = null; //-------------------OPTIONS DIALOG------------------------------------------- private Checkbox ivjOptionsCheckbox = null; private Button ivjOptionsClose = null; private Button ivjOptionsDefault = null; private Dialog ivjOptionsDialog = null; private Label ivjOptionsGroupLabel = null; private IntTextField ivjOptionsGroupText = null; private Choice ivjOptionsMutChoice = null; private Label ivjOptionsMutmetLabel = null; private Label ivjOptionsMutnumLabel = null; private Label ivjOptionsMutprobLabel = null; private Scrollbar ivjOptionsMutScroll = null; private Button ivjOptionsOk = null; private Label ivjOptionsPopLabel = null; private IntTextField ivjOptionsPopText = null; private Label ivjOptionsRecmetLabel = null; private Label ivjOptionsRecnumLabel = null; private Choice ivjOptionsRecombChoice = null; private Scrollbar ivjOptionsRecombScroll = null; private Label ivjOptionsRecprobLabel = null; //--------------------PARENT FRAME-------------------------------------------- private Label ivjParentFitLabel1 = null; private Label ivjParentFitLabel2 = null; private Label ivjParentFitLabel3 = null; private Frame ivjParentFrame = null; private GridLayout ivjParentFrameGridLayout = null; private Label ivjParentIndivLabel1 = null; private Label ivjParentIndivLabel2 = null; private Label ivjParentIndivLabel3 = null; private Panel ivjParentPanel1 = null; private Panel ivjParentPanel2 = null; private Panel ivjParentPanel3 = null; private TravelCanvas ivjParentTravelCanvas1 = null; private TravelCanvas ivjParentTravelCanvas2 = null; private TravelCanvas ivjParentTravelCanvas3 = null; //--------------------POP FRAME----------------------------------------------- private PopCanvas ivjPopCanvas = null; private Frame ivjPopFrame = null; private ScrollPane ivjPopScrollPane = null; //--------------------RECOMB FRAME-------------------------------------------- private RecombCanvas ivjRecombCanvas = null; private Frame ivjRecombframe = null; private ScrollPane ivjRecombScrollPane = null; //--------------------SET TOWNS DIALOG---------------------------------------- private TownCanvas ivjSetTownCanvas = null; private Button ivjSetTownsClearAll = null; private Dialog ivjSetTownsDialog = null; private Button ivjSetTownsAdd = null; private Button ivjSetTownsSet = null; private Button ivjSetTownsOk = null; private Panel ivjSetTownsPanel = null; private Label ivjSetTownsLabel = null; //-------------------STATISTIC FRAME------------------------------------------ private CheckboxMenuItem ivjStartOptionsTowns = null; private MenuItem ivjStartSaveFinal = null; private Menu ivjStartOptionsMenu = null; private MenuItem ivjStartOptionsOptions = null; private MenuItem ivjStartOptionsProblem = null; private MenuItem ivjStartOptionsItem3 = null; private MenuItem ivjStartOptionsItem2 = null; private MenuItem ivjStartOptionsItem1 = null; private MenuItem ivjStartInfoAbout = null; private Menu ivjStartInfoMenu = null; private CheckboxMenuItem ivjStartOptionsFonts1 = null; private CheckboxMenuItem ivjStartOptionsFonts2 = null; private CheckboxMenuItem ivjStartOptionsFonts3 = null; private MenuItem ivjStartCalculateTSP = null; private MenuItem ivjStatisticGoItem3 = null; private MenuItem ivjStatisticGoItem2 = null; private MenuItem ivjStatisticGoItem1 = null; private Label ivjStatisticBestfitLabel = null; private Label ivjStatisticBestindivLabel = null; private Label ivjStatisticBestLabel = null; private StatisticCanvas ivjStatisticCanvas = null; private MenuItem ivjStatisticFileClose = null; private Menu ivjStatisticFileMenu = null; private Frame ivjStatisticFrame = null; private GridLayout ivjStatisticFrameGridLayout = null; private MenuBar ivjStatisticFrameMenuBar = null; private Label ivjStatisticGenLabel = null; private MenuItem ivjStatisticGoGen = null; private Menu ivjStatisticGoMenu = null; private MenuItem ivjStatisticGoRun = null; private MenuItem ivjStatisticGoStep = null; private Panel ivjStatisticLabelPanel = null; private Panel ivjStatisticLabelPanel1 = null; private FlowLayout ivjStatisticLabelPanelFlowLayout = null; private FlowLayout ivjStatisticLabelPanelFlowLayout1 = null; private Label ivjStatisticMeanfitLabel = null; private Label ivjStatisticMeanLabel = null; private ScrollPane ivjStatisticScrollPane = null; private Panel ivjStatisticStatisticPanel = null; private MenuItem ivjStatisticStopStop = null; private Panel ivjStatisticTravelPanel = null; private TravelCanvas ivjStatisticTravelCanvas = null; private Menu ivjStatisticWindowMenu = null; private MenuItem ivjStatisticWindowPop = null; private MenuItem ivjStatisticWindowRecomb = null; private MenuItem ivjStatisticSimulationSimulation = null; //---------------------STRING FRAME------------------------------------------- private StringCanvas ivjStringCanvas = null; private Button ivjStringClose = null; private Frame ivjStringFrame = null; private Panel ivjStringPanel = null; private Button ivjStringStep = null; private Button ivjStringResult = null; private Button ivjStringTrace = null; private DialogData ivjDialogData = new DialogData(); private TravelData ivjTravelData; private Algorithm ivjAlgorithm; /** * Method to handle events for the ActionListener interface. * @param e java.awt.event.ActionEvent */ public void actionPerformed(java.awt.event.ActionEvent e) { Object source = e.getSource(); if ((source == getStartOptionsOptions()) ) { Dialog ResDialog; ResDialog=getOptionsDialog(); ivjOptionsRecombChoice.select(ivjDialogData.rm); ivjOptionsMutChoice.select(ivjDialogData.mm); ivjOptionsRecombScroll.setValue(ivjDialogData.rp); ivjOptionsRecnumLabel.setText(ivjDialogData.rp+"%"); ivjOptionsMutScroll.setValue(ivjDialogData.mp); ivjOptionsMutnumLabel.setText(ivjDialogData.mp+"%"); ivjOptionsGroupText.setText(""+ivjDialogData.group); ivjOptionsPopText.setText(""+ivjDialogData.pop); ivjOptionsCheckbox.setState(ivjDialogData.elitism); ResDialog.show(); } if ((source == getGaStart()) ) { initConnections(); if(ivjStatisticFrame.isShowing()) { if(TspThread != null) { getStatisticStopStop().setEnabled(false); getStatisticGoGen().setEnabled(true); getStatisticGoStep().setEnabled(true); getStatisticWindowMenu().setEnabled(true); getStartOptionsMenu().setEnabled(true); TspThread.stop(); TspThread = null; } ivjStatisticCanvas.clear(); toStart(); disposeFrames(); getStatisticFrame().dispose(); ivjStatisticFrameMenuBar=null; if(ivjGaStart.isShowing()) { ivjGaStart.setLabel("Start"); } else { this.destroy(); System.exit(0); } } else { getStatisticFrame(); //ivjStatisticFrame.setSize(800,300); getStatisticFrame().show(); ivjGaStart.setLabel("Stop"); } } if ((source == getStartCalculateTSP()) ) { Font f=null; step=0; generation=0; Individual bestindiv = null; getStartOptionsTowns().setEnabled(false); getStartOptionsFonts1().setEnabled(false); getStartOptionsFonts().setEnabled(false); getStartOptionsFonts3().setEnabled(false); ivjStatisticCanvas.clear(); // initialize the GA ivjTravelData =new TravelData(ivjDialogData); ivjAlgorithm = new Algorithm(ivjDialogData, ivjTravelData); // initialize PopCanvas, RecombCanvas, StatisticCanvas ivjPopCanvas.setPopData(ivjStatisticScrollPane, ivjDialogData.pop,ivjTravelData,ivjDialogData.showtowns, ivjDialogData.largefonts,ivjDialogData.grid); ivjPopCanvas.setPop(ivjAlgorithm.getPop(1) ); ivjRecombCanvas.setRecombData(ivjRecombScrollPane, ivjDialogData.pop,ivjAlgorithm.getSelectionSize(),ivjTravelData,ivjDialogData.showtowns, ivjDialogData.largefonts,ivjDialogData.grid, ivjDialogData.mm); ivjStatisticTravelCanvas.setTravelData(ivjTravelData,ivjDialogData.showtowns, ivjDialogData.largefonts); bestindiv=ivjAlgorithm.getPop(1).getBest(); ivjStatisticTravelCanvas.setTravelIndiv(bestindiv); if(ivjDialogData.largefonts==1) { f = new Font("Monospaced",Font.PLAIN, 12); } if(ivjDialogData.largefonts==0) { f = new Font("Monospaced",Font.PLAIN, 11); } if(ivjDialogData.largefonts==2) { f = new Font("Monospaced",Font.PLAIN, 13); } ivjStatisticBestfitLabel.setFont(f); ivjStatisticBestindivLabel.setFont(f); ivjStatisticMeanfitLabel.setFont(f); ivjStatisticGenLabel.setFont(f); ivjStatisticMeanLabel.setFont(f); ivjStatisticBestLabel.setFont(f); ivjStatisticBestfitLabel.setText("Best Fitness: " + bestindiv.trimFit() ); ivjStatisticBestindivLabel.setText("The best trip for now: " + bestindiv.toLabelString()); helpindiv= new Individual(ivjDialogData.towns); helpindiv.setFitness(ivjAlgorithm.getPop(1).getMeanFit() ); ivjStatisticMeanfitLabel.setText("Mean Fitness: "+helpindiv.trimFit()); ivjStatisticGenLabel.setText("Gen.: "+generation +" "); ivjStatisticCanvas.setData(ivjStatisticScrollPane); ivjStatisticCanvas.setValues(ivjAlgorithm.getPop(1).getBestFit(), ivjAlgorithm.getPop(1).getMeanFit() ); ivjStatisticBestfitLabel.invalidate(); ivjStatisticBestindivLabel.invalidate(); ivjStatisticMeanfitLabel.invalidate(); ivjStatisticGenLabel.invalidate(); ivjStatisticMeanLabel.invalidate(); ivjStatisticBestLabel.invalidate(); getStatisticLabelPanel1().doLayout(); getStatisticLabelPanel().doLayout(); ivjStatisticGoGen.setEnabled(true); ivjStatisticGoRun.setEnabled(true); ivjStatisticWindowMenu.setEnabled(true); ivjStartSaveFinal.setEnabled(true); if(ivjDialogData.towns>26) { getStatisticGoStep().setEnabled(false); getStatisticWindowMenu().setEnabled(false); } else { getStatisticGoStep().setEnabled(true); getStatisticWindowPop().setEnabled(false); getPopFrame().show(); getRecombframe(); ivjRecombCanvas.setSelection(null); getStatisticWindowRecomb().setEnabled(false); getRecombframe().show(); } } if ((source == getOptionsDefault()) ) { ivjOptionsRecombChoice.select(DialogData.DEF_RM); ivjOptionsMutChoice.select(DialogData.DEF_MM); ivjOptionsRecombScroll.setValue(DialogData.DEF_RP); ivjOptionsRecnumLabel.setText(DialogData.DEF_RP+"%"); ivjOptionsMutScroll.setValue(DialogData.DEF_MP); ivjOptionsMutnumLabel.setText(DialogData.DEF_MP+"%"); ivjOptionsGroupText.setText(""+DialogData.DEF_GROUP); ivjOptionsPopText.setText(""+DialogData.DEF_POP); ivjOptionsCheckbox.setState(DialogData.DEF_ELITISM); } if ((source == getOptionsOk()) ) { if(ivjOptionsPopText.isValid() && ivjOptionsGroupText.isValid() ) { toStart(); ivjDialogData.setDialogData(ivjOptionsRecombChoice.getSelectedIndex(), ivjOptionsRecombScroll.getValue(), ivjOptionsMutChoice.getSelectedIndex(), ivjOptionsMutScroll.getValue(), ivjOptionsPopText.getValue(), ivjOptionsGroupText.getValue(), ivjOptionsCheckbox.getState()); System.out.println("hallo Dialog:" + ivjDialogData); getOptionsDialog().dispose(); } //disposeFrames(); } if ((source == getOptionsClose()) ) { getOptionsDialog().dispose(); } if ((source == getStatisticFileClose()) ) { if(TspThread != null) { getStatisticStopStop().setEnabled(false); getStatisticGoGen().setEnabled(true); getStatisticGoStep().setEnabled(true); getStatisticWindowMenu().setEnabled(true); getStartOptionsMenu().setEnabled(true); TspThread.stop(); TspThread = null; } ivjStatisticCanvas.clear(); toStart(); disposeFrames(); getStatisticFrame().dispose(); ivjStatisticFrameMenuBar=null; if(ivjGaStart.isShowing()) { ivjGaStart.setLabel("Start"); } else { this.destroy(); System.exit(0); } } if ((source == getStatisticSimulationSimulation()) ) { Individual[] indivarray; int i; int selectsize; // store the information about the crossover ivjAlgorithm.setSim(); ivjAlgorithm.crossover(); step++; // show the childs ivjRecombCanvas.setPop(ivjAlgorithm.getPop(2)); ivjStatisticSimulationSimulation.setEnabled(false); ivjStatisticGoMenu.setEnabled(false); ivjStatisticWindowMenu.setEnabled(false); ivjStartOptionsMenu.setEnabled(false); // crossover methods from 0 to 3 if(ivjDialogData.rm < 4) { selectsize=ivjAlgorithm.getSelectionSize(); getStringCanvas().setData(selectsize, ivjDialogData.towns, ivjDialogData.largefonts, ivjDialogData.rm); indivarray=ivjAlgorithm.getSelection(); i=0; while(i-1) { selectsize=ivjAlgorithm.getSelectionSize(); indivarray=ivjAlgorithm.getSelection(); aktindiv=ivjAlgorithm.getPop(2).getIndiv(aktindivnr); aktstep=aktindiv.getVisRecomb().getMaxStep(); ivjStringResult.setEnabled(true); ivjStringCanvas.setStep(aktstep); ivjStringTrace.setEnabled(false); } } if ((source == getStringStep()) ) { Individual[] indivarray; int i; int selectsize; Individual aktindiv; if(aktindivnr>-1) { selectsize=ivjAlgorithm.getSelectionSize(); indivarray=ivjAlgorithm.getSelection(); aktindiv=ivjAlgorithm.getPop(2).getIndiv(aktindivnr); aktstep++; if(aktstep<=aktindiv.getVisRecomb().getMaxStep()) { if(aktstep==aktindiv.getVisRecomb().getMaxStep()) { ivjStringResult.setEnabled(true); ivjStringTrace.setEnabled(false); } ivjStringCanvas.setStep(aktstep); } else { i=2+aktindivnr*2; while(i-1) { selectsize=ivjAlgorithm.getSelectionSize(); indivarray=ivjAlgorithm.getSelection(); aktindiv=ivjAlgorithm.getPop(2).getIndiv(aktindivnr); aktstep=aktindiv.getVisRecomb().getMaxStep(); ivjErxResult.setEnabled(true); ivjErxCanvas.setStep(aktstep); ivjErxTrace.setEnabled(false); } } if ((source == getErxStep()) ) { Individual[] indivarray; int i; int selectsize; Individual aktindiv; if(aktindivnr>-1) { selectsize=ivjAlgorithm.getSelectionSize(); indivarray=ivjAlgorithm.getSelection(); aktindiv=ivjAlgorithm.getPop(2).getIndiv(aktindivnr); aktstep++; if(aktstep<=aktindiv.getVisRecomb().getMaxStep()) { if(aktstep==aktindiv.getVisRecomb().getMaxStep()) { ivjErxResult.setEnabled(true); ivjErxTrace.setEnabled(false); } ivjErxCanvas.setStep(aktstep); } else { i=2+aktindivnr*2; while(i3) { ivjDialogData.townarray=ivjSetTownCanvas.getTownArray(); ivjDialogData.towns=ivjSetTownCanvas.getTowns(); getSetTownsDialog().dispose(); } ivjStatisticCanvas.clear(); toStart(); disposeFrames(); } if ((source == getSetTownsClearAll()) ) { ivjSetTownCanvas.clearTownCanvas(); ivjDialogData.towns=0; } if ((source == getStatisticWindowPop()) ) { ivjPopCanvas.setPop(ivjAlgorithm.getPop(1) ); ivjPopScrollPane.setScrollPosition(0,0); ivjPopScrollPane.doLayout(); ivjStatisticWindowPop.setEnabled(false); getPopFrame().show(); } if ((source == getStatisticWindowRecomb()) ) { if(step==0) ivjRecombCanvas.setSelection(null); if(step==1) { ivjRecombCanvas.setSelection(ivjAlgorithm.getSelection()); ivjRecombCanvas.setPop(null); ivjRecombCanvas.setMut(null); } if(step==2) { ivjRecombCanvas.setSelection(ivjAlgorithm.getSelection()); ivjRecombCanvas.setPop(ivjAlgorithm.getPop(2)); ivjRecombCanvas.setMut(null); } if(step==3) { ivjRecombCanvas.setSelection(ivjAlgorithm.getSelection()); ivjRecombCanvas.setPop(ivjAlgorithm.getPop(2)); ivjRecombCanvas.setMut(ivjAlgorithm.getPop(3)); } if(step==4) { ivjRecombCanvas.setSelection(ivjAlgorithm.getSelection()); ivjRecombCanvas.setPop(ivjAlgorithm.getPop(2)); ivjRecombCanvas.setMut(ivjAlgorithm.getPop(3)); } ivjRecombScrollPane.setScrollPosition(0,0); ivjRecombScrollPane.doLayout(); ivjStatisticWindowRecomb.setEnabled(false); getRecombframe().show(); } if ((source == getErxClose()) ) { Population pop; pop=ivjAlgorithm.getPop(2); for(int i=0;i<(ivjAlgorithm.getSelectionSize()/2);i++) { pop.getIndiv(i).delVisRecomb(); } ivjAlgorithm.unsetSim(); ivjStatisticGoMenu.setEnabled(true); ivjStatisticSimulationSimulation.setEnabled(false); ivjStartOptionsMenu.setEnabled(true); if(ivjDialogData.towns<27) { ivjStatisticWindowMenu.setEnabled(true); } getErxFrame().dispose(); } if ((source == getStringClose()) ) { getParentFrame().dispose(); } if ((source == getStartSaveFinal()) ) { if(ivjStatisticCanvas.getBest().size()>0) { if(finalcount<20||checkFrames()) { finalarray[finalcount]= new FinalFrame(); finalarray[finalcount].setTitle(ivjDialogData.toTitle()); finalarray[finalcount].setData( ivjDialogData, ivjTravelData, ivjStatisticBestfitLabel.getText(), ivjStatisticMeanfitLabel.getText(), ivjStatisticGenLabel.getText(), ivjStatisticBestindivLabel.getText(), ivjStatisticCanvas.getBest(), ivjStatisticCanvas.getMean(), ivjAlgorithm.getPop(1).getBest()); finalarray[finalcount].show(); finalcount++; } } } if ((source == getErxClose()) ) { getParentFrame().dispose(); } if ((source == getGridClose()) ) { getGridDialog().dispose(); } if ((source == getGridOk()) ) { if(ivjGridText.isValid()) { ivjDialogData.grid=ivjGridText.getValue(); ivjDialogData.townarray=null; ivjDialogData.towns=0; getSetTownCanvas().setTownData(ivjDialogData.townarray, ivjDialogData.grid); getGridDialog().dispose(); } } if ((source == getTownClose()) ) { getTownDialog().dispose(); } if ((source == getTownOk()) ) { if(ivjTownText.isValid()) { int help; help=ivjTownText.getValue(); ivjSetTownCanvas.setTownsRandom(help); ivjDialogData.towns=ivjSetTownCanvas.getTowns(); getTownDialog().dispose(); } } if ((source == getStartOptionsProblem()) ) { getSetTownCanvas().setTownData(ivjDialogData.townarray, ivjDialogData.grid); getSetTownsDialog().show(); } if ((source == getSetTownsAdd()) ) { getTownDialog(); ivjTownText.setText("5"); getTownDialog().show(); } if ((source == getSetTownsSet()) ) { getGridDialog(); ivjGridText.setText("" + ivjDialogData.grid); getGridDialog().show(); } } /** * initializes the application to start a new GA */ public void toStart() { getStatisticSimulationSimulation().setEnabled(false); getStatisticGoStep().setEnabled(false); getStatisticGoGen().setEnabled(false); getStatisticGoRun().setEnabled(false); getStatisticStopStop().setEnabled(false); getStatisticWindowMenu().setEnabled(false); getStartCalculateTSP().setEnabled(true); getStatisticGoMenu().setEnabled(true); ivjStatisticTravelCanvas.setTravelIndiv(null); getStartOptionsTowns().setEnabled(true); getStartOptionsFonts1().setEnabled(true); getStartOptionsFonts().setEnabled(true); getStartOptionsFonts3().setEnabled(true); getStartSaveFinal().setEnabled(false); ivjStatisticCanvas.clear(); ivjStatisticBestfitLabel.setText("Best Fitness: 0.0"); ivjStatisticBestindivLabel.setText("The best trip for now: "); ivjStatisticMeanfitLabel.setText("Mean Fitness: 0.0"); ivjStatisticGenLabel.setText("Gen.: 0"); getPopCanvas().disposeFrames(); getRecombCanvas().disposeFrames(); getPopFrame().dispose(); getRecombframe().dispose(); getErxFrame().dispose(); getParentFrame().dispose(); getStringFrame().dispose(); } /** * after successfull dialog the run thread gets started * @param source who initiates the dialog * @param result information about the dialog */ public void processResult(Dialog source, Object result) { if (source instanceof RunDialog) { ConnectInfo info = (ConnectInfo)result; ivjDialogData.genstep=info.value; ivjDialogData.update=info.ok; System.out.println(ivjDialogData); getStatisticStopStop().setEnabled(true); getStatisticWindowMenu().setEnabled(false); getStatisticGoGen().setEnabled(false); getStatisticGoStep().setEnabled(false); getStatisticGoRun().setEnabled(false); getStartCalculateTSP().setEnabled(false); getStartOptionsMenu().setEnabled(false); if(TspThread == null) { TspThread=new Thread (this); TspThread.start(); TspThread.setPriority(Thread.MIN_PRIORITY); } } } /** * checks if there are invalid frames stored * @return true if there is a free place in the array, otherwise false */ public boolean checkFrames() { int index=-1; boolean state=false; for(int i=0;i<20;i++) { if(finalarray[i].isShowing() ) { if(index>-1) { finalarray[index]=finalarray[i]; index+=1; } } else { if(index==-1) index=i; finalcount--; state=true; } } System.out.println("showing:" + finalcount+ "index= "+index+"\n"); return state; } /** * disposes all FinalFrames and is called before the parent window is * closed or a new TSP is set */ public void disposeFrames() { for(int i=0;i0) { if(step<2) { ivjAlgorithm.crossover(); ivjStatisticSimulationSimulation.setEnabled(false); ivjRecombCanvas.setSelection(null); //ivjRecombCanvas.setPop(ivjAlgorithm.getPop(2)); } if(step<3) { ivjAlgorithm.mutation(); ivjRecombCanvas.setSelection(null); //ivjRecombCanvas.setMut(ivjAlgorithm.getPop(3)); } if(step<4) { ivjAlgorithm.evaluate(); ivjRecombCanvas.setSelection(null); //ivjRecombCanvas.setMut(ivjAlgorithm.getPop(3)); } if(step<5) { Individual bestindiv = null; ivjAlgorithm.populate(); ivjPopCanvas.setPop(ivjAlgorithm.getPop(1) ); bestindiv=ivjAlgorithm.getPop(1).getBest(); ivjStatisticTravelCanvas.setTravelIndiv(bestindiv); ivjStatisticBestfitLabel.setText("Best Fitness: " + bestindiv.trimFit() ); ivjStatisticBestindivLabel.setText("The best trip for now: " + bestindiv.toLabelString() ); ivjStatisticCanvas.setValues(ivjAlgorithm.getPop(1).getBestFit(), ivjAlgorithm.getPop(1).getMeanFit() ); helpindiv.setFitness(ivjAlgorithm.getPop(1).getMeanFit() ); ivjStatisticMeanfitLabel.setText("Mean Fitness: "+helpindiv.trimFit()); } step=0; generation++; ivjStatisticGenLabel.setText("Gen.: "+generation); } ivjRecombCanvas.setSelection(null); ivjRecombCanvas.setPop(null); ivjRecombCanvas.setMut(null); int i=0; Individual bestindiv = null; while(istepheight) stepwidth=stepheight; else stepheight= stepwidth; ivjSetTownCanvas.setTownCanvas(stepwidth,stepheight); } if ((source == getStatisticFrame()) ) { int stepwidth; int stepheight; Dimension canvassize; //System.out.println("Resize StatisticFrame \n"); canvassize=ivjStatisticTravelCanvas.getSize(); stepwidth=(int)(canvassize.width/ivjDialogData.grid); stepheight=(int)(canvassize.height/ivjDialogData.grid); if(stepwidth>stepheight) stepwidth=stepheight; else stepheight= stepwidth; ivjStatisticTravelCanvas.setTravelCanvas(stepwidth,stepheight); ivjStatisticCanvas.setChanged(); } if ((source == getParentFrame()) ) { int stepwidth; int stepheight; Dimension canvassize; //System.out.println("Resize ParentFrame \n"); canvassize=ivjParentTravelCanvas1.getSize(); stepwidth=(int)(canvassize.width/ivjDialogData.grid); stepheight=(int)(canvassize.height/ivjDialogData.grid); if(stepwidth>stepheight) stepwidth=stepheight; else stepheight= stepwidth; ivjParentTravelCanvas1.setTravelCanvas(stepwidth,stepheight); canvassize=ivjParentTravelCanvas2.getSize(); stepwidth=(int)(canvassize.width/ivjDialogData.grid); stepheight=(int)(canvassize.height/ivjDialogData.grid); if(stepwidth>stepheight) stepwidth=stepheight; else stepheight= stepwidth; ivjParentTravelCanvas2.setTravelCanvas(stepwidth,stepheight); canvassize=ivjParentTravelCanvas3.getSize(); stepwidth=(int)(canvassize.width/ivjDialogData.grid); stepheight=(int)(canvassize.height/ivjDialogData.grid); if(stepwidth>stepheight) stepwidth=stepheight; else stepheight= stepwidth; ivjParentTravelCanvas3.setTravelCanvas(stepwidth,stepheight); } } /** * Method to handle events for the ComponentListener interface. * @param e java.awt.event.ComponentEvent */ public void componentShown(java.awt.event.ComponentEvent e) { } }