private void btnBreadthFirst_Click(object sender, System.EventArgs e) { this.textBox1.Text = "NQueensDemo BFS -->" + System.Environment.NewLine; Problem problem = new Problem(new NQueensBoard(8),new NQueensSuccessorFunction(), new NQueensGoalTest()); Search search = new BreadthFirstSearch(new TreeSearch()); SearchAgent agent2 = new SearchAgent(problem, search); printActions(agent2.getActions()); printInstrumentation(agent2.getInstrumentation()); }
private void btnJugs_Click(object sender, System.EventArgs e) { this.textBox1.Text = ("Jugs Puzzle -->" + System.Environment.NewLine); Q2State initialState = new Q2State(); try { Problem problem = new Problem(initialState, new Q2SuccessorFunction(), new Q2GoalTest(), new Q2StepCostFunction()); Search search = new BreadthFirstSearch(new TreeSearch()); //Search search = new BreadthFirstSearch(new GraphSearch()); //Search search = new DepthFirstSearch(new TreeSearch()); //Search search = new DepthFirstSearch(new GraphSearch()); //Search search = new DepthLimitedSearch(12); //Search search = new IterativeDeepeningSearch(); //Search search = new AStarSearch(new TreeSearch()); ArrayList solution = search.search(problem); if (solution.Count == 0) { //empty list means failure this.textBox1.Text += (System.Environment.NewLine + "No Solution" +System.Environment.NewLine); } //this.textBox1.Text += (solution + System.Environment.NewLine); for (int i = 0; i < solution.Count; i++) { this.textBox1.Text += solution[i].ToString() + System.Environment.NewLine; } //Printing metrics Metrics searchMetrics = search.getMetrics(); IEnumerator iter = searchMetrics.keySet().GetEnumerator(); while (iter.MoveNext()) { string key = iter.Current.ToString(); string value = searchMetrics.get(key); this.textBox1.Text += (key +": " + value); } } catch (Exception ex) { this.textBox1.Text += ex.Message; } }