FJK Home | CPE/CSC 480 | Syllabus | Schedule | Lecture Notes | Assignments | Labs | Project | Teams |
Name(s): | |
Status | final |
Points: | 10 |
Deadline: | Tue of Week 4, end of lab |
This lab exercise builds upon the previous one with the Bot Environment. Please get the latest version from the Blackboard "Course Materials" section.
In this exercise, you need to systematically explore the environment by employing the breadth-first and the depth-first search algorithms. This algorithm looks at the potential successor nodes of the current node, and selects the next node to be explored. In the case of our Bot Environment, a grid element corresponds to one node, and only those nodes that the agent can actually enter need to be considered.
The exploration of these nodes can be depicted as a search tree, with the starting node as the root, the reachable grid elements as successor nodes, and nodes that have no successors as leaf nodes. The search is completed when either a specially marked node, the goal, is encountered, or when all reachable options have been exhausted.
In order to perform a systematic search, the two fundamental strategies are breadth-first and depth-first. In addition, the agent needs to select among nodes at the same level in a systematic manner. The most frequently used selections here are left-to-right or right-to-left with respect to the way the nodes are listed in a graphical view. Depending on the type of the nodes, there is also often an obvious ordering, such as alphabetical or numerical. In this task, use a clockwise ordering starting from the "North" position (i.e. in the order North, East, South, West).
In this strategy, all direct successor nodes of a given level are explored first, and then the successor nodes of the first node at this level are examined. In the tree, this means that all nodes at a given level are explored before proceeding to the next level.
This search strategy picks the first successor node of the current node, then the first successor node of that node, and so on. In the tree, this means that all nodes of a branch are explored until a leaf node is reached. Once a leaf node is reached, the algorithm "backtracks" (goes up one level), and selects the next node at that level as the new starting point of a sub-branch.
Your task is to implement one agent each for the breadth-first strategy and the depth-first search strategy. For both search methods, the agent should first construct a path to the goal, and then carry out this path. Once the agent reaches the goal, print out the search cost and path cost to the logging window.
In this lab, you will use the BotEnvironment, (similar to the Wumpus Environment).
A key difference between the two environments is that instead of defining
the step()
function, you should define a searchStep()
function
and a movementStep() function
.
To understand how this is implemented, note that in the BotSearch
class
which your agent extends, the following function is called by clicking the step button:
public void step() {
if (!goalFound) {
searchStep();
}
else if (!getGoalReached()) {
movementStep();
}
}
Your searchStep() function should implement the Breadth First Search
and the Depth First Search algorithms to find a path to the goal.
The movementStep()
function should carry out this path.
You can test out your path planning and path following using the environment
CPE480-Lab3-BFSearch.sbm
.
Note that the grader will use other maps as well to determine if your agent works.
Start by downloading the base code CPE480-Lab3-BFSearch.zip
from Blackboard.
A sample Windows-based agent compile batch file and run batch file are provided.
Similar command lines can be used in Linux:
javac -classpath BotEnvironment.jar:.: ./Agents/MySearchAgent.java
java -classpath .:BotEnvironment.jar BotEnvironment.BotEnvironment
Here are some hints for programming the BFS and DFS algorithms:
You can use the log() function to print out debugging information. For example:
log("Adding east node " + eastNode.getX() + "," + eastNode.getY());
You can reset all your variables in the function reset()
that is called
whenever the Map Reset drop-down menu is selected.
The class Node
has been implemented where each cell
in the environment grid is represented by a node.
These nodes can be used with the following functions:
getIsWall()
Returns true if the node is a wall, false otherwise. getIsEvaluated()
Returns true if the node has been evaluated by the search, false otherwise.getX(), getY()
Returns the integer x or y coordinate of the node in the map.getIsGoal()
Returns true if the node is a goal, false otherwise.The following functions can be used for an offline search. Note that there is a difference between the bot's location (or actual location in the environment) versus the current location of the search node in the state space. This location is depicted with a "fairy" during the search.
getGoalFound()
Returns true if the search has found the goal by the search, false otherwise.getSearchLocation()
Returns the Node object that the search is occupying.
From here, you can use the methods in the Node
class to find out more about this node and adjacent nodes. getBotLocation()
Returns the Node
object that the agent is occupying.
From here, the programmer can use the methods in the Node
class to find out more about this node and adjacent nodes. moveSearchLocation(Node n)
Moves the search location to the Node
object given.
This is most usefully coupled with the Node
returned from getNextFringeNode()
. getNorthOfSearchLocation()
Returns the corresponding Node
objects adjacent to the search location. getEastOfSearchLocation()
getSouthOfSearchLocation()
getWestOfSearchLocation()
getSearchCost()
Returns the total integer searching cost, where the cost to view a node
is defined in sbcproperties.dat
.getMovementCost()
Returns the total integer movement cost, where moving and turning costs
are defined in sbcproperties.dat
. SBConstants.NORTH, SBConstants.EAST, SBConstants.SOUTH, SBConstants.WEST
Defined constants that can be used for directions. A variable fringe
has been defined which is a linked list of nodes
that works as a First In First Out (FIFO) stack.
addToFringe(Node n)
Adds the Node
object to the end of the fringe. getNextFringeNode()
Returns the first Node
object in the fringe. fringeContains(Node n)
Returns true if the Node
object is in the fringe, false
otherwise. For moving the bot in the moveStep()
function,
you can use turnTo(int direction)
and moveForward()
as in the previous lab.
More information on how to use the environment can be found by following the link to the bot search tutorial. If you have problems with it, post your questions on the Blackboard discussion forum.
I strongly recommend to look at the way the different search algorithms are developed from a generic search method in the textbook (this is also shown on the PowerPoint slides). Using this approach, it is fairly straightforward to modify one agent (e.g. breadth-first) in order to obtain an agent that behaves differently (e.g. depth-first). It is probably a little more difficult to understand and implement the first one this way. The alternative is to develop each agent separately from scratch, causing considerably more work for additional agents.
This assignment must be submitted electronically via the assignment submission function on Blackboard under "Lab & Assignment Submissions" by the deadline specified above. You need to submit the following items, assembled into a single .tar, .zip, or similar format:
This is a "pair" assignment, and you can either do it individually, or together with one other student. Each pair must figure out and formulate their own answers, and write their own programs. It is fine with me to discuss general aspects of this lab with others (e.g. general aspects of the different search strategies).
If you have questions or comments concerning the programming aspects of the lab, post them on the Blackboard Discussion Forum for the lab. I will check that forum on a regular basis, and try to answeryour questions. It is also possible that somebody else ran into a similar problem, and may know the solution.
FJK Home | CPE/CSC 480 | Syllabus | Schedule | Lecture Notes | Assignments | Labs | Project | Teams |
Franz Kurfess |