|
@@ -25,6 +25,7 @@ import ui.view.UnitGraph;
|
|
|
import javax.swing.JButton;
|
|
|
|
|
|
import algorithms.geneticAlgorithm.Components.GAResultListener;
|
|
|
+import algorithms.geneticAlgorithm.holegGA.Components.HolegGeneration;
|
|
|
import algorithms.geneticAlgorithm.holegGA.Components.HolegIndividual;
|
|
|
|
|
|
import java.awt.event.ActionListener;
|
|
@@ -49,12 +50,14 @@ public class GenAlgoWindow implements GAResultListener<HolegIndividual> {
|
|
|
DefaultTreeModel treeModel;
|
|
|
DefaultMutableTreeNode treeRoot;
|
|
|
HashMap<DefaultMutableTreeNode, HolegIndividual> treeIndiHashmap;
|
|
|
-
|
|
|
GenAlgoHandler algoHandler;
|
|
|
private JTextField objectAmountField;
|
|
|
private JTextField edgeAmountField;
|
|
|
private JCheckBox chckbxOnlyNodes;
|
|
|
private JTextArea logArea;
|
|
|
+ private JTextField popSizeField;
|
|
|
+ private JTextField tournamentSizeField;
|
|
|
+ private JTextField tournamentProbField;
|
|
|
|
|
|
* Create the application.
|
|
|
*/
|
|
@@ -69,7 +72,9 @@ public class GenAlgoWindow implements GAResultListener<HolegIndividual> {
|
|
|
HolegIndividual originIndividual = new HolegIndividual(model.getObjectsOnCanvas());
|
|
|
ArrayList<HolegIndividual> originPopulation = new ArrayList<HolegIndividual>();
|
|
|
originPopulation.add(originIndividual);
|
|
|
- populationCreated(-1, originPopulation);
|
|
|
+ HolegGeneration originGen = new HolegGeneration(-1);
|
|
|
+ originGen.setGeneration(originPopulation);
|
|
|
+ populationCreated(originGen);
|
|
|
|
|
|
}
|
|
|
|
|
@@ -78,7 +83,7 @@ public class GenAlgoWindow implements GAResultListener<HolegIndividual> {
|
|
|
*/
|
|
|
private void initialize() {
|
|
|
frame = new JFrame();
|
|
|
- frame.setBounds(100, 100, 450, 409);
|
|
|
+ frame.setBounds(100, 100, 450, 520);
|
|
|
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
|
|
|
frame.getContentPane().setLayout(new BoxLayout(frame.getContentPane(), BoxLayout.X_AXIS));
|
|
|
|
|
@@ -107,12 +112,14 @@ public class GenAlgoWindow implements GAResultListener<HolegIndividual> {
|
|
|
rightSplitPane.setLeftComponent(panel);
|
|
|
|
|
|
JButton btnCreategeneration = new JButton("createGeneration");
|
|
|
- btnCreategeneration.setBounds(44, 11, 117, 23);
|
|
|
+ btnCreategeneration.setBounds(10, 11, 117, 23);
|
|
|
btnCreategeneration.addActionListener(new ActionListener() {
|
|
|
public void actionPerformed(ActionEvent arg0) {
|
|
|
int objAmount = Integer.parseInt(objectAmountField.getText());
|
|
|
int edgeAmount = Integer.parseInt(edgeAmountField.getText());
|
|
|
algoHandler.onlyNodes = chckbxOnlyNodes.isSelected();
|
|
|
+ algoHandler.popSize = Integer.parseInt(popSizeField.getText());
|
|
|
+ algoHandler.tournamentSize = Integer.parseInt(tournamentSizeField.getText());
|
|
|
algoHandler.createGeneration(objAmount, edgeAmount);
|
|
|
}
|
|
|
});
|
|
@@ -120,33 +127,77 @@ public class GenAlgoWindow implements GAResultListener<HolegIndividual> {
|
|
|
|
|
|
objectAmountField = new JTextField();
|
|
|
objectAmountField.setText("0");
|
|
|
- objectAmountField.setBounds(89, 45, 86, 20);
|
|
|
+ objectAmountField.setBounds(111, 45, 86, 20);
|
|
|
panel.add(objectAmountField);
|
|
|
objectAmountField.setColumns(10);
|
|
|
panel.add(btnCreategeneration);
|
|
|
|
|
|
edgeAmountField = new JTextField();
|
|
|
edgeAmountField.setText("0");
|
|
|
- edgeAmountField.setBounds(89, 76, 86, 20);
|
|
|
+ edgeAmountField.setBounds(111, 76, 86, 20);
|
|
|
panel.add(edgeAmountField);
|
|
|
edgeAmountField.setColumns(10);
|
|
|
|
|
|
JLabel lblMaxObjects = new JLabel("Max Objects");
|
|
|
- lblMaxObjects.setBounds(10, 48, 69, 14);
|
|
|
+ lblMaxObjects.setBounds(10, 48, 91, 14);
|
|
|
panel.add(lblMaxObjects);
|
|
|
|
|
|
JLabel lblMaxEdges = new JLabel("Max Edges");
|
|
|
- lblMaxEdges.setBounds(10, 79, 69, 14);
|
|
|
+ lblMaxEdges.setBounds(10, 79, 91, 14);
|
|
|
panel.add(lblMaxEdges);
|
|
|
|
|
|
chckbxOnlyNodes = new JCheckBox("\r\n");
|
|
|
- chckbxOnlyNodes.setBounds(89, 103, 25, 23);
|
|
|
+ chckbxOnlyNodes.setBounds(121, 103, 25, 23);
|
|
|
panel.add(chckbxOnlyNodes);
|
|
|
|
|
|
JLabel lblOnlyNodes = new JLabel("Only Nodes?");
|
|
|
- lblOnlyNodes.setBounds(10, 107, 69, 14);
|
|
|
+ lblOnlyNodes.setBounds(10, 107, 91, 14);
|
|
|
panel.add(lblOnlyNodes);
|
|
|
|
|
|
+ popSizeField = new JTextField();
|
|
|
+ popSizeField.setText("100");
|
|
|
+ popSizeField.setBounds(111, 133, 86, 20);
|
|
|
+ panel.add(popSizeField);
|
|
|
+ popSizeField.setColumns(10);
|
|
|
+
|
|
|
+ tournamentSizeField = new JTextField();
|
|
|
+ tournamentSizeField.setText("30");
|
|
|
+ tournamentSizeField.setBounds(111, 164, 86, 20);
|
|
|
+ panel.add(tournamentSizeField);
|
|
|
+ tournamentSizeField.setColumns(10);
|
|
|
+
|
|
|
+ tournamentProbField = new JTextField();
|
|
|
+ tournamentProbField.setText("0.8");
|
|
|
+ tournamentProbField.setBounds(111, 195, 86, 20);
|
|
|
+ panel.add(tournamentProbField);
|
|
|
+ tournamentProbField.setColumns(10);
|
|
|
+
|
|
|
+ JLabel lblPopulationSize = new JLabel("Population Size");
|
|
|
+ lblPopulationSize.setBounds(10, 136, 91, 14);
|
|
|
+ panel.add(lblPopulationSize);
|
|
|
+
|
|
|
+ JLabel lblTournamentSize = new JLabel("Tournament Size");
|
|
|
+ lblTournamentSize.setBounds(10, 167, 91, 14);
|
|
|
+ panel.add(lblTournamentSize);
|
|
|
+
|
|
|
+ JLabel lblTournamentProb = new JLabel("Tournament Prob");
|
|
|
+ lblTournamentProb.setBounds(10, 198, 91, 14);
|
|
|
+ panel.add(lblTournamentProb);
|
|
|
+
|
|
|
+ JButton btnMutation = new JButton("mutation");
|
|
|
+ btnMutation.addActionListener(new ActionListener() {
|
|
|
+ public void actionPerformed(ActionEvent arg0) {
|
|
|
+ int objAmount = Integer.parseInt(objectAmountField.getText());
|
|
|
+ int edgeAmount = Integer.parseInt(edgeAmountField.getText());
|
|
|
+ algoHandler.onlyNodes = chckbxOnlyNodes.isSelected();
|
|
|
+ algoHandler.popSize = Integer.parseInt(popSizeField.getText());
|
|
|
+ algoHandler.tournamentSize = Integer.parseInt(tournamentSizeField.getText());
|
|
|
+ algoHandler.mutationTest(objAmount, edgeAmount);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ btnMutation.setBounds(137, 11, 89, 23);
|
|
|
+ panel.add(btnMutation);
|
|
|
+
|
|
|
logArea = new JTextArea();
|
|
|
rightSplitPane.setRightComponent(logArea);
|
|
|
|
|
@@ -156,7 +207,7 @@ public class GenAlgoWindow implements GAResultListener<HolegIndividual> {
|
|
|
TreePath selPath = genTree.getPathForLocation(e.getX(), e.getY());
|
|
|
if(selRow != -1) {
|
|
|
if(e.getClickCount() == 1) {
|
|
|
-
|
|
|
+ nodeSingleClick(selRow, selPath);
|
|
|
}
|
|
|
else if(e.getClickCount() == 2) {
|
|
|
nodeDoubleClick(selRow, selPath);
|
|
@@ -168,28 +219,31 @@ public class GenAlgoWindow implements GAResultListener<HolegIndividual> {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ public void nodeSingleClick(int selRow, TreePath selPath){
|
|
|
+ DefaultMutableTreeNode node = (DefaultMutableTreeNode)selPath.getLastPathComponent();
|
|
|
+ if(node.getUserObject() instanceof HolegGeneration){
|
|
|
+ logArea.setText(((HolegGeneration)node.getUserObject()).getInformation());
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
public void nodeDoubleClick(int selRow, TreePath selPath){
|
|
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode)selPath.getLastPathComponent();
|
|
|
+
|
|
|
if(treeIndiHashmap.get(node) != null){
|
|
|
algoHandler.drawIndividual(treeIndiHashmap.get(node));
|
|
|
logArea.setText(treeIndiHashmap.get(node).log);
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
|
|
|
@Override
|
|
|
- public void populationCreated(int generation, ArrayList<HolegIndividual> population) {
|
|
|
- DefaultMutableTreeNode genNode;
|
|
|
- if(! (generation == -1)){
|
|
|
- genNode = new DefaultMutableTreeNode("Generation " + generation);
|
|
|
- }else{
|
|
|
- genNode = new DefaultMutableTreeNode("Origin Network");
|
|
|
- }
|
|
|
+ public void populationCreated(HolegGeneration holegGen) {
|
|
|
+ DefaultMutableTreeNode genNode = new DefaultMutableTreeNode(holegGen);
|
|
|
|
|
|
+ ArrayList<HolegIndividual> population = holegGen.getGeneration();
|
|
|
for(int i = 0; i < population.size(); i++){
|
|
|
DefaultMutableTreeNode child = new DefaultMutableTreeNode("Individual " + i);
|
|
|
- population.get(i).setId(generation, i);
|
|
|
+ population.get(i).setId(holegGen.getGenCount(), i);
|
|
|
treeIndiHashmap.put(child, population.get(i));
|
|
|
genNode.add(child);
|
|
|
}
|