Best First Search: Graphs

package graphs; import java.util.*; import graphs.State; public class GraphImplementation { public void dfs(Node root) { //Avoid infinite loops if(root == null) return; System.out.print(root.getVertex() + “\t”); root.state = State.Visited; //for every child for(Node n: root.getChild()) { //if childs state is not visited then recurse if(n.state == State.Unvisited) { dfs(n); } } } public void bfs(Node root) … Continue reading Best First Search: Graphs

Asignación #3: A* program

import java.util.PriorityQueue; import java.util.HashSet; import java.util.Set; import java.util.List; import java.util.Comparator; import java.util.ArrayList; import java.util.Collections; public class AstarSearchAlgo{ //h scores is the stright-line distance from the current city to Bucharest public static void main(String[] args){ //initialize the graph base on the Romania map Node n1 = new Node(“Arad”,366); Node n2 = new Node(“Zerind”,374); Node n3 = … Continue reading Asignación #3: A* program