aboutsummaryrefslogtreecommitdiffstats
path: root/src/jcgp/gui/population/PopulationPane.java
blob: 51b5ba41a174512671a261f1e0973a2c3ffa0043 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package jcgp.gui.population;

import javafx.scene.control.Tab;
import javafx.scene.control.TabPane;
import jcgp.JCGP;
import jcgp.backend.modules.problem.TestCaseProblem;
import jcgp.backend.modules.problem.TestCaseProblem.TestCase;
import jcgp.gui.GUI;

public class PopulationPane extends TabPane {
	
	private GUI gui;
	private TestCase<Object> currentTestCase;
	private boolean evaluating = false;
	
	public PopulationPane(GUI gui) {
		super();
		this.gui = gui;
		setTabClosingPolicy(TabClosingPolicy.UNAVAILABLE);
		remakeTabs();
	}
	
	public void remakeTabs() {
		getTabs().clear();
		JCGP jcgp = gui.getExperiment();
		
		Tab tab;
		ChromosomePane cp;
		for (int i = 0; i < jcgp.getResources().populationSize(); i++) {
			cp = new ChromosomePane(jcgp.getPopulation().get(i));
			tab = new Tab("Chr " + i);
			tab.setContent(cp);
			getTabs().add(tab);
		}
	}
		
	public void updateGenes() {
		if (evaluating) {
			evaluateTestCase(currentTestCase);
		}
		for (int i = 0; i < getTabs().size(); i++) {
			((ChromosomePane) getTabs().get(i).getContent()).updateGenes(gui.getExperiment().getPopulation().get(i));
		}
	}
	
	public void evaluateTestCase(TestCase<Object> testCase) {
		if (gui.getExperiment().getProblem() instanceof TestCaseProblem && testCase != null) {
			currentTestCase = testCase;
			if (testCase.getInputs().length == gui.getExperiment().getResources().inputs()) {
				evaluating = true;
				for (int i = 0; i < getTabs().size(); i++) {
					//((ChromosomePane) getTabs().get(i).getContent()).setInputs(testCase.getInputs());
				}
			} else {
				throw new IllegalArgumentException("Test case has " + testCase.getInputs().length
						+ " inputs and chromosome has " + gui.getExperiment().getResources().inputs());
			}
		}
	}
	
	public void hideValues() {
		evaluating = false;
		for (int i = 0; i < getTabs().size(); i++) {
			//((ChromosomePane) getTabs().get(i).getContent()).updateValues();
		}
	}

	public boolean isEvaluating() {
		return evaluating;
	}

	public void setEvaluating(boolean value) {
		evaluating = value;
	}
}