Ejemplo n.º 1
0
		private void btnJocks_Click(object sender, System.EventArgs e)
		{
			this.textBox1.Text = "";
			JocksNerdsState initialState = new JocksNerdsState();
			try 
			{
				Problem problem = new Problem(initialState, 
					new JocksNerdsSuccessorFunction(),
					new JocksNerdsGoalTest());
            
				//Search search = new BreadthFirstSearch(new TreeSearch());
				//Search search = new BreadthFirstSearch(new GraphSearch());

				//this one never ends because it tries to traverse a tree of effectively infinite depth
				//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 GraphSearch());
				//Search search = new GreedyBestFirstSearch(new GraphSearch());
				//Search search = new HillClimbingSearch();
				Search search = new SimulatedAnnealingSearch();

            
				ArrayList solution = search.search(problem);
            
				if (solution.Count == 0) 
				{ //empty list means failure
					//System.out.println("\nNo Solution\n");
					this.textBox1.Text = System.Environment.NewLine + "No Solution";
				}
				for (int i = 0; i < solution.Count; i++)
				{
					this.textBox1.Text += solution[i].ToString() + System.Environment.NewLine;
				}
            
				//Printing metrics
				Metrics searchMetrics = search.getMetrics();
				//ArrayList iter = (ArrayList)searchMetrics.keySet();
				ICollection col = searchMetrics.keySet();
				IEnumerator iter = col.GetEnumerator();
				//iter.GetEnumerator();
				//Array r = new Array();
				//iter.MoveNext();
				
				//iter.
            
            
				while(iter.MoveNext())
				{
					string key =  iter.Current.ToString();
					string val = searchMetrics.get(key);
					this.textBox1.Text += System.Environment.NewLine + key + ": " + val;
					//iter.MoveNext();
				}
            
			} 
			catch (Exception ex) 
			{
				//e.printStackTrace();
				this.textBox1.Text += ex.Message;
			}
		}
Ejemplo n.º 2
0
		private void btnSimulatedAnnealing_Click(object sender, System.EventArgs e)
		{
			this.textBox1.Text = "NQueensDemo Simulated Annealing -->" + System.Environment.NewLine;

			Problem problem =  new Problem(new NQueensBoard(8),new NQueensSuccessorFunction(), new NQueensGoalTest(),new QueensToBePlacedHeuristic());
			Search search =  new SimulatedAnnealingSearch();
			SearchAgent agent = new SearchAgent(problem,search);

			
			printActions(agent.getActions());
			printInstrumentation(agent.getInstrumentation());
		}
Ejemplo n.º 3
0
		private void btnSimulatedAnnealing_Click(object sender, System.EventArgs e)
		{
			this.textBox1.Text = "EightPuzzleDemo Simulated Annealing  Search -->" + System.Environment.NewLine;
			Problem problem = new Problem(random1,
				new EightPuzzleSuccessorFunction(),
				new EightPuzzleGoalTest(), new ManhattanHeuristicFunction());
			Search search = new SimulatedAnnealingSearch();
			SearchAgent agent = new SearchAgent(problem, search);
			printActions(agent.getActions());
			printInstrumentation(agent.getInstrumentation());
		}