Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

(For the CS-Artificial Intelligence class) The task is to implement the greedy best-search algorithm. And also need to print the path from start to goal.

(For the CS-Artificial Intelligence class)

The task is to implement the greedy best-search algorithm. And also need to print the path from start to goal.

(COMPLETE CODE PROVIDED)

*STARTS*

node.java FILE(no change needed)

public class Node{ public final String value; public double g_scores; public final double h_scores; public double f_scores = 0; public Edge[] adjacencies; public Node parent; public Node(String val, double hVal){ value = val; h_scores = hVal; } public String toString(){ return value; } }

Map.java File(no change needed)

public class Map { Node n1 = new Node("Arad",366); Node n2 = new Node("Zerind",374); Node n3 = new Node("Oradea",380); Node n4 = new Node("Sibiu",253); Node n5 = new Node("Fagaras",178); Node n6 = new Node("Rimnicu Vilcea",193); Node n7 = new Node("Pitesti",98); Node n8 = new Node("Timisoara",329); Node n9 = new Node("Lugoj",244); Node n10 = new Node("Mehadia",241); Node n11 = new Node("Drobeta",242); Node n12 = new Node("Craiova",160); Node n13 = new Node("Bucharest",0); Node n14 = new Node("Giurgiu",77); Map(){ //initialize the graph base on the Romania map //initialize the edges //Arad n1.adjacencies = new Edge[]{ new Edge(n2,75), new Edge(n4,140), new Edge(n8,118) }; //Zerind n2.adjacencies = new Edge[]{ new Edge(n1,75), new Edge(n3,71) }; //Oradea n3.adjacencies = new Edge[]{ new Edge(n2,71), new Edge(n4,151) }; //Sibiu n4.adjacencies = new Edge[]{ new Edge(n1,140), new Edge(n5,99), new Edge(n3,151), new Edge(n6,80), }; //Fagaras n5.adjacencies = new Edge[]{ new Edge(n4,99), //178 new Edge(n13,211) }; //Rimnicu Vilcea n6.adjacencies = new Edge[]{ new Edge(n4,80), new Edge(n7,97), new Edge(n12,146) }; //Pitesti n7.adjacencies = new Edge[]{ new Edge(n6,97), new Edge(n13,101), new Edge(n12,138) }; //Timisoara n8.adjacencies = new Edge[]{ new Edge(n1,118), new Edge(n9,111) }; //Lugoj n9.adjacencies = new Edge[]{ new Edge(n8,111), new Edge(n10,70) }; //Mehadia n10.adjacencies = new Edge[]{ new Edge(n9,70), new Edge(n11,75) }; //Drobeta n11.adjacencies = new Edge[]{ new Edge(n10,75), new Edge(n12,120) }; //Craiova n12.adjacencies = new Edge[]{ new Edge(n11,120), new Edge(n6,146), new Edge(n7,138) }; //Bucharest n13.adjacencies = new Edge[]{ new Edge(n7,101), new Edge(n14,90), new Edge(n5,211) }; //Giurgiu n14.adjacencies = new Edge[]{ new Edge(n13,90) }; } public Node getStart() { return this.n1; // n1 is Arad } public Node getGoal() { return this.n13; // n13 is Bucharest } }

Edge.java File(no change needed)

public class Edge{ public final double cost; public final Node target; public Edge(Node targetNode, double costVal){ target = targetNode; cost = costVal; } }

*ENDS*

*CODE THAT NEEDS TO BE COMPLETED*

inforedS.java File (COMPLETE THIS CODE )

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 inforedS { // scores is the stright-line distance from the current city to Bucharest public static void main(String[] args){ // create the map of Romenia Map map=new Map(); // get the source node: Arad Node start=map.getStart(); // get the destination node: bucharest Node goal=map.getGoal(); // task 1: implement the greedy best-search algorithm, then // ...call the method here: // GreedyBS(start,goal) // print the path } 
public static void GreedyBS(Node source, Node goal){ // complete the code } } 

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Security

Authors: Alfred Basta, Melissa Zgola

1st Edition

1435453905, 978-1435453906

Students also viewed these Databases questions