Example #1
0
    private JComponent createInputPanel() {
      JPanel inputPanel = new JPanel(new SpringLayout());
      JLabel populationLabel = new JLabel("Population Size: ");
      populationSpinner = new JSpinner(new SpinnerNumberModel(18, 2, 25, 1));
      populationSpinner.setEnabled(false);
      populationLabel.setLabelFor(populationSpinner);
      inputPanel.add(populationLabel);
      inputPanel.add(populationSpinner);
      JLabel generationsLabel = new JLabel("Number of Generations: ");
      generationsSpinner = new JSpinner(new SpinnerNumberModel(20, 1, 100, 1));
      generationsLabel.setLabelFor(generationsSpinner);
      inputPanel.add(generationsLabel);
      inputPanel.add(generationsSpinner);
      JLabel mutationLabel = new JLabel("Mutation Type: ");
      mutationCombo = new JComboBox(new String[] {"Dawkins (Non-random)", "Random"});
      mutationCombo.addItemListener(
          new ItemListener() {
            public void itemStateChanged(ItemEvent itemEvent) {
              if (mutationCombo.getSelectedIndex() == 0) {
                populationSpinner.setValue(18);
                populationSpinner.setEnabled(false);
              } else {
                populationSpinner.setEnabled(true);
              }
            }
          });
      inputPanel.add(mutationLabel);
      inputPanel.add(mutationCombo);

      SpringUtilities.makeCompactGrid(inputPanel, 3, 2, 30, 6, 6, 6);

      return inputPanel;
    }
Example #2
0
    EvolutionPanel() {
      super(new FlowLayout(FlowLayout.LEFT, 0, 0));
      Container innerPanel = new JPanel(new SpringLayout());

      populationLabel = new JLabel("Population Size: ");
      populationSpinner = new JSpinner(new SpinnerNumberModel(300, 2, 10000, 1));
      populationLabel.setLabelFor(populationSpinner);
      innerPanel.add(populationLabel);
      innerPanel.add(populationSpinner);

      elitismLabel = new JLabel("Elitism: ");
      elitismSpinner = new JSpinner(new SpinnerNumberModel(3, 0, 10000, 1));
      elitismLabel.setLabelFor(elitismSpinner);
      innerPanel.add(elitismLabel);
      innerPanel.add(elitismSpinner);

      generationsLabel = new JLabel("Number of Generations: ");
      generationsSpinner = new JSpinner(new SpinnerNumberModel(100, 1, 10000, 1));
      generationsLabel.setLabelFor(generationsSpinner);
      innerPanel.add(generationsLabel);
      innerPanel.add(generationsSpinner);

      selectionLabel = new JLabel("Selection Strategy: ");
      innerPanel.add(selectionLabel);

      SelectionStrategy<?>[] selectionStrategies = {
        new RankSelection(),
        new RouletteWheelSelection(),
        new StochasticUniversalSampling(),
        new TournamentSelection(new Probability(0.95)),
        new TruncationSelection(0.5)
      };

      selectionCombo = new JComboBox(selectionStrategies);
      selectionCombo.setRenderer(
          new DefaultListCellRenderer() {
            @Override
            public Component getListCellRendererComponent(
                JList list, Object value, int index, boolean isSelected, boolean hasFocus) {
              SelectionStrategy<?> strategy = (SelectionStrategy<?>) value;
              String text = strategy.getClass().getSimpleName();
              return super.getListCellRendererComponent(list, text, index, isSelected, hasFocus);
            }
          });
      selectionCombo.setSelectedIndex(selectionCombo.getItemCount() - 1);
      innerPanel.add(selectionCombo);

      crossoverCheckbox = new JCheckBox("Cross-over", true);
      mutationCheckbox = new JCheckBox("Mutation", true);
      distributedCheckbox = new JCheckBox("Distributed (Mahout)", false);

      innerPanel.add(crossoverCheckbox);
      innerPanel.add(mutationCheckbox);
      innerPanel.add(distributedCheckbox);
      innerPanel.add(new JLabel()); // pour avoir un nombre paire de components

      SpringUtilities.makeCompactGrid(innerPanel, 6, 2, 30, 6, 6, 6);
      add(innerPanel);
    }