|
@@ -25,6 +25,7 @@ import ui.view.UnitGraph;
|
|
|
import javax.swing.JButton;
|
|
|
|
|
|
import algorithms.geneticAlgorithm.Components.GAResultListener;
|
|
|
+import algorithms.geneticAlgorithm.holegGA.Components.HolegIndividual;
|
|
|
|
|
|
import java.awt.event.ActionListener;
|
|
|
import java.awt.event.ActionEvent;
|
|
@@ -33,7 +34,11 @@ import java.awt.event.MouseEvent;
|
|
|
import java.awt.event.MouseListener;
|
|
|
import java.util.ArrayList;
|
|
|
import java.util.HashMap;
|
|
|
+
|
|
|
import javax.swing.JTextField;
|
|
|
+import javax.swing.JLabel;
|
|
|
+import javax.swing.JCheckBox;
|
|
|
+import javax.swing.JTextArea;
|
|
|
|
|
|
public class GenAlgoWindow implements GAResultListener<HolegIndividual> {
|
|
|
|
|
@@ -46,7 +51,10 @@ public class GenAlgoWindow implements GAResultListener<HolegIndividual> {
|
|
|
HashMap<DefaultMutableTreeNode, HolegIndividual> treeIndiHashmap;
|
|
|
|
|
|
GenAlgoHandler algoHandler;
|
|
|
- private JTextField textField;
|
|
|
+ private JTextField objectAmountField;
|
|
|
+ private JTextField edgeAmountField;
|
|
|
+ private JCheckBox chckbxOnlyNodes;
|
|
|
+ private JTextArea logArea;
|
|
|
/**
|
|
|
* Create the application.
|
|
|
*/
|
|
@@ -58,6 +66,11 @@ public class GenAlgoWindow implements GAResultListener<HolegIndividual> {
|
|
|
treeIndiHashmap = new HashMap<DefaultMutableTreeNode, HolegIndividual>();
|
|
|
initialize();
|
|
|
|
|
|
+ HolegIndividual originIndividual = new HolegIndividual(model.getObjectsOnCanvas());
|
|
|
+ ArrayList<HolegIndividual> originPopulation = new ArrayList<HolegIndividual>();
|
|
|
+ originPopulation.add(originIndividual);
|
|
|
+ populationCreated(-1, originPopulation);
|
|
|
+
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -94,17 +107,49 @@ public class GenAlgoWindow implements GAResultListener<HolegIndividual> {
|
|
|
rightSplitPane.setLeftComponent(panel);
|
|
|
|
|
|
JButton btnCreategeneration = new JButton("createGeneration");
|
|
|
+ btnCreategeneration.setBounds(44, 11, 117, 23);
|
|
|
btnCreategeneration.addActionListener(new ActionListener() {
|
|
|
public void actionPerformed(ActionEvent arg0) {
|
|
|
- algoHandler.createGeneration();
|
|
|
+ int objAmount = Integer.parseInt(objectAmountField.getText());
|
|
|
+ int edgeAmount = Integer.parseInt(edgeAmountField.getText());
|
|
|
+ algoHandler.onlyNodes = chckbxOnlyNodes.isSelected();
|
|
|
+ algoHandler.createGeneration(objAmount, edgeAmount);
|
|
|
}
|
|
|
});
|
|
|
+ panel.setLayout(null);
|
|
|
|
|
|
- textField = new JTextField();
|
|
|
- panel.add(textField);
|
|
|
- textField.setColumns(10);
|
|
|
+ objectAmountField = new JTextField();
|
|
|
+ objectAmountField.setText("0");
|
|
|
+ objectAmountField.setBounds(89, 45, 86, 20);
|
|
|
+ panel.add(objectAmountField);
|
|
|
+ objectAmountField.setColumns(10);
|
|
|
panel.add(btnCreategeneration);
|
|
|
|
|
|
+ edgeAmountField = new JTextField();
|
|
|
+ edgeAmountField.setText("0");
|
|
|
+ edgeAmountField.setBounds(89, 76, 86, 20);
|
|
|
+ panel.add(edgeAmountField);
|
|
|
+ edgeAmountField.setColumns(10);
|
|
|
+
|
|
|
+ JLabel lblMaxObjects = new JLabel("Max Objects");
|
|
|
+ lblMaxObjects.setBounds(10, 48, 69, 14);
|
|
|
+ panel.add(lblMaxObjects);
|
|
|
+
|
|
|
+ JLabel lblMaxEdges = new JLabel("Max Edges");
|
|
|
+ lblMaxEdges.setBounds(10, 79, 69, 14);
|
|
|
+ panel.add(lblMaxEdges);
|
|
|
+
|
|
|
+ chckbxOnlyNodes = new JCheckBox("\r\n");
|
|
|
+ chckbxOnlyNodes.setBounds(89, 103, 25, 23);
|
|
|
+ panel.add(chckbxOnlyNodes);
|
|
|
+
|
|
|
+ JLabel lblOnlyNodes = new JLabel("Only Nodes?");
|
|
|
+ lblOnlyNodes.setBounds(10, 107, 69, 14);
|
|
|
+ panel.add(lblOnlyNodes);
|
|
|
+
|
|
|
+ logArea = new JTextArea();
|
|
|
+ rightSplitPane.setRightComponent(logArea);
|
|
|
+
|
|
|
MouseListener ml = new MouseAdapter() {
|
|
|
public void mousePressed(MouseEvent e) {
|
|
|
int selRow = genTree.getRowForLocation(e.getX(), e.getY());
|
|
@@ -127,6 +172,7 @@ public class GenAlgoWindow implements GAResultListener<HolegIndividual> {
|
|
|
DefaultMutableTreeNode node = (DefaultMutableTreeNode)selPath.getLastPathComponent();
|
|
|
if(treeIndiHashmap.get(node) != null){
|
|
|
algoHandler.drawIndividual(treeIndiHashmap.get(node));
|
|
|
+ logArea.setText(treeIndiHashmap.get(node).log);
|
|
|
}
|
|
|
|
|
|
}
|
|
@@ -134,10 +180,16 @@ public class GenAlgoWindow implements GAResultListener<HolegIndividual> {
|
|
|
|
|
|
@Override
|
|
|
public void populationCreated(int generation, ArrayList<HolegIndividual> population) {
|
|
|
- DefaultMutableTreeNode genNode = new DefaultMutableTreeNode("Generation " + generation);
|
|
|
+ DefaultMutableTreeNode genNode;
|
|
|
+ if(! (generation == -1)){
|
|
|
+ genNode = new DefaultMutableTreeNode("Generation " + generation);
|
|
|
+ }else{
|
|
|
+ genNode = new DefaultMutableTreeNode("Origin Network");
|
|
|
+ }
|
|
|
|
|
|
for(int i = 0; i < population.size(); i++){
|
|
|
DefaultMutableTreeNode child = new DefaultMutableTreeNode("Individual " + i);
|
|
|
+ population.get(i).setId(generation, i);
|
|
|
treeIndiHashmap.put(child, population.get(i));
|
|
|
genNode.add(child);
|
|
|
}
|