1 | /* |
---|
2 | Copyright 2006 by Sean Paus |
---|
3 | Licensed under the Academic Free License version 3.0 |
---|
4 | See the file "LICENSE" for more information |
---|
5 | */ |
---|
6 | |
---|
7 | |
---|
8 | /* |
---|
9 | * Created on Mar 6, 2005 12:48:58 PM |
---|
10 | * |
---|
11 | * By: spaus |
---|
12 | */ |
---|
13 | package ec.display; |
---|
14 | |
---|
15 | import java.awt.Component; |
---|
16 | import java.awt.Dimension; |
---|
17 | import java.awt.FileDialog; |
---|
18 | import java.awt.GridBagConstraints; |
---|
19 | import java.awt.GridBagLayout; |
---|
20 | import java.awt.event.ItemEvent; |
---|
21 | import java.awt.event.KeyEvent; |
---|
22 | import java.io.File; |
---|
23 | import java.io.FileInputStream; |
---|
24 | import java.io.IOException; |
---|
25 | import java.io.InputStreamReader; |
---|
26 | import java.io.LineNumberReader; |
---|
27 | |
---|
28 | import javax.swing.BorderFactory; |
---|
29 | import javax.swing.Box; |
---|
30 | import javax.swing.ButtonGroup; |
---|
31 | import javax.swing.JButton; |
---|
32 | import javax.swing.JCheckBox; |
---|
33 | import javax.swing.JLabel; |
---|
34 | import javax.swing.JPanel; |
---|
35 | import javax.swing.JRadioButton; |
---|
36 | import javax.swing.JScrollPane; |
---|
37 | import javax.swing.JTable; |
---|
38 | import javax.swing.JTextField; |
---|
39 | import javax.swing.border.TitledBorder; |
---|
40 | import javax.swing.table.DefaultTableColumnModel; |
---|
41 | import javax.swing.table.DefaultTableModel; |
---|
42 | |
---|
43 | import ec.EvolutionState; |
---|
44 | import ec.Evolve; |
---|
45 | import ec.util.Parameter; |
---|
46 | |
---|
47 | /** |
---|
48 | * @author spaus |
---|
49 | */ |
---|
50 | public class ControlPanel extends JPanel |
---|
51 | { |
---|
52 | |
---|
53 | final Console console; |
---|
54 | |
---|
55 | final static String P_JOBFILEPREFIX = "job-file-prefix"; |
---|
56 | |
---|
57 | JLabel jLabel = null; |
---|
58 | JTextField numGensField = null; |
---|
59 | JCheckBox quitOnRunCompleteCheckbox = null; // @jve:decl-index=0: |
---|
60 | JLabel jLabel1 = null; |
---|
61 | JTextField numJobsField = null; // @jve:decl-index=0: |
---|
62 | JLabel jLabel2 = null; |
---|
63 | JLabel jLabel3 = null; |
---|
64 | JTextField evalThreadsField = null; |
---|
65 | JTextField breedThreadsField = null; |
---|
66 | JPanel jPanel = null; |
---|
67 | JRadioButton seedFileRadioButton = null; |
---|
68 | JTextField seedFileField = null; |
---|
69 | JButton seedFileButton = null; // @jve:decl-index=0: |
---|
70 | JRadioButton randomSeedsRadioButton = null; |
---|
71 | JTable seedsTable = null; |
---|
72 | JScrollPane jScrollPane = null; |
---|
73 | JLabel jLabel6 = null; |
---|
74 | JCheckBox checkpointCheckBox = null; |
---|
75 | JPanel checkpointPanel = null; |
---|
76 | JLabel jLabel7 = null; |
---|
77 | JTextField checkpointModuloField = null; |
---|
78 | JLabel jLabel8 = null; |
---|
79 | JTextField prefixField = null; |
---|
80 | JLabel jLabel10 = null; |
---|
81 | |
---|
82 | ButtonGroup seedButtonGroup; |
---|
83 | JButton generateSeedsButton = null; |
---|
84 | JRadioButton sequentialSeedsRadioButton = null; |
---|
85 | JLabel jLabel5 = null; |
---|
86 | JTextField jobFilePrefixField = null; |
---|
87 | /** |
---|
88 | * This is the default constructor |
---|
89 | */ |
---|
90 | public ControlPanel(Console console) |
---|
91 | { |
---|
92 | super(); |
---|
93 | this.console = console; |
---|
94 | initialize(); |
---|
95 | } |
---|
96 | |
---|
97 | public void disableControls() |
---|
98 | { |
---|
99 | breedThreadsField.setEnabled(false); |
---|
100 | checkpointCheckBox.setEnabled(false); |
---|
101 | checkpointModuloField.setEnabled(false); |
---|
102 | evalThreadsField.setEnabled(false); |
---|
103 | generateSeedsButton.setEnabled(false); |
---|
104 | jobFilePrefixField.setEnabled(false); |
---|
105 | numGensField.setEnabled(false); |
---|
106 | numJobsField.setEnabled(false); |
---|
107 | prefixField.setEnabled(false); |
---|
108 | quitOnRunCompleteCheckbox.setEnabled(false); |
---|
109 | sequentialSeedsRadioButton.setEnabled(false); |
---|
110 | randomSeedsRadioButton.setEnabled(false); |
---|
111 | seedFileRadioButton.setEnabled(false); |
---|
112 | seedFileButton.setEnabled(false); |
---|
113 | seedsTable.setEnabled(false); |
---|
114 | } |
---|
115 | |
---|
116 | public void enableControls() |
---|
117 | { |
---|
118 | breedThreadsField.setEnabled(true); |
---|
119 | checkpointCheckBox.setEnabled(true); |
---|
120 | if (checkpointCheckBox.isSelected()) |
---|
121 | { |
---|
122 | checkpointModuloField.setEnabled(true); |
---|
123 | prefixField.setEnabled(true); |
---|
124 | } |
---|
125 | evalThreadsField.setEnabled(true); |
---|
126 | jobFilePrefixField.setEnabled(true); |
---|
127 | numGensField.setEnabled(true); |
---|
128 | numJobsField.setEnabled(true); |
---|
129 | quitOnRunCompleteCheckbox.setEnabled(true); |
---|
130 | sequentialSeedsRadioButton.setEnabled(true); |
---|
131 | randomSeedsRadioButton.setEnabled(true); |
---|
132 | if (randomSeedsRadioButton.isSelected()) |
---|
133 | { |
---|
134 | generateSeedsButton.setEnabled(true); |
---|
135 | } |
---|
136 | seedFileRadioButton.setEnabled(true); |
---|
137 | if (seedFileRadioButton.isSelected()) |
---|
138 | { |
---|
139 | seedFileButton.setEnabled(true); |
---|
140 | } |
---|
141 | seedsTable.setEnabled(true); |
---|
142 | } |
---|
143 | |
---|
144 | /** |
---|
145 | * This method initializes this |
---|
146 | * |
---|
147 | * @return void |
---|
148 | */ |
---|
149 | void initialize() |
---|
150 | { |
---|
151 | jLabel5 = new JLabel(); |
---|
152 | GridBagConstraints gridBagConstraints28 = new GridBagConstraints(); |
---|
153 | GridBagConstraints gridBagConstraints37 = new GridBagConstraints(); |
---|
154 | jLabel10 = new JLabel(); |
---|
155 | GridBagConstraints gridBagConstraints45 = new GridBagConstraints(); |
---|
156 | jLabel6 = new JLabel(); |
---|
157 | jLabel3 = new JLabel(); |
---|
158 | jLabel2 = new JLabel(); |
---|
159 | jLabel1 = new JLabel(); |
---|
160 | jLabel = new JLabel(); |
---|
161 | GridBagConstraints gridBagConstraints1 = new GridBagConstraints(); |
---|
162 | GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
---|
163 | GridBagConstraints gridBagConstraints4 = new GridBagConstraints(); |
---|
164 | GridBagConstraints gridBagConstraints5 = new GridBagConstraints(); |
---|
165 | GridBagConstraints gridBagConstraints6 = new GridBagConstraints(); |
---|
166 | GridBagConstraints gridBagConstraints7 = new GridBagConstraints(); |
---|
167 | GridBagConstraints gridBagConstraints8 = new GridBagConstraints(); |
---|
168 | GridBagConstraints gridBagConstraints9 = new GridBagConstraints(); |
---|
169 | GridBagConstraints gridBagConstraints10 = new GridBagConstraints(); |
---|
170 | GridBagConstraints gridBagConstraints11 = new GridBagConstraints(); |
---|
171 | GridBagConstraints gridBagConstraints25 = new GridBagConstraints(); |
---|
172 | GridBagConstraints gridBagConstraints26 = new GridBagConstraints(); |
---|
173 | GridBagConstraints gridBagConstraints35 = new GridBagConstraints(); |
---|
174 | GridBagConstraints gridBagConstraints36 = new GridBagConstraints(); |
---|
175 | this.setLayout(new GridBagLayout()); |
---|
176 | this.setSize(975, 300); |
---|
177 | this.setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); |
---|
178 | gridBagConstraints1.gridx = 1; |
---|
179 | gridBagConstraints1.gridy = 2; |
---|
180 | gridBagConstraints1.gridheight = 1; |
---|
181 | gridBagConstraints1.gridwidth = 1; |
---|
182 | gridBagConstraints1.anchor = java.awt.GridBagConstraints.WEST; |
---|
183 | jLabel.setText("# Generations:"); |
---|
184 | gridBagConstraints2.gridx = 2; |
---|
185 | gridBagConstraints2.gridy = 2; |
---|
186 | gridBagConstraints2.fill = java.awt.GridBagConstraints.HORIZONTAL; |
---|
187 | gridBagConstraints2.weightx = 0.0D; |
---|
188 | gridBagConstraints2.insets = new java.awt.Insets(0,5,0,0); |
---|
189 | gridBagConstraints2.ipadx = 30; |
---|
190 | gridBagConstraints4.gridx = 1; |
---|
191 | gridBagConstraints4.gridy = 6; |
---|
192 | gridBagConstraints4.anchor = java.awt.GridBagConstraints.WEST; |
---|
193 | gridBagConstraints4.gridwidth = 2; |
---|
194 | gridBagConstraints5.gridx = 1; |
---|
195 | gridBagConstraints5.gridy = 0; |
---|
196 | gridBagConstraints5.anchor = java.awt.GridBagConstraints.NORTHWEST; |
---|
197 | jLabel1.setText("# Jobs:"); |
---|
198 | gridBagConstraints6.gridx = 2; |
---|
199 | gridBagConstraints6.gridy = 0; |
---|
200 | gridBagConstraints6.fill = java.awt.GridBagConstraints.HORIZONTAL; |
---|
201 | gridBagConstraints6.insets = new java.awt.Insets(0,5,0,0); |
---|
202 | gridBagConstraints6.anchor = java.awt.GridBagConstraints.NORTHWEST; |
---|
203 | gridBagConstraints6.gridwidth = 1; |
---|
204 | gridBagConstraints7.gridx = 1; |
---|
205 | gridBagConstraints7.gridy = 3; |
---|
206 | gridBagConstraints7.anchor = java.awt.GridBagConstraints.WEST; |
---|
207 | jLabel2.setText("# Evaluation Threads:"); |
---|
208 | gridBagConstraints8.gridx = 1; |
---|
209 | gridBagConstraints8.gridy = 4; |
---|
210 | gridBagConstraints8.anchor = java.awt.GridBagConstraints.WEST; |
---|
211 | gridBagConstraints8.gridwidth = 1; |
---|
212 | jLabel3.setText("# Breeder Threads:"); |
---|
213 | gridBagConstraints9.gridx = 2; |
---|
214 | gridBagConstraints9.gridy = 3; |
---|
215 | gridBagConstraints9.fill = java.awt.GridBagConstraints.HORIZONTAL; |
---|
216 | gridBagConstraints9.insets = new java.awt.Insets(0,5,0,0); |
---|
217 | gridBagConstraints10.gridx = 2; |
---|
218 | gridBagConstraints10.gridy = 4; |
---|
219 | gridBagConstraints10.fill = java.awt.GridBagConstraints.HORIZONTAL; |
---|
220 | gridBagConstraints10.insets = new java.awt.Insets(0,5,0,0); |
---|
221 | gridBagConstraints11.gridx = 11; |
---|
222 | gridBagConstraints11.gridy = 0; |
---|
223 | gridBagConstraints11.gridwidth = 6; |
---|
224 | gridBagConstraints11.fill = java.awt.GridBagConstraints.BOTH; |
---|
225 | gridBagConstraints11.gridheight = 13; |
---|
226 | gridBagConstraints11.weightx = 1.0D; |
---|
227 | gridBagConstraints25.gridx = 1; |
---|
228 | gridBagConstraints25.gridy = 5; |
---|
229 | gridBagConstraints25.anchor = java.awt.GridBagConstraints.WEST; |
---|
230 | gridBagConstraints25.insets = new java.awt.Insets(0,0,0,0); |
---|
231 | jLabel6.setText("Verbosity:"); |
---|
232 | gridBagConstraints26.gridx = 2; |
---|
233 | gridBagConstraints26.gridy = 5; |
---|
234 | gridBagConstraints26.fill = java.awt.GridBagConstraints.HORIZONTAL; |
---|
235 | gridBagConstraints26.anchor = java.awt.GridBagConstraints.WEST; |
---|
236 | gridBagConstraints26.weightx = 0.0D; |
---|
237 | gridBagConstraints26.insets = new java.awt.Insets(0,5,0,0); |
---|
238 | gridBagConstraints26.ipadx = 30; |
---|
239 | gridBagConstraints35.gridx = 1; |
---|
240 | gridBagConstraints35.gridy = 7; |
---|
241 | gridBagConstraints35.anchor = java.awt.GridBagConstraints.WEST; |
---|
242 | gridBagConstraints35.gridwidth = 2; |
---|
243 | gridBagConstraints35.gridheight = 1; |
---|
244 | gridBagConstraints36.gridx = 1; |
---|
245 | gridBagConstraints36.gridy = 8; |
---|
246 | gridBagConstraints36.gridheight = 1; |
---|
247 | gridBagConstraints36.gridwidth = 3; |
---|
248 | gridBagConstraints36.anchor = java.awt.GridBagConstraints.NORTH; |
---|
249 | gridBagConstraints36.ipadx = 107; |
---|
250 | gridBagConstraints45.gridx = 5; |
---|
251 | gridBagConstraints45.gridy = 8; |
---|
252 | gridBagConstraints45.weighty = 1.0D; |
---|
253 | jLabel10.setText(""); |
---|
254 | gridBagConstraints28.gridx = 1; |
---|
255 | gridBagConstraints28.gridy = 1; |
---|
256 | gridBagConstraints28.anchor = java.awt.GridBagConstraints.WEST; |
---|
257 | jLabel5.setText("Job file prefix:"); |
---|
258 | gridBagConstraints37.gridx = 2; |
---|
259 | gridBagConstraints37.gridy = 1; |
---|
260 | gridBagConstraints37.fill = java.awt.GridBagConstraints.HORIZONTAL; |
---|
261 | gridBagConstraints37.insets = new java.awt.Insets(0,5,0,0); |
---|
262 | gridBagConstraints37.gridwidth = 3; |
---|
263 | this.add(jLabel, gridBagConstraints1); |
---|
264 | this.add(getNumGensField(), gridBagConstraints2); |
---|
265 | this.add(getQuitOnRunCompleteCheckbox(), gridBagConstraints4); |
---|
266 | this.add(jLabel1, gridBagConstraints5); |
---|
267 | this.add(getNumJobsField(), gridBagConstraints6); |
---|
268 | this.add(jLabel2, gridBagConstraints7); |
---|
269 | this.add(jLabel3, gridBagConstraints8); |
---|
270 | this.add(getEvalThreadsField(), gridBagConstraints9); |
---|
271 | this.add(getBreedThreadsField(), gridBagConstraints10); |
---|
272 | this.add(getJPanel(), gridBagConstraints11); |
---|
273 | this.add(jLabel6, gridBagConstraints25); |
---|
274 | //this.add(getVerbosityField(), gridBagConstraints26); |
---|
275 | this.add(getCheckpointCheckBox(), gridBagConstraints35); |
---|
276 | this.add(getCheckpointPanel(), gridBagConstraints36); |
---|
277 | this.add(jLabel10, gridBagConstraints45); |
---|
278 | this.add(jLabel5, gridBagConstraints28); |
---|
279 | this.add(getJobFilePrefixField(), gridBagConstraints37); |
---|
280 | this.add(Box.createRigidArea(new Dimension(5,0))); |
---|
281 | } |
---|
282 | /** |
---|
283 | * This method initializes jTextField |
---|
284 | * |
---|
285 | * @return javax.swing.JTextField |
---|
286 | */ |
---|
287 | JTextField getNumGensField() |
---|
288 | { |
---|
289 | if (numGensField == null) |
---|
290 | { |
---|
291 | numGensField = new JTextField(); |
---|
292 | numGensField.addKeyListener(new java.awt.event.KeyAdapter() |
---|
293 | { |
---|
294 | public void keyPressed(KeyEvent e) |
---|
295 | { |
---|
296 | if (e.getKeyCode() == KeyEvent.VK_ENTER) |
---|
297 | { |
---|
298 | console.parameters.set(new Parameter(EvolutionState.P_GENERATIONS), ((JTextField)e.getSource()).getText()); |
---|
299 | } |
---|
300 | else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) |
---|
301 | { |
---|
302 | ((JTextField)e.getSource()).setText(console.parameters.getString(new Parameter(EvolutionState.P_GENERATIONS),null)); |
---|
303 | } |
---|
304 | } |
---|
305 | }); |
---|
306 | } |
---|
307 | return numGensField; |
---|
308 | } |
---|
309 | /** |
---|
310 | * This method initializes jCheckBox |
---|
311 | * |
---|
312 | * @return javax.swing.JCheckBox |
---|
313 | */ |
---|
314 | JCheckBox getQuitOnRunCompleteCheckbox() |
---|
315 | { |
---|
316 | if (quitOnRunCompleteCheckbox == null) |
---|
317 | { |
---|
318 | quitOnRunCompleteCheckbox = new JCheckBox(); |
---|
319 | quitOnRunCompleteCheckbox.setText("Quit on Run Complete"); |
---|
320 | quitOnRunCompleteCheckbox.addItemListener(new java.awt.event.ItemListener() |
---|
321 | { |
---|
322 | public void itemStateChanged(java.awt.event.ItemEvent e) |
---|
323 | { |
---|
324 | console.parameters.set(new Parameter(EvolutionState.P_QUITONRUNCOMPLETE), |
---|
325 | "" + ((JCheckBox)e.getSource()).isSelected()); |
---|
326 | } |
---|
327 | }); |
---|
328 | } |
---|
329 | return quitOnRunCompleteCheckbox; |
---|
330 | } |
---|
331 | /** |
---|
332 | * This method initializes jTextField1 |
---|
333 | * |
---|
334 | * @return javax.swing.JTextField |
---|
335 | */ |
---|
336 | JTextField getNumJobsField() |
---|
337 | { |
---|
338 | if (numJobsField == null) |
---|
339 | { |
---|
340 | numJobsField = new JTextField(); |
---|
341 | numJobsField.addKeyListener(new java.awt.event.KeyAdapter() |
---|
342 | { |
---|
343 | public void keyPressed(java.awt.event.KeyEvent e) |
---|
344 | { |
---|
345 | if (e.getKeyCode() == KeyEvent.VK_ENTER) |
---|
346 | { |
---|
347 | resizeSeedTable(); |
---|
348 | } |
---|
349 | } |
---|
350 | }); |
---|
351 | } |
---|
352 | return numJobsField; |
---|
353 | } |
---|
354 | |
---|
355 | public int getNumJobs() |
---|
356 | { |
---|
357 | return Integer.valueOf(getNumJobsField().getText()).intValue(); |
---|
358 | } |
---|
359 | |
---|
360 | public int getThreadCount(String text) |
---|
361 | { |
---|
362 | if (text.toLowerCase().trim().equals("auto")) |
---|
363 | return Runtime.getRuntime().availableProcessors(); |
---|
364 | else return Integer.valueOf(text).intValue(); |
---|
365 | } |
---|
366 | |
---|
367 | |
---|
368 | /** |
---|
369 | * @throws NumberFormatException |
---|
370 | */ |
---|
371 | void resizeSeedTable() |
---|
372 | throws NumberFormatException |
---|
373 | { |
---|
374 | int numJobs = Integer.valueOf(numJobsField.getText()).intValue(); |
---|
375 | int breedThreads = getThreadCount(breedThreadsField.getText()); |
---|
376 | int evalThreads = getThreadCount(evalThreadsField.getText()); |
---|
377 | |
---|
378 | int numThreads = Math.max(breedThreads, evalThreads); |
---|
379 | |
---|
380 | DefaultTableModel model =(DefaultTableModel)seedsTable.getModel(); |
---|
381 | model.setColumnCount(numThreads); |
---|
382 | String[] columnHeaders = new String[numThreads]; |
---|
383 | for (int i = 0; i < numThreads; ++i) |
---|
384 | { |
---|
385 | columnHeaders[i] = "Thread "+i; |
---|
386 | } |
---|
387 | |
---|
388 | model.setColumnIdentifiers(columnHeaders); |
---|
389 | model.setRowCount(numJobs); |
---|
390 | |
---|
391 | if (seedFileRadioButton.isSelected()) |
---|
392 | { |
---|
393 | File f = new File(seedFileField.getText()); |
---|
394 | try |
---|
395 | { |
---|
396 | loadSeeds(f); |
---|
397 | } |
---|
398 | catch (IOException ex) |
---|
399 | { |
---|
400 | System.err.println(ex.getMessage()); |
---|
401 | } |
---|
402 | } |
---|
403 | else if (randomSeedsRadioButton.isSelected()) |
---|
404 | { |
---|
405 | generateRandomSeeds(); |
---|
406 | } |
---|
407 | else if (sequentialSeedsRadioButton.isSelected()) |
---|
408 | { |
---|
409 | int seed; |
---|
410 | int i = 0; |
---|
411 | for (int thread = 0; thread < numThreads; ++thread) |
---|
412 | { |
---|
413 | try |
---|
414 | { |
---|
415 | seed = console.parameters.getInt(new Parameter("seed."+thread),null); |
---|
416 | } |
---|
417 | catch (NumberFormatException ex) |
---|
418 | { |
---|
419 | seed = getSeed(0,thread-1)+1; |
---|
420 | } |
---|
421 | for (int job = 0; job < numJobs; ++job) |
---|
422 | setSeed(""+(seed+(i++)),job,thread); |
---|
423 | } |
---|
424 | } |
---|
425 | else |
---|
426 | { |
---|
427 | for (int job = 0; job < numJobs; ++job) |
---|
428 | { |
---|
429 | for (int thread = 0; thread < numThreads; ++thread) |
---|
430 | { |
---|
431 | setSeed(console.parameters.getString(new Parameter("seed."+thread),null),job,thread); |
---|
432 | } |
---|
433 | } |
---|
434 | } |
---|
435 | } |
---|
436 | |
---|
437 | /** |
---|
438 | * @throws NumberFormatException |
---|
439 | */ |
---|
440 | void generateRandomSeeds() |
---|
441 | throws NumberFormatException |
---|
442 | { |
---|
443 | int numJobs = Integer.valueOf(numJobsField.getText()).intValue(); |
---|
444 | int breedThreads = getThreadCount(breedThreadsField.getText()); |
---|
445 | int evalThreads = getThreadCount(evalThreadsField.getText()); |
---|
446 | int numThreads = Math.max(breedThreads, evalThreads); |
---|
447 | |
---|
448 | int seed = (int)(System.currentTimeMillis()); |
---|
449 | for (int job = 0; job < numJobs; ++job) |
---|
450 | { |
---|
451 | for (int thread = 0; thread < numThreads; ++thread) |
---|
452 | { |
---|
453 | seed = seed+(job*Math.min(breedThreads, evalThreads))+(thread*Math.max(breedThreads, evalThreads)); |
---|
454 | setSeed(""+seed,job,thread); |
---|
455 | } |
---|
456 | } |
---|
457 | } |
---|
458 | |
---|
459 | public int getSeed(int experimentNum, int threadNum) |
---|
460 | { |
---|
461 | try { return Integer.valueOf((String)seedsTable.getValueAt(experimentNum, threadNum)).intValue(); } |
---|
462 | catch (RuntimeException e) |
---|
463 | { |
---|
464 | javax.swing.JOptionPane.showMessageDialog(null, "Value of seed for experiment " + experimentNum + |
---|
465 | " and thread " + threadNum + " not a fixed number: probably 'time'. Rebuilding random number seeds.", "Adjusting Seeds", |
---|
466 | javax.swing.JOptionPane.INFORMATION_MESSAGE); |
---|
467 | generateRandomSeeds(); |
---|
468 | return Integer.valueOf((String)seedsTable.getValueAt(experimentNum, threadNum)).intValue(); |
---|
469 | } |
---|
470 | } |
---|
471 | |
---|
472 | public void setSeed(String seed, int experimentNum, int threadNum) |
---|
473 | { |
---|
474 | seedsTable.setValueAt(seed, experimentNum, threadNum); |
---|
475 | } |
---|
476 | /** |
---|
477 | * This method initializes jTextField2 |
---|
478 | * |
---|
479 | * @return javax.swing.JTextField |
---|
480 | */ |
---|
481 | JTextField getEvalThreadsField() |
---|
482 | { |
---|
483 | if (evalThreadsField == null) |
---|
484 | { |
---|
485 | evalThreadsField = new JTextField(); |
---|
486 | evalThreadsField.addKeyListener(new java.awt.event.KeyAdapter() |
---|
487 | { |
---|
488 | public void keyPressed(java.awt.event.KeyEvent e) |
---|
489 | { |
---|
490 | if (e.getKeyCode() == KeyEvent.VK_ENTER) |
---|
491 | { |
---|
492 | console.parameters.set(new Parameter(Evolve.P_EVALTHREADS), ((JTextField)e.getSource()).getText()); |
---|
493 | resizeSeedTable(); |
---|
494 | } |
---|
495 | else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) |
---|
496 | { |
---|
497 | ((JTextField)e.getSource()).setText(console.parameters.getString(new Parameter(Evolve.P_EVALTHREADS),null)); |
---|
498 | } |
---|
499 | } |
---|
500 | }); |
---|
501 | } |
---|
502 | return evalThreadsField; |
---|
503 | } |
---|
504 | /** |
---|
505 | * This method initializes jTextField3 |
---|
506 | * |
---|
507 | * @return javax.swing.JTextField |
---|
508 | */ |
---|
509 | JTextField getBreedThreadsField() |
---|
510 | { |
---|
511 | if (breedThreadsField == null) |
---|
512 | { |
---|
513 | breedThreadsField = new JTextField(); |
---|
514 | breedThreadsField.addKeyListener(new java.awt.event.KeyAdapter() |
---|
515 | { |
---|
516 | public void keyPressed(java.awt.event.KeyEvent e) |
---|
517 | { |
---|
518 | if (e.getKeyCode() == KeyEvent.VK_ENTER) |
---|
519 | { |
---|
520 | console.parameters.set(new Parameter(Evolve.P_BREEDTHREADS), ((JTextField)e.getSource()).getText()); |
---|
521 | resizeSeedTable(); |
---|
522 | } |
---|
523 | else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) |
---|
524 | { |
---|
525 | ((JTextField)e.getSource()).setText(console.parameters.getString(new Parameter(Evolve.P_BREEDTHREADS),null)); |
---|
526 | } |
---|
527 | } |
---|
528 | }); |
---|
529 | } |
---|
530 | return breedThreadsField; |
---|
531 | } |
---|
532 | /** |
---|
533 | * This method initializes jPanel |
---|
534 | * |
---|
535 | * @return javax.swing.JPanel |
---|
536 | */ |
---|
537 | JPanel getJPanel() |
---|
538 | { |
---|
539 | if (jPanel == null) |
---|
540 | { |
---|
541 | GridBagConstraints gridBagConstraints15 = new GridBagConstraints(); |
---|
542 | GridBagConstraints gridBagConstraints81 = new GridBagConstraints(); |
---|
543 | GridBagConstraints gridBagConstraints14 = new GridBagConstraints(); |
---|
544 | GridBagConstraints gridBagConstraints13 = new GridBagConstraints(); |
---|
545 | GridBagConstraints gridBagConstraints12 = new GridBagConstraints(); |
---|
546 | GridBagConstraints gridBagConstraints19 = new GridBagConstraints(); |
---|
547 | GridBagConstraints gridBagConstraints21 = new GridBagConstraints(); |
---|
548 | TitledBorder titledBorder28 = javax.swing.BorderFactory.createTitledBorder(null, "Random Seed(s)", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null); |
---|
549 | jPanel = new JPanel(); |
---|
550 | jPanel.setLayout(new GridBagLayout()); |
---|
551 | gridBagConstraints12.gridx = 0; |
---|
552 | gridBagConstraints12.gridy = 1; |
---|
553 | gridBagConstraints12.fill = java.awt.GridBagConstraints.HORIZONTAL; |
---|
554 | gridBagConstraints12.anchor = java.awt.GridBagConstraints.EAST; |
---|
555 | gridBagConstraints12.gridwidth = 5; |
---|
556 | gridBagConstraints12.insets = new java.awt.Insets(0,20,0,0); |
---|
557 | gridBagConstraints12.weightx = 1.0D; |
---|
558 | gridBagConstraints13.gridx = 5; |
---|
559 | gridBagConstraints13.gridy = 1; |
---|
560 | gridBagConstraints13.anchor = java.awt.GridBagConstraints.WEST; |
---|
561 | gridBagConstraints13.insets = new java.awt.Insets(0,5,0,0); |
---|
562 | gridBagConstraints14.gridx = 0; |
---|
563 | gridBagConstraints14.gridy = 3; |
---|
564 | gridBagConstraints14.gridwidth = 1; |
---|
565 | gridBagConstraints14.anchor = java.awt.GridBagConstraints.WEST; |
---|
566 | gridBagConstraints19.gridwidth = 6; |
---|
567 | gridBagConstraints19.anchor = java.awt.GridBagConstraints.WEST; |
---|
568 | gridBagConstraints21.gridx = 0; |
---|
569 | gridBagConstraints21.gridy = 7; |
---|
570 | gridBagConstraints21.fill = java.awt.GridBagConstraints.BOTH; |
---|
571 | gridBagConstraints21.gridwidth = 6; |
---|
572 | gridBagConstraints21.gridheight = 1; |
---|
573 | gridBagConstraints21.weighty = 1.0D; |
---|
574 | gridBagConstraints21.weightx = 1.0D; |
---|
575 | jPanel.setBorder(titledBorder28); |
---|
576 | titledBorder28.setBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.LOWERED)); |
---|
577 | gridBagConstraints81.gridx = 1; |
---|
578 | gridBagConstraints81.gridy = 3; |
---|
579 | gridBagConstraints15.gridx = 0; |
---|
580 | gridBagConstraints15.gridy = 2; |
---|
581 | gridBagConstraints15.anchor = java.awt.GridBagConstraints.WEST; |
---|
582 | jPanel.add(getSeedFileRadioButton(), gridBagConstraints19); |
---|
583 | jPanel.add(getSeedFileField(), gridBagConstraints12); |
---|
584 | jPanel.add(getSeedFileButton(), gridBagConstraints13); |
---|
585 | jPanel.add(getRandomSeedsRadioButton(), gridBagConstraints14); |
---|
586 | jPanel.add(getJScrollPane(), gridBagConstraints21); |
---|
587 | seedButtonGroup = new ButtonGroup(); |
---|
588 | seedButtonGroup.add(getRandomSeedsRadioButton()); |
---|
589 | seedButtonGroup.add(getSeedFileRadioButton()); |
---|
590 | seedButtonGroup.add(getSequentialSeedsRadioButton()); |
---|
591 | jPanel.add(getGenerateSeedsButton(), gridBagConstraints81); |
---|
592 | jPanel.add(getSequentialSeedsRadioButton(), gridBagConstraints15); |
---|
593 | } |
---|
594 | return jPanel; |
---|
595 | } |
---|
596 | /** |
---|
597 | * This method initializes jRadioButton |
---|
598 | * |
---|
599 | * @return javax.swing.JRadioButton |
---|
600 | */ |
---|
601 | JRadioButton getSeedFileRadioButton() |
---|
602 | { |
---|
603 | if (seedFileRadioButton == null) |
---|
604 | { |
---|
605 | seedFileRadioButton = new JRadioButton(); |
---|
606 | seedFileRadioButton.setText("Seeds from file:"); |
---|
607 | final ControlPanel cp = this; |
---|
608 | seedFileRadioButton.addItemListener(new java.awt.event.ItemListener() |
---|
609 | { |
---|
610 | public void itemStateChanged(java.awt.event.ItemEvent e) |
---|
611 | { |
---|
612 | if (e.getStateChange() == ItemEvent.SELECTED) |
---|
613 | { |
---|
614 | seedFileField.setEnabled(true); |
---|
615 | seedFileButton.setEnabled(true); |
---|
616 | |
---|
617 | String seedFileName = seedFileField.getText(); |
---|
618 | File seedFile = null; |
---|
619 | if ( seedFileName == null || |
---|
620 | seedFileName.length() == 0) |
---|
621 | { |
---|
622 | FileDialog fileDialog = new FileDialog(ControlPanel.this.console,"Load...",FileDialog.LOAD); |
---|
623 | fileDialog.setDirectory(System.getProperty("user.dir")); |
---|
624 | fileDialog.setFile("*.seed"); |
---|
625 | fileDialog.setVisible(true); |
---|
626 | String fileName = fileDialog.getFile(); |
---|
627 | if ( fileName != null ) |
---|
628 | |
---|
629 | { |
---|
630 | seedFile = new File(fileDialog.getDirectory(),fileName); |
---|
631 | } |
---|
632 | } |
---|
633 | else |
---|
634 | { |
---|
635 | seedFile = new File(seedFileName); |
---|
636 | } |
---|
637 | |
---|
638 | if (seedFile != null) |
---|
639 | { |
---|
640 | try |
---|
641 | { |
---|
642 | cp.loadSeeds(seedFile); |
---|
643 | } |
---|
644 | catch (IOException ex) |
---|
645 | { |
---|
646 | System.err.println(ex.getMessage()); |
---|
647 | } |
---|
648 | } |
---|
649 | } |
---|
650 | else |
---|
651 | { |
---|
652 | seedFileField.setEnabled(false); |
---|
653 | seedFileButton.setEnabled(false); |
---|
654 | } |
---|
655 | } |
---|
656 | }); |
---|
657 | } |
---|
658 | return seedFileRadioButton; |
---|
659 | } |
---|
660 | /** |
---|
661 | * This method initializes jTextField4 |
---|
662 | * |
---|
663 | * @return javax.swing.JTextField |
---|
664 | */ |
---|
665 | JTextField getSeedFileField() |
---|
666 | { |
---|
667 | if (seedFileField == null) |
---|
668 | { |
---|
669 | seedFileField = new JTextField(); |
---|
670 | seedFileField.setEnabled(false); |
---|
671 | seedFileField.setEditable(false); |
---|
672 | } |
---|
673 | return seedFileField; |
---|
674 | } |
---|
675 | /** |
---|
676 | * This method initializes jButton |
---|
677 | * |
---|
678 | * @return javax.swing.JButton |
---|
679 | */ |
---|
680 | JButton getSeedFileButton() |
---|
681 | { |
---|
682 | if (seedFileButton == null) |
---|
683 | { |
---|
684 | seedFileButton = new JButton(); |
---|
685 | seedFileButton.setText("..."); |
---|
686 | seedFileButton.setEnabled(false); |
---|
687 | final ControlPanel cp = this; |
---|
688 | seedFileButton.addActionListener(new java.awt.event.ActionListener() |
---|
689 | { |
---|
690 | public void actionPerformed(java.awt.event.ActionEvent e) |
---|
691 | { |
---|
692 | File seedFile = null; |
---|
693 | FileDialog fileDialog = new FileDialog(ControlPanel.this.console,"Load...",FileDialog.LOAD); |
---|
694 | fileDialog.setDirectory(System.getProperty("user.dir")); |
---|
695 | fileDialog.setFile("*.seed"); |
---|
696 | fileDialog.setVisible(true); |
---|
697 | String fileName = fileDialog.getFile(); |
---|
698 | if ( fileName != null ) |
---|
699 | |
---|
700 | { |
---|
701 | seedFile = new File(fileDialog.getDirectory(),fileName); |
---|
702 | } |
---|
703 | |
---|
704 | if (seedFile != null) |
---|
705 | { |
---|
706 | try |
---|
707 | { |
---|
708 | cp.loadSeeds(seedFile); |
---|
709 | } |
---|
710 | catch (IOException ex) |
---|
711 | { |
---|
712 | System.err.println(ex.getMessage()); |
---|
713 | } |
---|
714 | } |
---|
715 | } |
---|
716 | }); |
---|
717 | } |
---|
718 | return seedFileButton; |
---|
719 | } |
---|
720 | /** |
---|
721 | * This method initializes jRadioButton1 |
---|
722 | * |
---|
723 | * @return javax.swing.JRadioButton |
---|
724 | */ |
---|
725 | JRadioButton getRandomSeedsRadioButton() |
---|
726 | { |
---|
727 | if (randomSeedsRadioButton == null) |
---|
728 | { |
---|
729 | randomSeedsRadioButton = new JRadioButton(); |
---|
730 | randomSeedsRadioButton.setText("Random Seeds"); |
---|
731 | randomSeedsRadioButton.addItemListener(new java.awt.event.ItemListener() |
---|
732 | { |
---|
733 | public void itemStateChanged(java.awt.event.ItemEvent e) |
---|
734 | { |
---|
735 | if (e.getStateChange() == ItemEvent.SELECTED) |
---|
736 | { |
---|
737 | generateSeedsButton.setEnabled(true); |
---|
738 | } |
---|
739 | else |
---|
740 | { |
---|
741 | generateSeedsButton.setEnabled(false); |
---|
742 | } |
---|
743 | } |
---|
744 | }); |
---|
745 | } |
---|
746 | return randomSeedsRadioButton; |
---|
747 | } |
---|
748 | /** |
---|
749 | * This method initializes jTable |
---|
750 | * |
---|
751 | * @return javax.swing.JTable |
---|
752 | */ |
---|
753 | JTable getSeedsTable() |
---|
754 | { |
---|
755 | if (seedsTable == null) |
---|
756 | { |
---|
757 | seedsTable = new JTable(); |
---|
758 | seedsTable.setAutoResizeMode(javax.swing.JTable.AUTO_RESIZE_OFF); |
---|
759 | } |
---|
760 | return seedsTable; |
---|
761 | } |
---|
762 | /** |
---|
763 | * This method initializes jScrollPane |
---|
764 | * |
---|
765 | * @return javax.swing.JScrollPane |
---|
766 | */ |
---|
767 | JScrollPane getJScrollPane() |
---|
768 | { |
---|
769 | if (jScrollPane == null) |
---|
770 | { |
---|
771 | jScrollPane = new JScrollPane(); |
---|
772 | jScrollPane.setViewportView(getSeedsTable()); |
---|
773 | jScrollPane.setHorizontalScrollBarPolicy(javax.swing.JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS); |
---|
774 | } |
---|
775 | return jScrollPane; |
---|
776 | } |
---|
777 | |
---|
778 | /** |
---|
779 | * @param panel TODO |
---|
780 | * @param enabled TODO |
---|
781 | * |
---|
782 | */ |
---|
783 | void setEnabled(JPanel panel, boolean enabled) |
---|
784 | { |
---|
785 | Component[] components = panel.getComponents(); |
---|
786 | for (int i = 0; i < components.length; ++i) |
---|
787 | { |
---|
788 | components[i].setEnabled(enabled); |
---|
789 | } |
---|
790 | } |
---|
791 | /** |
---|
792 | * This method initializes jCheckBox10 |
---|
793 | * |
---|
794 | * @return javax.swing.JCheckBox |
---|
795 | */ |
---|
796 | JCheckBox getCheckpointCheckBox() |
---|
797 | { |
---|
798 | if (checkpointCheckBox == null) |
---|
799 | { |
---|
800 | checkpointCheckBox = new JCheckBox(); |
---|
801 | checkpointCheckBox.setText("Checkpoint"); |
---|
802 | checkpointCheckBox.addItemListener(new java.awt.event.ItemListener() |
---|
803 | { |
---|
804 | public void itemStateChanged(java.awt.event.ItemEvent e) |
---|
805 | { |
---|
806 | if (e.getStateChange() == ItemEvent.SELECTED) |
---|
807 | { |
---|
808 | setEnabled(checkpointPanel, true); |
---|
809 | } |
---|
810 | else |
---|
811 | { |
---|
812 | setEnabled(checkpointPanel, false); |
---|
813 | } |
---|
814 | |
---|
815 | console.parameters.set(new Parameter(EvolutionState.P_CHECKPOINT),"" + ((JCheckBox)e.getSource()).isSelected()); |
---|
816 | } |
---|
817 | }); |
---|
818 | } |
---|
819 | return checkpointCheckBox; |
---|
820 | } |
---|
821 | /** |
---|
822 | * This method initializes jPanel2 |
---|
823 | * |
---|
824 | * @return javax.swing.JPanel |
---|
825 | */ |
---|
826 | JPanel getCheckpointPanel() |
---|
827 | { |
---|
828 | if (checkpointPanel == null) |
---|
829 | { |
---|
830 | GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
---|
831 | jLabel8 = new JLabel(); |
---|
832 | jLabel7 = new JLabel(); |
---|
833 | GridBagConstraints gridBagConstraints39 = new GridBagConstraints(); |
---|
834 | GridBagConstraints gridBagConstraints40 = new GridBagConstraints(); |
---|
835 | GridBagConstraints gridBagConstraints41 = new GridBagConstraints(); |
---|
836 | checkpointPanel = new JPanel(); |
---|
837 | checkpointPanel.setLayout(new GridBagLayout()); |
---|
838 | jLabel7.setText("Frequency:"); |
---|
839 | jLabel7.setEnabled(false); |
---|
840 | gridBagConstraints39.fill = java.awt.GridBagConstraints.HORIZONTAL; |
---|
841 | gridBagConstraints39.gridx = 1; |
---|
842 | gridBagConstraints39.gridy = 0; |
---|
843 | gridBagConstraints39.ipady = 0; |
---|
844 | gridBagConstraints39.ipadx = 0; |
---|
845 | gridBagConstraints39.weightx = 0.0D; |
---|
846 | gridBagConstraints39.insets = new java.awt.Insets(0,5,0,0); |
---|
847 | checkpointPanel.setBorder(javax.swing.BorderFactory.createTitledBorder(javax.swing.BorderFactory.createEtchedBorder(javax.swing.border.EtchedBorder.LOWERED), "Checkpointing", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
---|
848 | jLabel8.setText("File Prefix:"); |
---|
849 | jLabel8.setEnabled(false); |
---|
850 | gridBagConstraints40.gridx = 0; |
---|
851 | gridBagConstraints40.gridy = 1; |
---|
852 | gridBagConstraints40.anchor = java.awt.GridBagConstraints.WEST; |
---|
853 | gridBagConstraints41.gridx = 1; |
---|
854 | gridBagConstraints41.gridy = 1; |
---|
855 | gridBagConstraints41.fill = java.awt.GridBagConstraints.HORIZONTAL; |
---|
856 | gridBagConstraints41.insets = new java.awt.Insets(0,5,0,0); |
---|
857 | gridBagConstraints41.gridwidth = 2; |
---|
858 | gridBagConstraints41.weightx = 0.5D; |
---|
859 | gridBagConstraints3.anchor = java.awt.GridBagConstraints.WEST; |
---|
860 | checkpointPanel.add(jLabel7, gridBagConstraints3); |
---|
861 | checkpointPanel.add(getCheckpointModuloField(), gridBagConstraints39); |
---|
862 | checkpointPanel.add(jLabel8, gridBagConstraints40); |
---|
863 | checkpointPanel.add(getPrefixField(), gridBagConstraints41); |
---|
864 | } |
---|
865 | return checkpointPanel; |
---|
866 | } |
---|
867 | /** |
---|
868 | * This method initializes jTextField8 |
---|
869 | * |
---|
870 | * @return javax.swing.JTextField |
---|
871 | */ |
---|
872 | JTextField getCheckpointModuloField() |
---|
873 | { |
---|
874 | if (checkpointModuloField == null) |
---|
875 | { |
---|
876 | checkpointModuloField = new JTextField(); |
---|
877 | checkpointModuloField.setPreferredSize(new java.awt.Dimension(35,20)); |
---|
878 | checkpointModuloField.setEnabled(false); |
---|
879 | checkpointModuloField.addKeyListener(new java.awt.event.KeyAdapter() |
---|
880 | { |
---|
881 | public void keyPressed(java.awt.event.KeyEvent e) |
---|
882 | { |
---|
883 | if (e.getKeyCode() == KeyEvent.VK_ENTER) |
---|
884 | { |
---|
885 | console.parameters.set(new Parameter(EvolutionState.P_CHECKPOINTMODULO), ((JTextField)e.getSource()).getText()); |
---|
886 | } |
---|
887 | else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) |
---|
888 | { |
---|
889 | ((JTextField)e.getSource()).setText(console.parameters.getString(new Parameter(EvolutionState.P_CHECKPOINTMODULO),null)); |
---|
890 | } |
---|
891 | } |
---|
892 | }); |
---|
893 | } |
---|
894 | return checkpointModuloField; |
---|
895 | } |
---|
896 | /** |
---|
897 | * This method initializes jTextField9 |
---|
898 | * |
---|
899 | * @return javax.swing.JTextField |
---|
900 | */ |
---|
901 | JTextField getPrefixField() |
---|
902 | { |
---|
903 | if (prefixField == null) |
---|
904 | { |
---|
905 | prefixField = new JTextField(); |
---|
906 | prefixField.setEnabled(false); |
---|
907 | prefixField.addKeyListener(new java.awt.event.KeyAdapter() |
---|
908 | { |
---|
909 | public void keyPressed(java.awt.event.KeyEvent e) |
---|
910 | { |
---|
911 | if (e.getKeyCode() == KeyEvent.VK_ENTER) |
---|
912 | { |
---|
913 | console.parameters.set(new Parameter(EvolutionState.P_CHECKPOINTPREFIX), ((JTextField)e.getSource()).getText()); |
---|
914 | } |
---|
915 | else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) |
---|
916 | { |
---|
917 | ((JTextField)e.getSource()).setText(console.parameters.getString(new Parameter(EvolutionState.P_CHECKPOINTPREFIX),null)); |
---|
918 | } |
---|
919 | } |
---|
920 | }); |
---|
921 | } |
---|
922 | return prefixField; |
---|
923 | } |
---|
924 | public void loadParameters() |
---|
925 | { |
---|
926 | numGensField.setText(console.parameters.getStringWithDefault( |
---|
927 | new Parameter(EvolutionState.P_GENERATIONS),null,"1")); |
---|
928 | quitOnRunCompleteCheckbox.setSelected(console.parameters.getBoolean(new Parameter(EvolutionState.P_QUITONRUNCOMPLETE),null,true)); |
---|
929 | evalThreadsField.setText(console.parameters.getStringWithDefault(new Parameter(Evolve.P_EVALTHREADS),null,"1")); |
---|
930 | breedThreadsField.setText(console.parameters.getStringWithDefault(new Parameter(Evolve.P_BREEDTHREADS),null,"1")); |
---|
931 | checkpointCheckBox.setSelected(console.parameters.getBoolean(new Parameter(EvolutionState.P_CHECKPOINT),null,false)); |
---|
932 | checkpointModuloField.setText(console.parameters.getStringWithDefault(new Parameter(EvolutionState.P_CHECKPOINTMODULO),null,"10")); |
---|
933 | prefixField.setText(console.parameters.getStringWithDefault(new Parameter(EvolutionState.P_CHECKPOINTPREFIX),null,"gc")); |
---|
934 | numJobsField.setText("1"); |
---|
935 | jobFilePrefixField.setText(console.parameters.getStringWithDefault(new Parameter(P_JOBFILEPREFIX),null,"")); |
---|
936 | |
---|
937 | resizeSeedTable(); |
---|
938 | } |
---|
939 | |
---|
940 | void loadSeeds(File f) |
---|
941 | throws IOException |
---|
942 | { |
---|
943 | LineNumberReader in = new LineNumberReader(new InputStreamReader(new FileInputStream(f))); |
---|
944 | |
---|
945 | seedFileField.setText(f.getAbsolutePath()); |
---|
946 | // whether a seed is used for a particular thread or job depends |
---|
947 | // upon how many of each there are. Just read seeds, one per line, until |
---|
948 | // numJobs * numThreads seeds are read. If there are not enough seeds, |
---|
949 | // print a warning and generate the remaining necessary. |
---|
950 | int numJobs = Integer.valueOf(numJobsField.getText()).intValue(); |
---|
951 | int evalThreads = getThreadCount(console.parameters.getString(new Parameter(Evolve.P_EVALTHREADS),null)); |
---|
952 | int breedThreads = getThreadCount(console.parameters.getString(new Parameter(Evolve.P_BREEDTHREADS),null)); |
---|
953 | int numThreads = Math.max(evalThreads, breedThreads); |
---|
954 | |
---|
955 | // Read seeds for threads first |
---|
956 | // TODO Make this more robust (i.e. ensure we're reading integers). |
---|
957 | int job = 0; |
---|
958 | int thread = 0; |
---|
959 | String lastSeed = null; |
---|
960 | for (; job < numJobs; ++job) |
---|
961 | { |
---|
962 | String seed = null; |
---|
963 | for (; thread < numThreads; ++thread) |
---|
964 | { |
---|
965 | seed = in.readLine(); |
---|
966 | if (seed != null) |
---|
967 | { |
---|
968 | setSeed(seed, job, thread); |
---|
969 | lastSeed = seed; |
---|
970 | } |
---|
971 | else break; |
---|
972 | } |
---|
973 | if (seed == null) |
---|
974 | break; |
---|
975 | thread = 0; |
---|
976 | } |
---|
977 | |
---|
978 | // Finish filling out the table with sequential numbers starting from |
---|
979 | // the last good seed. |
---|
980 | // TODO Determine if this is reasonable. Should we instead generate |
---|
981 | // random seeds? Alternatively, should we indicate this as an error |
---|
982 | // to the user and abort? |
---|
983 | if ((job)*(thread) != (numJobs)*(numThreads)) |
---|
984 | { |
---|
985 | int seedNum = Integer.valueOf(lastSeed).intValue(); |
---|
986 | for (;job < numJobs; ++job) |
---|
987 | { |
---|
988 | for (;thread < numThreads; ++thread) |
---|
989 | { |
---|
990 | String seed = ""+(++seedNum); |
---|
991 | setSeed(seed,job,thread); |
---|
992 | } |
---|
993 | thread = 0; |
---|
994 | } |
---|
995 | } |
---|
996 | } |
---|
997 | /** |
---|
998 | * This method initializes jButton |
---|
999 | * |
---|
1000 | * @return javax.swing.JButton |
---|
1001 | */ |
---|
1002 | JButton getGenerateSeedsButton() |
---|
1003 | { |
---|
1004 | if (generateSeedsButton == null) |
---|
1005 | { |
---|
1006 | generateSeedsButton = new JButton(); |
---|
1007 | generateSeedsButton.setText("Generate"); |
---|
1008 | generateSeedsButton.setEnabled(false); |
---|
1009 | generateSeedsButton.addActionListener(new java.awt.event.ActionListener() |
---|
1010 | { |
---|
1011 | public void actionPerformed(java.awt.event.ActionEvent e) |
---|
1012 | { |
---|
1013 | generateRandomSeeds(); |
---|
1014 | } |
---|
1015 | }); |
---|
1016 | } |
---|
1017 | return generateSeedsButton; |
---|
1018 | } |
---|
1019 | /** |
---|
1020 | * This method initializes jRadioButton |
---|
1021 | * |
---|
1022 | * @return javax.swing.JRadioButton |
---|
1023 | */ |
---|
1024 | JRadioButton getSequentialSeedsRadioButton() |
---|
1025 | { |
---|
1026 | if (sequentialSeedsRadioButton == null) |
---|
1027 | { |
---|
1028 | sequentialSeedsRadioButton = new JRadioButton(); |
---|
1029 | sequentialSeedsRadioButton.setText("Sequential"); |
---|
1030 | sequentialSeedsRadioButton.addItemListener(new java.awt.event.ItemListener() |
---|
1031 | { |
---|
1032 | public void itemStateChanged(java.awt.event.ItemEvent e) |
---|
1033 | { |
---|
1034 | if (e.getStateChange() == ItemEvent.SELECTED) |
---|
1035 | { |
---|
1036 | resizeSeedTable(); |
---|
1037 | } |
---|
1038 | } |
---|
1039 | }); |
---|
1040 | } |
---|
1041 | return sequentialSeedsRadioButton; |
---|
1042 | } |
---|
1043 | /** |
---|
1044 | * This method initializes jTextField |
---|
1045 | * |
---|
1046 | * @return javax.swing.JTextField |
---|
1047 | */ |
---|
1048 | JTextField getJobFilePrefixField() |
---|
1049 | { |
---|
1050 | if (jobFilePrefixField == null) |
---|
1051 | { |
---|
1052 | jobFilePrefixField = new JTextField(); |
---|
1053 | jobFilePrefixField.addKeyListener(new java.awt.event.KeyAdapter() |
---|
1054 | { |
---|
1055 | public void keyPressed(java.awt.event.KeyEvent e) |
---|
1056 | { |
---|
1057 | if (e.getKeyCode() == KeyEvent.VK_ENTER) |
---|
1058 | { |
---|
1059 | console.parameters.set(new Parameter(P_JOBFILEPREFIX), ((JTextField)e.getSource()).getText()); |
---|
1060 | } |
---|
1061 | else if (e.getKeyCode() == KeyEvent.VK_ESCAPE) |
---|
1062 | { |
---|
1063 | ((JTextField)e.getSource()).setText(console.parameters.getStringWithDefault(new Parameter(P_JOBFILEPREFIX),null,"")); |
---|
1064 | } |
---|
1065 | } |
---|
1066 | }); |
---|
1067 | } |
---|
1068 | return jobFilePrefixField; |
---|
1069 | } |
---|
1070 | |
---|
1071 | public String getJobFilePrefix() |
---|
1072 | { |
---|
1073 | return jobFilePrefixField.getText(); |
---|
1074 | } |
---|
1075 | } // @jve:decl-index=0:visual-constraint="66,13" |
---|