package ia.search;

import ia.City;
import ia.Colour;
import ia.WeightCityLink;

import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.Stack;

import org.jgrapht.UndirectedGraph;

/**
 * 
 * @author Anderson Queiroz, Fernando Zucatelli, Jo��o Coutinho, Tiago Queiroz
 *
 */





public class DeepSearch implements SearchProblem {

	
	
	
	
	
	/** The graph */
	private UndirectedGraph<City, WeightCityLink> graph;
	/** A stack to walk trough graph */ 
	private Stack<City> stack;
	
	/**
	 * Deep search to search problem
	 * @param graph
	 */


	
	public DeepSearch(UndirectedGraph<City, WeightCityLink> graph)
	{
		this.graph = graph;
		this.stack = new Stack<City>();
		
	
		
			}
	
	
	public void paint_white(UndirectedGraph<City,WeightCityLink> graph){
		
		 Set<City>vertices = graph.vertexSet();
		 
		 for(City c:vertices){
			 c.setColour(Colour.WHITE);
			 
		 }
		 
		 
			
		}
	
	public Stack run(City inicio, City fim){
		
		City temp, filho; 
		Set<WeightCityLink> vert_col ; //Collections de v������rtice
		stack.add(inicio); 
		paint_white(graph);
		
		while(!stack.empty()){ 
			temp = stack.pop();
			temp.setColour(Colour.GRAY);
			
			if(temp == fim){
				return stack;
			}
			
			vert_col = graph.edgesOf(temp);
			
			for(WeightCityLink e: vert_col){
				filho = e.getTarget();
				
				if(filho.c.equals("WHITE")){
					stack.add(filho);
				}
				
				temp.setColour(Colour.BLACK);;
				
			}			
			
			
			
		}
		
		return null;
	}
	
	@Override
	public List<Object> expand(Object o) {
		//Cast to city
		City city = (City) o;
		//A Set to keep neighbour
		Set<WeightCityLink> neighbour;
		//Get neighbours
		neighbour = graph.edgesOf(city);
		
		List<Object> l = new LinkedList<Object>();
		
		for(WeightCityLink c : neighbour)
		{
			if(!l.contains(c.getTarget()))
			{
				l.add(c);
			}
		}
		
		return l;
	}

	@Override
	public SearchResult process(Object o) {
		
		
		
		return null;
	}

}

@@ -269,18 +269,17 @@
 elli, Jo
-%EF%BF%BD%EF%BF%BD
+%C3%A3
 o Coutin
@@ -303,21 +303,16 @@
 %0A *%0A */%0A
-%0A%0A%0A%0A%0A
 public c
@@ -357,17 +357,8 @@
 em %7B
-%0A%0A%09%0A%09%0A%09%0A%09
 %0A%09%0A%09
@@ -561,12 +561,8 @@
  */%0A
-%0A%0A%09%0A
 %09pub
@@ -685,23 +685,10 @@
 );%0A%09
-%09%0A%09%0A%09%09%0A%09%09%09%7D%0A%09%0A%09
+%7D%0A
 %0A%09pu
@@ -758,14 +758,11 @@
 h)%7B%0A
-%09%09
 %0A%09%09
- 
 Set%3C
@@ -796,23 +796,19 @@
 xSet();%0A
-%09%09 
 %0A%09%09
- 
 for(City
@@ -824,17 +824,16 @@
 es)%7B%0A%09%09%09
- 
 c.setCol
@@ -857,33 +857,13 @@
 ;%0A%09%09
-%09 %0A%09%09 %7D%0A%09%09 %0A%09%09 %0A%09%09%09%0A%09
+%7D%0A
 %09%7D%0A
-%09
 %0A%09pu
@@ -901,18 +901,16 @@
 y fim)%7B%0A
-%09%09
 %0A%09%09City 
@@ -1030,18 +1030,16 @@
 graph);%0A
-%09%09
 %0A%09%09while
@@ -1112,19 +1112,16 @@
 .GRAY);%0A
-%09%09%09
 %0A%09%09%09if(t
@@ -1156,19 +1156,16 @@
 k;%0A%09%09%09%7D%0A
-%09%09%09
 %0A%09%09%09vert
@@ -1192,19 +1192,16 @@
 (temp);%0A
-%09%09%09
 %0A%09%09%09for(
@@ -1256,20 +1256,16 @@
 rget();%0A
-%09%09%09%09
 %0A%09%09%09%09if(
@@ -1319,20 +1319,16 @@
 ;%0A%09%09%09%09%7D%0A
-%09%09%09%09
 %0A%09%09%09%09tem
@@ -1359,21 +1359,16 @@
 );;%0A
-%09%09%09%09%0A
 %09%09%09%7D%09%09%09%0A
 %09%09%09%0A
@@ -1367,27 +1367,12 @@
 %09%09%09%0A
-%09%09%09%0A%09%09%09%0A%09%09%09%0A
 %09%09%7D%0A
-%09%09%0A
 %09%09re
@@ -1385,17 +1385,16 @@
 ull;%0A%09%7D%0A
-%09
 %0A%09@Overr
@@ -1593,18 +1593,16 @@
 (city);%0A
-%09%09
 %0A%09%09List%3C
@@ -1639,18 +1639,16 @@
 ect%3E();%0A
-%09%09
 %0A%09%09for(W
@@ -1742,19 +1742,16 @@
 %09%09%7D%0A%09%09%7D%0A
-%09%09%0A
 %09%09return
@@ -1814,17 +1814,8 @@
 ) %7B%0A
-%09%09%0A%09%09%0A%09%09%0A
 %09%09re
@@ -1828,11 +1828,10 @@
 ull;%0A%09%7D%0A
-%0A
 %7D%0A

Is is not a white space program