📄 config.java
字号:
import javax.swing.*;import java.awt.*;import java.awt.event.*;import javax.swing.border.*;public class Config extends JDialog implements ActionListener{ public static String popsize="100"; public static String newind_maxdepth="6"; public static String pcross="80.0"; public static String preproduction="0.0"; public static String pmutation="20.0"; public static String maxdepth_after_cross="20"; public static String maxdepth_subtreeofmutation="4"; public static String rawText; public static int Gene_Choice=2; public static int Select_Choice=0; public static int Function_Choice=0; //xy 坐标象限 XYPlot xy_axis=new XYPlot(); //user selection for terminals and functions public static int [] term_selections={0,1}; public static int [] func_selections={0,1,2}; //选择方法 public static final int FITNESS_PROPORTIONATE = 0; public static final int TOURNAMENT = 1; //树的生成方法 public static final int GROW = 0; public static final int FULL = 1; public static final int RAMPED_HALF_AND_HALF = 2; //VERY IMPORTANT HERE //GP running reference contained by Config public static GP gp=null; public JPanel p1=new JPanel(); public JPanel p2=new JPanel(); public JPanel p21=new JPanel(); public JPanel p22=new JPanel(); public JPanel p23=new JPanel(); public JPanel p3=new JPanel(); public JPanel p4=new JPanel(); public JButton b1=new JButton("随机创建"); public JButton ok=new JButton("确认"); public JButton cancel=new JButton("取消"); public String [] Gene_Method={"FULL","GROW","RAMP_HALF_AND HALF"}; public String [] Select_Method={"Wheel","Tournament"}; public String [] Function_Set={"ADD","SUB","MULTI","DIV","SIN","COS","EXP"}; public String [] Terminal_Set={"CONSTANT","VARIABLE(X)"}; public String [] Calculate_Functions ={"3*x^4 - 3*x + 1","sin(x)","cos(x)"}; public JTextField t1=new JTextField(popsize); public JTextField t2=new JTextField(newind_maxdepth); public JTextField t3=new JTextField(pcross); public JTextField t4=new JTextField(preproduction); public JTextField t5=new JTextField(pmutation); public JTextField t6=new JTextField(maxdepth_after_cross); public JTextField t7=new JTextField(maxdepth_subtreeofmutation); public JComboBox c1=new JComboBox(Gene_Method); public JComboBox c2=new JComboBox(Select_Method); public JComboBox c3=new JComboBox(Calculate_Functions); public JLabel j1=new JLabel("种群数量"); public JLabel j2=new JLabel("个体最大深度"); public JLabel j3=new JLabel("交叉率"); public JLabel j4=new JLabel("繁殖率"); public JLabel j5=new JLabel("变异率"); public JLabel j6=new JLabel("交叉后最大深度"); public JLabel j7=new JLabel("变异子树最大深度"); public JLabel j8=new JLabel("种群产生策略"); public JLabel j9=new JLabel("选择策略"); public JTextArea a1=new JTextArea(); public JList l1=new JList(Function_Set); public JList l2=new JList(Terminal_Set); public Config() { Container conn=this.getContentPane(); b1.addActionListener(this); ok.addActionListener(this); cancel.addActionListener(this); p1.setLayout(new GridLayout(9,2)); p1.add(j1); p1.add(t1); p1.add(j2); p1.add(t2); p1.add(j3); p1.add(t3); p1.add(j4); p1.add(t4); p1.add(j5); p1.add(t5); p1.add(j6); p1.add(t6); p1.add(j7); p1.add(t7); p1.add(j8); p1.add(c1); p1.add(j9); p1.add(c2); this.c3.setBackground(Color.orange); l1.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); l2.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); conn.setLayout(new GridLayout(2,1)); conn.add(p1); p4.setLayout(new BorderLayout()); p2.setLayout(new GridLayout(1,3)); p21.setLayout(new BorderLayout()); p22.setLayout(new BorderLayout()); p23.setLayout(new BorderLayout()); p21.add(new JLabel("坐标数据"),BorderLayout.NORTH); p21.add(new JScrollPane(a1),BorderLayout.CENTER); p21.add(b1,BorderLayout.SOUTH); p2.add(p21); p22.add(new JLabel("函数集"),BorderLayout.NORTH); p22.add(new JScrollPane(l1)); p2.add(p22); p23.add(new JLabel("终结符集"),BorderLayout.NORTH); p23.add(new JScrollPane(l2)); p2.add(p23); p4.add(p2,BorderLayout.CENTER); p3.add(ok); p3.add(cancel); p4.add(p3,BorderLayout.SOUTH); conn.add(p4); rawText=Original_Function_Point_Set.makeDefaultFitnessCases(0); gp=new GP(0); c3.addActionListener(this); } public void actionPerformed(ActionEvent e) { if(e.getSource()==b1) { Function_Choice=this.c3.getSelectedIndex(); rawText=Original_Function_Point_Set.makeDefaultFitnessCases(Function_Choice); a1.setText(rawText); } else if(e.getSource()==ok) { popsize=t1.getText(); newind_maxdepth=t2.getText(); pcross=t3.getText(); preproduction=t4.getText(); pmutation=t5.getText(); maxdepth_after_cross=t6.getText(); maxdepth_subtreeofmutation=t7.getText(); Gene_Choice=c1.getSelectedIndex(); Select_Choice=c2.getSelectedIndex(); System.out.println(Gene_Choice); System.out.println(Select_Choice); rawText=a1.getText(); System.out.println(rawText); func_selections=l1.getSelectedIndices(); term_selections=l2.getSelectedIndices(); System.out.println(func_selections+""+term_selections); for(int i=0;i<func_selections.length;i++) { System.out.println(func_selections[i]); } if(popsize.equals("") ||newind_maxdepth.equals("") ||pcross.equals("") ||preproduction.equals("") ||pmutation.equals("") ||maxdepth_after_cross.equals("") ||maxdepth_subtreeofmutation.equals("") ||rawText.equals("") ||func_selections.length==0 ||term_selections.length==0 ) { JOptionPane.showMessageDialog(this,"输入参数不合法,请重新输入!"); } else { gp=new GP(Function_Choice);//用新的参数来启动一个新的GP xy_axis.setTrace(0,gp.fitnessCases.data); this.setVisible(false); this.validate(); } } else if(e.getSource()==cancel){ this.hide(); this.validate(); } else if(e.getSource()==c3) { int index=c3.getSelectedIndex(); this.rawText=Original_Function_Point_Set.makeDefaultFitnessCases(index); gp=new GP(index); RealPoint []temp=gp.fitnessCases.data; this.xy_axis.setTrace(0,temp); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -