📄 gaclust.java
字号:
/* GAClust.java (P)2002 Dana Cristofor*//*GAClust - Clustering categorical databases using genetic algorithmsCopyright (C) 2002 Dana CristoforThis program is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2 of the License, or (atyour option) any later version.This program is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with this program; if not, write to the Free SoftwareFoundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307USAGAClust was written by Dana Cristofor (dana@cs.umb.edu).*/import laur.tools.*;import laur.tools.Timer;import javax.swing.*;import javax.swing.event.*;import javax.swing.border.*;import javax.swing.table.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.util.*;import java.text.*;/** * The GAClust GUI * * @version 1.0 * @author Dana Cristofor */public class GAClust extends JFrame implements ActionListener, ItemListener, ThreadMonitor{ // variables for database selection private String DBName; private int nRows; private int nCols; private Partition[] db; private Partition[] db_copy; // variables for genetic algorithm private int popSize; private int K; private int useTarget; private int targetId; private int useWeights; private double sampleDBPct; private int excludeAttr; private int noRemAttr; private double crossoverRate; private double mutationRate; private int classFitnessType; private int crossoverType; private int mutationType; private int distributionType; private int entropyMeasure; private int fitnessMeasure; private int minimization; private double fitnessThreshold; private int consecItrs; private int randseed; private Timer timer; private Partition refPart; // reference partition private GA ga; // genetic algorithm private GenSynDB genSynDB; // attribute weights private double[] wTargetCondOnDB; private double[] wDBCondOnTarget; private double[] weight; private double targetEntr; private int nColsClust; private int nColsClust_copy; private Random rand; private Chromosome finalChrom; private Integer noIterations; private boolean flipTarget; // variables for generate database tab private boolean isGenerating; private int nDBClasses; private int DBSeed; private int generateLarge; // miscellaneous private int status; // rembers the last fitness measure used private int lastFitnessMeasureUsed; // a ThreadMonitor reference used to refer to the monitor of a // thread that is executing at some point private ThreadMonitor monitor; private NumberFormat nf; private StringBuffer output; private ResultsTableModel resModel; private final int IDLE = 0; private final int GA_RUNNING = 1; private final int GENDB_RUNNING = 2; /** Creates new form GAClust */ public GAClust() { super("GAClust"); timer = new Timer(); nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(3); status = IDLE; resModel = null; initComponents(); } /** This method is called from within the constructor to * initialize the form. */ private void initComponents() { // initComponents MainMenuBar = new JMenuBar(); ProgramMenu = new JMenu(); ForceGCMenuItem = new JMenuItem(); ExitMenuItem = new JMenuItem(); HelpMenu = new JMenu(); TopicsMenuItem = new JMenuItem(); AboutMenuItem = new JMenuItem(); // Database Tab MainTabbedPane = new JTabbedPane(); DatabaseSplitPane = new JSplitPane(); DatabasePanel = new JPanel(); DatabaseCenterPanel = new JPanel(); DatabaseSouthPanel = new JPanel(); DBNameLabelPanel = new JPanel(); DBNameLabel = new JLabel(); DBNamePanel = new JPanel(); DBNameTextField = new JTextField(); BrowsePanel = new JPanel(); BrowseButton = new JButton(); NRowsLabelPanel = new JPanel(); NRowsLabel = new JLabel(); NRowsPanel = new JPanel(); NRowsTextField = new JTextField(); BogusLabel1 = new JLabel(); BogusLabel2 = new JLabel(); NAttrLabelPanel = new JPanel(); NAttrLabel = new JLabel(); NAttrPanel = new JPanel(); NAttrTextField = new JTextField(); OpenButton = new JButton(); Results = new JPanel(); ResultsNorth = new JPanel(); ResultsSouth = new JPanel(); DatabaseScrollPane = new JScrollPane(); DBLogTextArea = new JTextArea(); DBTableScrollPane = new JScrollPane(); DBTable = new JTable(); // Generate Tab GenerateSplitPane = new JSplitPane(); GenerateDBPanel = new JPanel(); GenerateDBNorthPanel = new JPanel(); GenerateDBSouthPanel = new JPanel(); GenDBNameLabelPanel = new JPanel(); GenDBNameLabel = new JLabel(); GenDBNamePanel = new JPanel(); GenDBNameTextField = new JTextField(); UseDefaultNamingCheckBox = new JCheckBox(); UseDefaultNamingPanel = new JPanel(); GenNRowsLabelPanel = new JPanel(); GenNRowsLabel = new JLabel(); GenNRowsPanel = new JPanel(); GenNRowsTextField = new JTextField(); GenBogusLabel1 = new JLabel(); GenNAttrLabelPanel = new JPanel(); GenNAttrLabel = new JLabel(); GenNAttrPanel = new JPanel(); GenNAttrTextField = new JTextField(); GenBogusLabel2 = new JLabel(); GenNClassesLabelPanel = new JPanel(); GenNClassesLabel = new JLabel(); GenNClassesPanel = new JPanel(); GenNClassesTextField = new JTextField(); GenBogusLabel3 = new JLabel(); GenRandomSeedLabelPanel = new JPanel(); GenRandomSeedLabel = new JLabel(); GenRandomSeedPanel = new JPanel(); GenRandomSeedTextField = new JTextField(); GenBogusLabel4 = new JLabel(); GenerateLargePanel = new JPanel(); GenerateLargeCheckBox = new JCheckBox(); GenBogusLabel5 = new JLabel(); GenBogusLabel6 = new JLabel(); GenerateButton = new JButton(); GenAbortButton = new JButton(); GenProgressBar = new JProgressBar(); GenProgressBarPanel = new JPanel(); GenResultsPanel = new JPanel(); GenResultsNorthPanel = new JPanel(); GenResultsSouthPanel = new JPanel(); GenDBTableScrollPane = new JScrollPane(); GenDBTable = new JTable(); GenLogScrollPane = new JScrollPane(); GenLogTextArea = new JTextArea(); // GA Tab GAHorizontalSplitPane = new JSplitPane(); GASplitPane = new JSplitPane(); GAPanel = new JPanel(); GACenterPanel = new JPanel(); GASouthPanel = new JPanel(); PopSizeLabelPanel = new JPanel(); PopSizeLabel = new JLabel(); PopSizePanel = new JPanel(); PopSizeTextField = new JTextField(); NClassesClustLabelPanel = new JPanel(); NClassesClustLabel = new JLabel(); NClassesClustPanel = new JPanel(); NClassesClustTextField = new JTextField(); CrossRateLabelPanel = new JPanel(); CrossRateLabel = new JLabel(); CrossRatePanel = new JPanel(); CrossRateTextField = new JTextField(); MutRateLabelPanel = new JPanel(); MutRateLabel = new JLabel(); MutRatePanel = new JPanel(); MutRateTextField = new JTextField(); ClassFitnessLabelPanel = new JPanel(); ClassFitnessLabel = new JLabel(); ClassFitnessPanel = new JPanel(); ClassFitnessComboBox = new JComboBox(); CrossTypeLabelPanel = new JPanel(); CrossTypeLabel = new JLabel(); CrossTypePanel = new JPanel(); CrossTypeComboBox = new JComboBox(); MutTypeLabelPanel = new JPanel(); MutTypeLabel = new JLabel(); MutTypePanel = new JPanel(); MutTypeComboBox = new JComboBox(); DistrTypeLabelPanel = new JPanel(); DistrTypeLabel = new JLabel(); DistrTypePanel = new JPanel(); DistrTypeComboBox = new JComboBox(); EntropyMeasureLabelPanel = new JPanel(); EntropyMeasureLabel = new JLabel(); EntropyMeasurePanel = new JPanel(); EntropyMeasureComboBox = new JComboBox(); FitnessMeasureLabelPanel = new JPanel(); FitnessMeasureLabel = new JLabel(); FitnessMeasurePanel = new JPanel(); FitnessMeasureComboBox = new JComboBox(); FitnessThresholdLabelPanel = new JPanel(); FitnessThresholdLabel = new JLabel(); FitnessThresholdPanel = new JPanel(); FitnessThresholdTextField = new JTextField(); ConsecItrsLabelPanel = new JPanel(); ConsecItrsLabel = new JLabel(); ConsecItrsPanel = new JPanel(); ConsecItrsTextField = new JTextField(); RandomSeedGALabelPanel = new JPanel(); RandomSeedGALabel = new JLabel(); RandomSeedGAPanel = new JPanel(); RandomSeedGATextField = new JTextField(); UseTargetPanel = new JPanel(); UseTargetCheckBox = new JCheckBox(); TargetIDLabelPanel = new JPanel(); TargetIDLabel = new JLabel(); TargetIDPanel = new JPanel(); TargetIDTextField = new JTextField(); UseWeightsPanel = new JPanel(); UseWeightsCheckBox = new JCheckBox(); SampleDBPctLabelPanel = new JPanel(); SampleDBPctLabel = new JLabel(); SampleDBPctPanel = new JPanel(); SampleDBPctTextField = new JTextField(); ExcludeAttrPanel = new JPanel(); ExcludeAttrCheckBox = new JCheckBox(); NRemAttrLabelPanel = new JPanel(); NRemAttrLabel = new JLabel(); NRemAttrPanel = new JPanel(); NRemAttrTextField = new JTextField(); MinimizationLabelPanel = new JPanel(); MinimizationLabel = new JLabel(); MinimizationPanel = new JPanel(); MinimizationComboBox = new JComboBox(); ClusterPanel = new JPanel(); ClusterButton = new JButton(); ClusterAbortButton = new JButton(); BogusLabel3 = new JLabel(); BogusLabel4 = new JLabel(); BogusLabel5 = new JLabel(); GAResultsPanel = new JPanel(); GAResultsNorthPanel = new JPanel(); GAResultsScrollPane = new JScrollPane(); GAResultsTable = new JTable(); GALogPanel = new JPanel(); GAScrollPane = new JScrollPane(); GALogTextArea = new JTextArea(); jfc = new JFileChooser(); jfc.setCurrentDirectory(new File(".")); ProgramMenu.setText(Strings.PROGRAM); ProgramMenu.setMnemonic(KeyEvent.VK_P); ProgramMenu.addActionListener(this); ForceGCMenuItem.setText(Strings.FORCEGC + Strings.dots); ForceGCMenuItem.addActionListener(this); ForceGCMenuItem.setMnemonic(KeyEvent.VK_F); ProgramMenu.add(ForceGCMenuItem); ProgramMenu.addSeparator(); ExitMenuItem.setText(Strings.EXIT); ExitMenuItem.addActionListener(this); ExitMenuItem.setMnemonic(KeyEvent.VK_X); ProgramMenu.add(ExitMenuItem); MainMenuBar.add(ProgramMenu); HelpMenu.setText(Strings.HELP); HelpMenu.setMnemonic(KeyEvent.VK_H); TopicsMenuItem.setText(Strings.TOPICS + Strings.dots); TopicsMenuItem.addActionListener(this); TopicsMenuItem.setMnemonic(KeyEvent.VK_T); HelpMenu.add(TopicsMenuItem); HelpMenu.addSeparator(); AboutMenuItem.setText(Strings.ABOUT + Strings.dots); AboutMenuItem.addActionListener(this); AboutMenuItem.setMnemonic(KeyEvent.VK_A); HelpMenu.add(AboutMenuItem); MainMenuBar.add(HelpMenu); getContentPane().add(MainMenuBar, BorderLayout.NORTH); setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE); addWindowListener(new WindowAdapter() { public void windowClosing(WindowEvent evt) { exitForm(evt); } }); Dimension prefDim = new Dimension(150, 25); DatabaseSplitPane.setOrientation(JSplitPane.VERTICAL_SPLIT); DatabasePanel.setLayout(new BorderLayout()); DatabasePanel.setBorder(new TitledBorder(Strings.DBBORDERTITLE)); DatabaseCenterPanel.setLayout(new GridLayout(3, 3)); DBNameLabel.setPreferredSize(prefDim); DBNameLabel.setHorizontalAlignment(SwingConstants.RIGHT); DBNameLabel.setText("Database name :"); DBNameLabelPanel.add(DBNameLabel); DatabaseCenterPanel.add(DBNameLabelPanel); DBNameTextField.setPreferredSize(prefDim); DBNameTextField.setText("zoo.data"); DBNameTextField.setToolTipText(Strings.DBNAME_TIP); DBNamePanel.add(DBNameTextField); DatabaseCenterPanel.add(DBNamePanel); BrowseButton.setText("Browse"); BrowseButton.addActionListener(this); BrowseButton.setMnemonic(KeyEvent.VK_B); BrowseButton.setToolTipText(Strings.BROWSE_TIP); BrowsePanel.add(BrowseButton); DatabaseCenterPanel.add(BrowsePanel);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -