/*
*Copyright 2007, 2011 CCLS Columbia University (USA), LIFO University of Orl��ans (France), BRGM (France)
*
*Authors: Cyril Nortet, Xiangrong Kong, Ansaf Salleb-Aouissi, Christel Vrain, Daniel Cassard
*
*This file is part of QuantMiner.
*
*QuantMiner is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or any later version.
*
*QuantMiner is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
*
*You should have received a copy of the GNU General Public License along with QuantMiner. If not, see <http://www.gnu.org/licenses/>.
*/
package src.graphicalInterface;
import javax.swing.*;
import src.geneticAlgorithm.*;
import src.solver.*;
import src.tools.*;
public class PanelGeneticParam extends PanelBaseParam {//step 3 technique parameters
/** Creates new form PanneauParamGenetique */
public PanelGeneticParam(ResolutionContext contexteResolution) {
super(contexteResolution);
ImageIcon iconeRetourDefaut = null;
initComponents();
// Ic�nes sur les boutons :
iconeRetourDefaut = new ImageIcon( ENV.REPERTOIRE_RESSOURCES + "retour_defaut.jpg" );
jButtonDefautPopulation.setIcon(iconeRetourDefaut);
jButtonDefautGenerations.setIcon(iconeRetourDefaut);
jButtonDefautCroisement.setIcon(iconeRetourDefaut);
jButtonDefautMutation.setIcon(iconeRetourDefaut);
if (m_contexteResolution == null)
return;
ParametersGeneticAlgo parametresTechAlgoGenetique = m_contexteResolution.m_parametresTechAlgoGenetique;
// Initialisation du contenu des champs :
jTextTaillePopulation.setText( String.valueOf( parametresTechAlgoGenetique.m_iTaillePopulation ) );
jTextNombreGens.setText( String.valueOf( parametresTechAlgoGenetique.m_iNombreGenerations ) );
jTextTauxCroisement.setText( ResolutionContext.EcrirePourcentage( parametresTechAlgoGenetique.m_fPourcentageCroisement, 3, false) );
jTextTauxMutation.setText( ResolutionContext.EcrirePourcentage( parametresTechAlgoGenetique.m_fPourcentageMutation, 3, false) );
}
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {//GEN-BEGIN:initComponents
jTextTaillePopulation = new javax.swing.JTextField();
jLabelTaillePopulation = new javax.swing.JLabel();
jLabelTauxCroisement = new javax.swing.JLabel();
jLabelTauxMutation = new javax.swing.JLabel();
jTextTauxCroisement = new javax.swing.JTextField();
jTextTauxMutation = new javax.swing.JTextField();
jLabelNombreGens = new javax.swing.JLabel();
jTextNombreGens = new javax.swing.JTextField();
jButtonDefautPopulation = new javax.swing.JButton();
jButtonDefautGenerations = new javax.swing.JButton();
jButtonDefautCroisement = new javax.swing.JButton();
jButtonDefautMutation = new javax.swing.JButton();
setLayout(null);
setPreferredSize(new java.awt.Dimension(410, 150));
jTextTaillePopulation.setText("jTextField1");
add(jTextTaillePopulation);
jTextTaillePopulation.setBounds(330, 20, 60, 20);
jLabelTaillePopulation.setText("Population size :");
add(jLabelTaillePopulation);
jLabelTaillePopulation.setBounds(20, 20, 140, 16);
jLabelTauxCroisement.setText("Cross-over rate (%) :");
add(jLabelTauxCroisement);
jLabelTauxCroisement.setBounds(20, 80, 140, 16);
jLabelTauxMutation.setText("Mutation rate (%) :");
add(jLabelTauxMutation);
jLabelTauxMutation.setBounds(20, 110, 130, 16);
jTextTauxCroisement.setText("jTextField2");
jTextTauxCroisement.setInputVerifier(new ToolsInterface.VerifieurTextFieldIntervalleFloat(0.0f, 100.0f));
add(jTextTauxCroisement);
jTextTauxCroisement.setBounds(330, 80, 60, 20);
jTextTauxMutation.setText("jTextField1");
jTextTauxMutation.setInputVerifier(new ToolsInterface.VerifieurTextFieldIntervalleFloat(0.0f, 100.0f));
add(jTextTauxMutation);
jTextTauxMutation.setBounds(330, 110, 60, 20);
jLabelNombreGens.setText("Number of generations :");
add(jLabelNombreGens);
jLabelNombreGens.setBounds(20, 50, 250, 16);
jTextNombreGens.setText("jTextField1");
add(jTextNombreGens);
jTextNombreGens.setBounds(330, 50, 60, 20);
jButtonDefautPopulation.setBackground(new java.awt.Color(255, 255, 255));
jButtonDefautPopulation.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonDefautPopulationActionPerformed(evt);
}
});
add(jButtonDefautPopulation);
jButtonDefautPopulation.setBounds(400, 20, 20, 20);
jButtonDefautGenerations.setBackground(new java.awt.Color(255, 255, 255));
jButtonDefautGenerations.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonDefautGenerationsActionPerformed(evt);
}
});
add(jButtonDefautGenerations);
jButtonDefautGenerations.setBounds(400, 50, 20, 20);
jButtonDefautCroisement.setBackground(new java.awt.Color(255, 255, 255));
jButtonDefautCroisement.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonDefautCroisementActionPerformed(evt);
}
});
add(jButtonDefautCroisement);
jButtonDefautCroisement.setBounds(400, 80, 20, 20);
jButtonDefautMutation.setBackground(new java.awt.Color(255, 255, 255));
jButtonDefautMutation.addActionListener(new java.awt.event.ActionListener() {
public void actionPerformed(java.awt.event.ActionEvent evt) {
jButtonDefautMutationActionPerformed(evt);
}
});
add(jButtonDefautMutation);
jButtonDefautMutation.setBounds(400, 110, 20, 20);
}//GEN-END:initComponents
private void jButtonDefautMutationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDefautMutationActionPerformed
jTextTauxMutation.setText( ResolutionContext.EcrirePourcentage(ParametersGeneticAlgo.DEFAUT_COEFMUT, 3, false) );
}//GEN-LAST:event_jButtonDefautMutationActionPerformed
private void jButtonDefautCroisementActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDefautCroisementActionPerformed
jTextTauxCroisement.setText( ResolutionContext.EcrirePourcentage(ParametersGeneticAlgo.DEFAUT_COEFFCROIS, 3, false) );
}//GEN-LAST:event_jButtonDefautCroisementActionPerformed
private void jButtonDefautGenerationsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDefautGenerationsActionPerformed
jTextNombreGens.setText( String.valueOf(ParametersGeneticAlgo.DEFAUT_NBGEN) );
}//GEN-LAST:event_jButtonDefautGenerationsActionPerformed
private void jButtonDefautPopulationActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButtonDefautPopulationActionPerformed
jTextTaillePopulation.setText( String.valueOf(ParametersGeneticAlgo.DEFAUT_TAILLEPOP) );
}//GEN-LAST:event_jButtonDefautPopulationActionPerformed
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JButton jButtonDefautCroisement;
private javax.swing.JButton jButtonDefautGenerations;
private javax.swing.JButton jButtonDefautMutation;
private javax.swing.JButton jButtonDefautPopulation;
private javax.swing.JLabel jLabelNombreGens;
private javax.swing.JLabel jLabelTaillePopulation;
private javax.swing.JLabel jLabelTauxCroisement;
private javax.swing.JLabel jLabelTauxMutation;
private javax.swing.JTextField jTextNombreGens;
private javax.swing.JTextField jTextTaillePopulation;
private javax.swing.JTextField jTextTauxCroisement;
private javax.swing.JTextField jTextTauxMutation;
// End of variables declaration//GEN-END:variables
public boolean EnregistrerParametres() {
int iTaillePopulation = 0;
float fPourcentageCroisement = 0.0f;
float fPourcentageMutation = 0.0f;
int iNombreGenerations = 0;
ParametersGeneticAlgo parametresTechnique = m_contexteResolution.m_parametresTechAlgoGenetique;
if (parametresTechnique == null)
return true;
// M�morisation des param�tres :
try {
iTaillePopulation = Integer.parseInt( jTextTaillePopulation.getText() );
parametresTechnique.m_iTaillePopulation = iTaillePopulation;
}
catch (NumberFormatException e) {
return false;
}
try {
iNombreGenerations = Integer.parseInt( jTextNombreGens.getText() );
parametresTechnique.m_iNombreGenerations = iNombreGenerations;
}
catch (NumberFormatException e) {
return false;
}
try {
fPourcentageCroisement = (float) ( Double.parseDouble( jTextTauxCroisement.getText() ) / 100.0 );
parametresTechnique.m_fPourcentageCroisement = fPourcentageCroisement;
}
catch (NumberFormatException e) {
return false;
}
try {
fPourcentageMutation = (float) ( Double.parseDouble( jTextTauxMutation.getText() ) / 100.0 );
parametresTechnique.m_fPourcentageMutation = fPourcentageMutation;
}
catch (NumberFormatException e) {
return false;
}
return true;
}
}