Professional Documents
Culture Documents
(Semester 2, 2018/2019)
Fig. 1. Tree 1
First, the implementation of tree structure used for the tasks of uninformed search is defined
as follows (code is sent to students):
Each Node has a label and a path cost (computed from the start node) and a list of children
presented as edges where the current node is the begin and the end node is given by methods:
1
AI - LAB - NLU
(Semester 2, 2018/2019)
addEdge (Node that, double weight): add an edge connecting the current node with
that node. The weight is given as the second parameter.
addEdge(Node that): add an edge connecting the current node with that node. The
default weight is 1. This option is used for non-weighted tree.
Parent attribute is used to track the found path from the Start node to the Goal node (or
from the Root node to the Goal node).
Other comments for the implementation of tree structure is given in the code.
public Node execute(Node tree, String goal);// find the path from root node
//to the goal node
public Node execute(Node tree, String start, String goal); // find the path
//from start node to the goal node
==================================================================
==================================================================
==================================================================
2
AI - LAB - NLU
(Semester 2, 2018/2019)
The result of the test (BreadthFirstSearchAlgo) is as follows:
algo1.execute(nodeS);
For BreadthFirstSearchAlgo: S A B C D E G F H ?
For DepthFirstSearchAlgo: S C F G B A E D H ?
==================================================================
==================================================================
In this task, the parent attribute is used to track the found path from the Root node (or the
Start node) to the Goal node. The method for convert from a GOAL node with setting its
parent node is defined as follows (NodeUtils.java):
result.add(tmp.getLabel());
node = tmp;
}
Collections.reverse(result);
return result;
}
3
AI - LAB - NLU
(Semester 2, 2018/2019)
The result of the test (BreadthFirstSearchAlgo) with the above tree is as follows:
For BreadthFirstSearchAlgo: S B G ?
For DepthFirstSearchAlgo: S C F G ?
==================================================================
==================================================================
UniformCostSearchAlgo: S C F G, pathcost = 7
==================================================================
4
AI - LAB - NLU
(Semester 2, 2018/2019)
Task 4: Similar task 3, implement execute(Node tree, String start, String goal) in
BreadthFirstSearchAlgo.java, DepthFirstSearchAlgo.java and
UniformCostSearchAlgo.java
==================================================================
5 3
9
2
3
4 7
1
2
Fig. 4. Tree 2