<commit_before>package aima.gui.fx.demo.search;

import aima.core.environment.nqueens.NQueensBoard;
import aima.core.environment.nqueens.NQueensBoard.Config;
import aima.core.search.framework.Metrics;
import aima.core.search.framework.qsearch.TreeSearch;
import aima.core.search.uninformed.DepthFirstSearch;
import aima.gui.fx.framework.IntegrableApplication;
import aima.gui.fx.framework.Parameter;
import aima.gui.fx.framework.SimulationPaneBuilder;
import aima.gui.fx.framework.SimulationPaneCtrl;
import aima.gui.fx.views.NQueensViewCtrl;
import javafx.application.Platform;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;


/**
 * Integrable application which demonstrates how different search strategies
 * solve the N-Queens problem.
 * 
 * @author <NAME>
 *
 */
public class NQueensSearchApp extends IntegrableApplication {

	public static void main(String[] args) {
		launch(args);
	}

	public final static String PARAM_STRATEGY = "strategy";
	public final static String PARAM_BOARD_SIZE = "boardSize";
	public final static String PARAM_INIT_CONFIG = "initConfig";

	private NQueensViewCtrl stateViewCtrl;
	private SimulationPaneCtrl simPaneCtrl;
	private NQueensSearchProg experiment;

	public NQueensSearchApp() {
		experiment = new NQueensSearchProg();
		experiment.addProgressTracer(this::updateStateView);
	}

	@Override
	public String getTitle() {
		return "N-Queens Search App";
	}

	/**
	 * Defines state view, parameters, and call-back functions and calls the
	 * simulation pane builder to create layout and controller objects.
	 */
	@Override
	public Pane createRootPane() {
		BorderPane root = new BorderPane();

		StackPane stateView = new StackPane();
		stateViewCtrl = new NQueensViewCtrl(stateView);

		Parameter[] params = createParameters();

		SimulationPaneBuilder builder = new SimulationPaneBuilder();
		builder.defineParameters(params);
		builder.defineStateView(stateView);
		builder.defineInitMethod(this::initialize);
		builder.defineSimMethod(this::simulate);
		simPaneCtrl = builder.getResultFor(root);

		return root;
	}
	
	protected Parameter[] createParameters() {
		Parameter p1 = new Parameter(PARAM_STRATEGY, "Depth-First Search", "Hill Climbing", "Simulated Annealing",
				"Genetic Algorithm");
		Parameter p2 = new Parameter(PARAM_BOARD_SIZE, 8, 16, 32, 64);
		Parameter p3 = new Parameter(PARAM_INIT_CONFIG, "FirstRow", "Random");
		p3.setDependency(PARAM_STRATEGY, "Hill Climbing", "Simulated Annealing");
		return new Parameter[] {p1, p2, p3};
	}

	/** Displays the selected function on the state view. */
	@Override
	public void initialize() {
		experiment.setBoardSize(simPaneCtrl.getParamAsInt(PARAM_BOARD_SIZE));
		Object strategy = simPaneCtrl.getParamValue(PARAM_STRATEGY);
		Config config;
		if (strategy.equals("Depth-First Search") || strategy.equals("Genetic Algorithm"))
			config = Config.EMPTY;
		else if (simPaneCtrl.getParamValue(PARAM_INIT_CONFIG).equals("Random"))<commit_msg>Dependency handling optimized.<commit_after>package aima.gui.fx.demo.search;

import aima.core.environment.nqueens.NQueensBoard;
import aima.core.environment.nqueens.NQueensBoard.Config;
import aima.core.search.framework.Metrics;
import aima.core.search.framework.qsearch.TreeSearch;
import aima.core.search.uninformed.DepthFirstSearch;
import aima.gui.fx.framework.IntegrableApplication;
import aima.gui.fx.framework.Parameter;
import aima.gui.fx.framework.SimulationPaneBuilder;
import aima.gui.fx.framework.SimulationPaneCtrl;
import aima.gui.fx.views.NQueensViewCtrl;
import javafx.application.Platform;
import javafx.scene.layout.BorderPane;
import javafx.scene.layout.Pane;
import javafx.scene.layout.StackPane;


/**
 * Integrable application which demonstrates how different search strategies
 * solve the N-Queens problem.
 * 
 * @author <NAME>
 *
 */
public class NQueensSearchApp extends IntegrableApplication {

	public static void main(String[] args) {
		launch(args);
	}

	public final static String PARAM_STRATEGY = "strategy";
	public final static String PARAM_BOARD_SIZE = "boardSize";
	public final static String PARAM_INIT_CONFIG = "initConfig";

	private NQueensViewCtrl stateViewCtrl;
	private SimulationPaneCtrl simPaneCtrl;
	private NQueensSearchProg experiment;

	public NQueensSearchApp() {
		experiment = new NQueensSearchProg();
		experiment.addProgressTracer(this::updateStateView);
	}

	@Override
	public String getTitle() {
		return "N-Queens Search App";
	}

	/**
	 * Defines state view, parameters, and call-back functions and calls the
	 * simulation pane builder to create layout and controller objects.
	 */
	@Override
	public Pane createRootPane() {
		BorderPane root = new BorderPane();

		StackPane stateView = new StackPane();
		stateViewCtrl = new NQueensViewCtrl(stateView);

		Parameter[] params = createParameters();

		SimulationPaneBuilder builder = new SimulationPaneBuilder();
		builder.defineParameters(params);
		builder.defineStateView(stateView);
		builder.defineInitMethod(this::initialize);
		builder.defineSimMethod(this::simulate);
		simPaneCtrl = builder.getResultFor(root);

		return root;
	}
	
	protected Parameter[] createParameters() {
		Parameter p1 = new Parameter(PARAM_STRATEGY, "Depth-First Search", "Hill Climbing", "Simulated Annealing",
				"Genetic Algorithm");
		Parameter p2 = new Parameter(PARAM_BOARD_SIZE, 8, 16, 32, 64);
		Parameter p3 = new Parameter(PARAM_INIT_CONFIG, "FirstRow", "Random");
		p3.setDependency(PARAM_STRATEGY, "Hill Climbing", "Simulated Annealing", "Genetic Algorithm");
		return new Parameter[] {p1, p2, p3};
	}

	/** Displays the selected function on the state view. */
	@Override
	public void initialize() {
		experiment.setBoardSize(simPaneCtrl.getParamAsInt(PARAM_BOARD_SIZE));
		Object strategy = simPaneCtrl.getParamValue(PARAM_STRATEGY);
		Config config;
		if (strategy.equals("Depth-First Search") || strategy.equals("Genetic Algorithm"))
			config = Config.EMPTY;
		else if (simPaneCtrl.getParamValue(PARAM_INIT_CONFIG).equals("Random"))
{'fraction_non_alphanumeric': 0.10353953026794575, 'fraction_numerical': 0.004631161098246774, 'mean_word_length': 5.7188888888888885, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7321602', 'n_tokens_mistral': 1936, 'n_tokens_neox': 1797, 'n_words': 429}