Instructions
Write a program in Java that implements the A* algorithm to find a
path from any two given nodes.
Problem Overview & Algorithm Description
In a fully-observable environment where there are both pathable and
blocked nodes, an agent must find a good path from their starting
node to the goal node. The agent must use the A* algorithm to
determine its path. For this program, you must use the Manhattan
method for calculating the heuristic.
Remember: your heuristic function is a representation of how
good or close you are to the goal state.
Program Requirements
No graphics are required for this program but using them will help
you with debugging and problem solving. Your environment should be
a 15x15 tile-based world that randomly generates nodes that are
unpathable (blocks) in 10% of the nodes. This should be done each
time the program compiles ensuring that there are different
environment makeups each run. The program should display the
generated environment when the program runs, and should allow the
user to select a starting node and goal node. This can be done via
text input into the console or with a GUI. Once the start and goal
nodes have been defined, the program should run the A* algorithm to
find a path. The path should be displayed (series of [x,y] nodes,
highlighting nodes, or actually moving the agent) if one exists, or
a message indicating that a path could not be found. The user
should be able to continue specifying starting and goal nodes after
paths have been found.
You must use the following class :
public class Node {
private int row, col, f, g, h, type;
private Node parent;
public Node(int r, int c, int t){
row = r;
col = c;
type = t;
parent = null;
//type 0 is traverseable, 1 is not
}
//mutator methods to set values
public void setF(){
f = g + h;
}
public void setG(int value){
g = value;
}
public void setH(int value){
h = value;
}
public void setParent(Node n){
parent = n;
}
//accessor methods to get values
public int getF(){
return f;
}
public int getG(){
return g;
}
public int getH(){
return h;
}
public Node getParent(){
return parent;
}
public int getRow(){
return row;
}
public int getCol(){
return col;
}
public boolean equals(Object in){
//typecast to Node
Node n = (Node) in;
return row == n.getRow() && col == n.getCol();
}
public String toString(){
return "Node: " + row + "_" + col;
}
}
Instructions Write a program in Java that implements the A* algorithm to find a path from...
Consider the following undirected weighted graph where you want to find a path from A to G. A / \ B --- C \ / \ G --- H Weights (costs) of the edges are W(AB) = 1; W(AC) = 3; W(BC) = 1; W(BG) = 9; W(CG) = 5; W(CH) = 2; W(GH) = 1, and the heuristic estimates (h(n)) to the goal node, G, are h(A) = 5, h(B) = 4, h(C) = 1, h(G) = 0, h(H)...
//Graph Class:
import java.util.ArrayList;
//Graph is a class whose objects represent graphs.
public class Graph {
ArrayList<Node> nodeList;
ArrayList<Edge> edgeList;
public Graph() {
nodeList = new ArrayList<Node>();
edgeList = new ArrayList<Edge>();
}
public ArrayList<Node> getNodeList() {
return nodeList;
}
public ArrayList<Edge> getEdgeList() {
return edgeList;
}
public void addNode(Node n) {
nodeList.add(n);
}
public void addEdge(Edge e) {
edgeList.add(e);
}
public String toString() {
String s = "Graph g.\n";
if (nodeList.size() > 0) {
for (Node n : nodeList) {
// Print node info
String t = "\nNode " + n.getName() + ", abbrev " + n.getAbbrev() + ", value " + n.getVal() + "\n";
s = s.concat(t);
}
s = s.concat("\n");
}
return s;
}
}
// Node Class:
import java.util.ArrayList;
// Node is a class whose objects represent nodes (a.k.a., vertices) in the graph.
public class Node {
String name;
String val; // The value of the Node
String abbrev; // The abbreviation for the Node
ArrayList<Edge> outgoingEdges;
ArrayList<Edge> incomingEdges;
String color; //Create the color of the TYPE Node List
int start; //Create the Starting Time
int end; //Create the Ending Time
public Node( String theAbbrev ) {
setAbbrev( theAbbrev );
val = null;
name = null;
outgoingEdges = new ArrayList<Edge>();
incomingEdges = new ArrayList<Edge>();
}
public String getAbbrev() {
return abbrev;
}
public String getName() {
return name;
}
public String getVal() {
return val;
}
public ArrayList<Edge> getOutgoingEdges() {
return outgoingEdges;
}
public ArrayList<Edge> getIncomingEdges() {
return incomingEdges;...
Please I need help ASAP Java Programing: Binary Search Tree Fully implement the BST class in Listing 25.4 (on page 961 of the 11th Edition of the text). Design and write a (main) driver program to completely test every method in the BST class to ensure the class meets all its requirements. You should read the Listing 25.5: TestBST.java for an idea of what your program should look like. Listing 25.4 BST.java public class BST> extends AbstractTree { protected TreeNode...
When outputting the path found in the proposed program, the direction of movement is output. However, the direction of movement to the last movement, EXIT, is not output. To print this out, please describe how to modify the proposed program. #include <stdio.h> #define NUM_ROWS 5 #define NUM_COLS 3 #define BOUNDARY_COLS 5 #define MAX_STACK_SIZE 100 #define FALSE 0 #define TRUE 1 typedef struct { short int row; short int col; short int dir; } element; element stack[MAX_STACK_SIZE];...
Shortest Path (DAG) Students, In this coding assignment, you will be asked to write Java code to read a text file (input.txt) of a graph represented as an adjacency list. Example: A, 7, B, 9, C B, 1, C C, 8, E, 2, F D, 1, E, 3, G E, 3, G F, 3, D, -3, H H, 6, G K, 3, H, -1, F The graph represented by the adjacency list above looks like this: The graph is a...
Programming Language : JAVA Write a class named Ship. Its purpose is to model a ship in the BattleShip game and its placement on the Battleship board. Ships exist on a 10 x 10 battleship board with ten rows labeled A through J and columns labeled 1 through 9 and the final column labeled 0 to indicate the tenth column. We will refer to the Ship placed on the board at the origin which the pair (r,c) where in the...
Write a C++ program called ts.cpp that implements the topological sorting algorithm based on the DFS algorithm. Your program should read an input file name and determine if the input graph is a DAG (= directed acyclic graph) or not. If the graph is not a DAG, your program has to stop without further processing. However, if it’s a DAG, your program should display the starting node(s), popping-off order, and topologically sorted list. In the problem, you can assume that...
Please follow all the instructions and do all the parts
(a-d)!
Create a Java program which implements Dijkstra’s shortest path
algorithm according to the psueudocode below. Base the design on
the weighted graph implementation used in Problem3.java (provided
at the bottom). Your program should include the following
features:
a. A new method receives a starting vertex index and a target
vertex index (e.g. 0 and 4). It computes the shortest distances to
all vertexes using Dijkstra’s algorithm. The pseudocode is...
SpecificationStart with your Java program "prog340" which implements Deliverables A and B.This assignment is based on the definition of the Traveling Salesperson Problem (the TSP): Given a set of cities, you want to find the shortest route that visits every city and ends up back at the original starting city. For the purposes of this problem, every city will be directly reachable from every other city (think flying from city to city).Your goal is to use a non-genetic local search...
Hi I need help with a java program that I need to create a Airline Reservation System I already finish it but it doesnt work can someone please help me I would be delighted it doesnt show the available seats when running the program and I need it to run until someone says no for booking a seat and if they want to cancel a seat it should ask the user to cancel a seat or continue booking also it...