You are required to write your own Java program to solve the problem. The proble
ID: 3542139 • Letter: Y
Question
You are required to write your own Java program to solve the problem. The problem is described as follows. Consider an idealization of a problem where a robot has to navigate its way around obstacles. The goal is to find the shortest distance between two points on a plane that has convex polygonal obstacles. Figure 2 shows an example scene with seven polygonal obstacles where the robot has to move from the point start to the point end. Convince yourself that the shortest path from one polygon vertex to any other in the scene consists of straight-line segments joining some of the vertices of the polygon. (Note that the start and the end goal points may be considered polygons of size 0). Implement an algorithm to find the shortest path from the start node to the end node using an A* (A-star) heuristic search. Use the straight-line distance to the end node as a heuristic function. Show your pseudo code for this algorithm and present the solutions for the following problem using the A* algorithm you implemented.
Polygon 1: ((220, 616), (220, 666), (251, 670), (272, 647))
Polygon 2: ((341, 655), (359, 667), (374, 651), (366, 577))
Polygon 3: ((311, 530), (311, 559), (339, 578), (361, 560), (361, 528), (336, 516))
Polygon 4: ((105, 628), (151, 670), (180, 629), (156, 577), (113, 587))
Polygon 5: ((118, 517), (245, 517), (245, 577), (118, 557))
Polygon 6: ((280, 583), (333, 583), (333, 665), (280, 665))
Polygon 7: ((252, 594), (290, 562), (264, 538))
Polygon 8: ((198, 635), (217, 574), (182, 574))
Start: (120, 650) End: (380, 560)
Figure 2
Note: This figure is for illustration purpose only. Positions of the polygons inside the figure may not reflect their actual coordinates.
You are required to write your own Java program to solve the problem. The problem is described as follows. Consider an idealization of a problem where a robot has to navigate its way around obstacles. The goal is to find the shortest distance between two points on a plane that has convex polygonal obstacles. Figure 2 shows an example scene with seven polygonal obstacles where the robot has to move from the point start to the point end. Convince yourself that the shortest path from one polygon vertex to any other in the scene consists of straight-line segments joining some of the vertices of the polygon. (Note that the start and the end goal points may be considered polygons of size 0). Implement an algorithm to find the shortest path from the start node to the end node using an A* (A-star) heuristic search. Use the straight-line distance to the end node as a heuristic function. Show your pseudo code for this algorithm and present the solutions for the following problem using thExplanation / Answer
import java.awt.Graphics; import java.awt.Color; import java.awt.Point; /** * Represents simple simulated robots. These robots occupy rooms with walls and * tiled floors. Robots walk around on the floors (one tile at a time), changing * and sensing the colors of tiles if they wish. But robots can't move through * walls, thus they have to stay in their room. Robots can face in any of four * directions, which are described as compass directions in analogy to a map: * north is towards the top of the robot's room as drawn on a computer screen, * east is towards the right, etc. * @see geneseo.cs.sc.RobotRoom */ public class Robot { /** * The heading a robot has when facing north. */ public static final int NORTH = 0; /** * The heading a robot has when facing east. */ public static final int EAST = 1; /** * The heading a robot has when facing south. */ public static final int SOUTH = 2; /** * The heading a robot has when facing west. */ public static final int WEST = 3; // Internally, a robot records the room it is in, its row and column // coordinates (in tiles) within that room, its heading, whether // or not it is visible, and the amount of time it should delay // after movements: private RobotRoom room; private int row; private int col; private int direction; private boolean visible; private int delayTime; private static final int initialDelay = 500; // Number of milliseconds delay for new robots // Robots also have some data that they use to draw themselves: x and y offsets // of vertices of the robot relative to its center, and a color to draw it in // (see the comments for the "draw" method below for more details): private static final int[] xOffsets = { 0, -10, -5, -5, 5, 5, 10 }; private static final int[] yOffsets = { -10, 0, 0, 10, 10, 0, 0 }; private static final Color robotColor = new Color( (float)0.25, (float)0.0, (float)0.3 ); /** * Initialize a robot and a room for it to occupy. The room will be a default room, * and this robot will be its only occupant. The robot will have the default position * and heading (center of the room, facing north). For example *Robot r = new Robot();
Robot r = new Robot( 1, 3, Robot.NORTH, someRoom );
r.move();
if ( r.okToMove() ) {...
r.turnLeft();
r.turnRight();
r.paint( java.awt.Color.yellow );
if ( r.colorOfTile() == java.awt.Color.red ) {...
if ( r.heading() == Robot.NORTH ) {...
Robot.NORTH, Robot.EAST, * Robot.SOUTH, or Robot.WEST. */ public int heading() { return direction; } /** * Set the speed at which a robot moves and turns. For example * r.setSpeed( 100 );
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.