Prohledávání stavového prostoru I: BFS & DFS
Prohledávání stavového prostoru I: BFS & DFS
Prohledávání stavového prostoru I: BFS & DFS
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Cybernetics and Artificial Intelligence 2012/SS<br />
Assignment:<br />
Searching a State Space<br />
Petr Benda, translated by Radek Píbil<br />
Part A<br />
Implement <strong>BFS</strong> and <strong>DFS</strong> algorithms for state-space search. If you implement them<br />
using the OPEN and CLOSED sets (lists), the difference between them is minimal.<br />
The output of the algorithm is meant to be the first path between start and target<br />
state found. Use the provided libraries for the GUI. In case of matlab or c/c++ either<br />
use comprehensive text output, or create a simple GUI yourself. Matlab also has a<br />
pretty good support of Java applications so there might be a way for you to use both<br />
Matlab and the GUI. The state-space is defined by a planar graph.<br />
Guidelines for implementation:<br />
1. Download the “software tool for students” from the CourseWare website. Use<br />
NetBeans to open the project.<br />
2. Open the <strong>BFS</strong>.java source in NetBeans IDE. Your implementation goes in<br />
there.<br />
3. You can run your program using a premade run configuration “bfs” for NB.<br />
“bfs directx” is provided in case you cannot use OpenGL.<br />
4. In case you have troubles using the project on your home PC, follow<br />
the instructions “solving settings problems” on the CW website,<br />
which is going to be periodically updated. The system can be ran<br />
with console output only using the “noVisio” argument (see<br />
run<strong>BFS</strong>_novisio.bat), which may be useful for debugging.<br />
Notes for implementation:<br />
Do not create any other files, all the code is supposed to go into <strong>BFS</strong>.java.<br />
See javadoc.<br />
The node.isTarget() methods return true if a node is the target.<br />
Newly expanded edges are drawn automatically after calling expand() method.<br />
You should know that the nodes accessed through the kui.Node interface have<br />
hashCode and equals correctly implemented. It is not possible to create a<br />
node class not implementing kui.Node.<br />
In order to draw the path (the ordered list of nodes), it is necessary to return<br />
it from the findWay() method.
Cybernetics and Artificial Intelligence 2012/SS<br />
Your algorithm can be run without NetBeans IDE using the Application class as<br />
the main class and the name of your class (fully qualified) as a parameter.<br />
This method is also being used by the provided batch files.<br />
In order to slow down the execution in order to see the progress of execution you<br />
can use the following code:<br />
try {<br />
Thread.sleep(100); // 100 ms<br />
} catch (InterruptedException ex) {<br />
}<br />
Using the visualization tool:<br />
ex.printStackTrace();<br />
Setting the start and target node can be done using the left mouse button. Zooming<br />
in and out can be done with the mouse wheel. A region can be enlarged using<br />
ctrl+left mouse button and drag selecting the desired region. The right mouse button<br />
can be used to scroll around the map. The color of an expanded edge corresponds<br />
with the time at which the expansion took place. The oldest edges are green,<br />
followed by blue, purple, red and yellow for the newest.<br />
How to submit?<br />
1. The deadline for all three tasks (<strong>BFS</strong>, <strong>DFS</strong>, A*) is the next seminar.<br />
2. Only <strong>BFS</strong> and A* are submitted into CW. <strong>DFS</strong> is evaluated by your teacher, in<br />
person.<br />
3. Create a zip archive, which contains the <strong>BFS</strong>.java and AStar.java source files<br />
in “kui” directory. One file is ok as well, for a partial automatic test, but it is<br />
necessary for you to submit both files in the end. Other files are not<br />
admissible.<br />
4. Your classes must not contain any slowdown code.<br />
5. Upload the zip archive into the upload system (https://cw.felk.cvut.cz/upload).<br />
The name of the archive is irrelevant.<br />
6. An automatic test is executed. It takes 30s at most, and then you can<br />
examine the results.<br />
7. You can upload the zip archive into the upload system as many times as you<br />
may require.
Cybernetics and Artificial Intelligence 2012/SS<br />
Assignment:<br />
Part B<br />
Implement the A* algorithm. The result is going to be the shortest path between the<br />
starting a target node specified by the user. Design and use a heuristic function. Use<br />
the provided GUI libraries (if applicable). The state-space is specified by a planar<br />
graph.<br />
Guidelines for implementation:<br />
1. Open the AStar.java source file in the project. This class implements the<br />
InformedSearchingAlgorithm interface. In contrast with the previous task,<br />
findWay() receives both the starting and target node.<br />
2. Change the run configuration to “astar” (hit the arrow next to the combo box<br />
with “” and choose “astar”).<br />
Notes for implementation:<br />
Do not create any other files, put all the necessary code into the AStar.java<br />
source file.<br />
Questions:<br />
Which of the algorithms usually (in our case) returns the shortest path?<br />
How many states the <strong>BFS</strong> and <strong>DFS</strong> algorithms are going to expand in the<br />
worst case?<br />
In what sense is the path found by <strong>BFS</strong> the shortest one?<br />
What conditions must the heuristic function satisfy in order to be sure that the<br />
A* algorithm actually returns the shortest path with certainty?<br />
What is a monotonic heuristic function?<br />
What heuristic function have you chosen?<br />
Is it necessary to implement the algorithm in its full generality, or is it possible<br />
to perform some simplifications?<br />
How to submit?<br />
1. The deadline for all three tasks (<strong>BFS</strong>, <strong>DFS</strong>, A*) is the next seminar.<br />
2. Only <strong>BFS</strong> and A* are submitted into CW. <strong>DFS</strong> is evaluated by your teacher, in<br />
person.
Cybernetics and Artificial Intelligence 2012/SS<br />
3. Create a zip archive, which contains the <strong>BFS</strong>.java and AStar.java source files<br />
in “kui” directory. One file is ok as well, for a partial automatic test, but it is<br />
necessary for you to submit both files in the end. Other files are not<br />
admissible.<br />
4. Your classes must not contain any slowdown code.<br />
5. Upload the zip archive into the upload system (https://cw.felk.cvut.cz/upload).<br />
The name of the archive is irrelevant.<br />
6. An automatic test is executed. It takes 30s at most, and then you can<br />
examine the results.<br />
7. You can upload the zip archive into the upload system as many times as you<br />
may require.