foundations of computational agents
In this chapter, the problem of finding a sequence of actions to achieve a goal is abstracted as searching for paths in directed graphs. Searching in graphs provides an appropriate abstract model of problem solving independent of a particular domain.
A directed graph consists of a set of nodes and a set of directed arcs between nodes. The idea is to find a path along these arcs from the start node to a goal node.
The abstraction is necessary because there may be more than one way to represent a problem as a graph. The examples in this chapter are in terms of state-space searching, where nodes represent states and arcs represent actions. Future chapters consider other ways to use graphs for problem solving.
A directed graph consists of:
a set of nodes
a set of arcs, where an arc is an ordered pair of nodes.
In this definition, a node could be anything. There may be infinitely many nodes and arcs. A graph need not be represented explicitly; only a procedure to generate nodes and arcs as needed is required.
The arc is an outgoing arc from and an incoming arc to .
A node is a neighbor of if there is an arc from to ; that is, if . Note that being a neighbor does not imply symmetry; just because is a neighbor of does not imply that is a neighbor of . Arcs may be labeled, for example, with the action that will take the agent from a node to its neighbor or with the cost of an action or both.
A path from node to node is a sequence of nodes such that , , and ; that is, there is an arc from to for each . Sometimes it is useful to view a path as the sequence of arcs, , or a sequence of labels of these arcs. Path is an initial part of , when .
A goal is a Boolean function on nodes. Node is a goal node if is true.
To encode problems as graphs, one node is identified as the start node. A solution is a path from the start node to a goal node.
Sometimes there is a cost – a non-negative number – associated with arcs. The cost of arc is written as .
The costs of arcs induce a cost of paths. Given a path , the cost of path is the sum of the costs of the arcs in the path:
An optimal solution is one of the solutions that has the lowest cost. That is, an optimal solution is a path from the start node to a goal node such that there is no path from the start node to a goal node where .
A state-space graph is a special type of graph where the nodes are the states, and there is an arc if there is an action that is possible to be carried out in and the effect of the action is to be in state . Future chapters consider other ways to represent problems as graphs.
Consider the problem of the delivery robot finding a path from location to location in the domain shown in Figure 3.1. The nodes are the labelled locations. Assume that the robot is only able to travel in one direction between the locations. Figure 3.3 shows the resulting graph where the nodes represent locations and the arcs represent possible single steps between locations. Each arc is shown with its associated cost, an estimate of the travel time of getting from one location to the next.
In this graph, the set of nodes is and the set of arcs is Node has no neighbors. Node has two neighbors, namely and . is not a neighbor of as there is no arc from to .
There are three paths from to :
If were the start node and were the unique goal node, all three paths would be a solution to the graph-searching problem. The second, with cost , is an optimal solution.
A cycle is a non-empty path where the end node is the same as the start node – that is, such that . A directed graph without any cycles is called a directed acyclic graph (DAG). Note that this should be called an acyclic directed graph, because it is a directed graph that happens to be acyclic, not an acyclic graph that happens to be directed, but DAG sounds better than ADG! The graph of Figure 3.3 is a DAG.
A tree is a DAG where there is one node with no incoming arcs and every other node has exactly one incoming arc. The node with no incoming arcs is called the root of the tree. A node with no outgoing arcs is called a leaf. In a tree, an arc goes from a parent to a child; the family-tree metaphor, with grandparents, siblings, and so on, is often used.
In many problems the search graph is not given explicitly, but is dynamically constructed as needed. For the search algorithms, all that is required is a way to generate the neighbors of a node and to determine if a node is a goal node.
The forward branching factor of a node is the number of outgoing arcs from the node. The backward branching factor of a node is the number of incoming arcs to the node. These factors provide measures for the complexity of graph algorithms. In the time and space complexity discussed below, assume that the branching factors are bounded, meaning they are all less than some positive integer.
In the graph of Figure 3.3, the forward branching factor of node is three because there are three outgoing arcs from node . The backward branching factor of node is zero; there are no incoming arcs to node . The forward branching factor of is zero and the backward branching factor of is one. The forward branching factor of node is two and the backward branching factor of is one.
The branching factor is an important key component in the size of the graph. If the forward branching factor for each node is , and the graph is a tree, there are nodes that are arcs away from any node. (This is only possible if the tree is infinite.)