Some problems decompose into sub-problems that all must be solved. These are represented by AND-OR graphs and searched by AO*.

AND-OR Graphs

In an ordinary state-space graph every arc is an alternative (OR): one path suffices. In many problems, such as proving a theorem or planning a trip, a goal can be achieved by either of several alternatives (OR) or by solving all of several sub-goals together (AND). An AND-OR graph shows this: AND arcs are joined by an arc symbol and require all their successors. For example, "buy a car" may be achieved by (OR) "inherit money" or by (AND) "get a loan" and "find a job". A solution is not a path but a subgraph: from the root, one OR-successor is chosen and all AND-successors of each chosen AND-arc are included, ending in terminal (solved) nodes.

Definition: AND-OR graph. A graph in which a node's successors are grouped into alternatives (OR) and into sets that must all be solved (AND); its solution is a sub-graph rather than a single path.

The AO* Algorithm

AO\ is the best-first algorithm for AND-OR graphs, using an admissible heuristic. It works in two repeated steps. Forward step: starting at the root, follow the currently best marked arcs to find a non-terminal node of the best partial solution graph and expand it, giving each new successor its heuristic estimate h. Backward (cost revision) step: from the expanded node, revise the cost upwards: for an OR node the cost is the minimum over its arcs, and for an AND arc the cost is the sum of the costs of its successors plus the arc costs; the best arc is marked, and the revision is propagated to the ancestors. The process stops when the root is labelled solved*.

Cost Calculation

If a node has an OR-arc to B with cost c₁ and h(B), and an AND-arc to C and D with costs c₂, c₃ and heuristics h(C), h(D), then f = min( c₁ + h(B), (c₂ + h(C)) + (c₃ + h(D)) ). The choice may change after expansion: when a successor's cost is revised upwards, the other alternative may become cheaper, so AO can switch the marked arc, which is why revision proceeds backward. AO is optimal for an admissible heuristic in acyclic graphs.

Table 2.5: A versus AO**

Basis A* AO*
Graph OR graph (state space) AND-OR graph
Solution A path A sub-graph
Cost g + h along a path min over OR, sum over AND
Revision Update g of nodes Back-propagate costs up the graph

Example 2.5: Cost revision in AO*

Problem: Node A has an OR arc to B (cost 1, h(B) = 7) and an AND arc to C and D (cost 1 each, h(C) = 3, h(D) = 2). Find the best choice. Then C is expanded and its cost is revised to 6. Find the new best choice.

Solution:

  1. Via B: 1 + 7 = 8. Via the AND arc: (1 + 3) + (1 + 2) = 7. Mark the AND arc; f(A) = 7.
  2. After C's revision to 6, the AND arc costs (1 + 6) + (1 + 2) = 10.
  3. Now via B costs 8 < 10, so the marked arc switches to B and f(A) = 8.

Result: Initially choose AND (cost 7); after revision choose B (cost 8).

def best_arc(hB, hC, hD, step=1):
    via_or = step + hB
    via_and = (step + hC) + (step + hD)
    if via_and < via_or:
        return "AND (C and D)", via_and
    return "OR (B)", via_or
print(best_arc(7, 3, 2))
print(best_arc(7, 6, 2))

Output

('AND (C and D)', 7)
('OR (B)', 8)

Common mistakes

  • Treating AND successors as alternatives; all of them must be solved.
  • Summing costs of OR alternatives instead of taking the minimum.
  • Forgetting to back-propagate the revised cost to ancestors.
  • Expecting a solution to be a single path.

Key takeaways

  • AND-OR graphs model problems with alternatives (OR) and conjunctions (AND).
  • A solution is a sub-graph; AO* is the best-first search for it.
  • OR node cost = minimum arc; AND arc cost = sum of successors plus arc costs.
  • AO* expands the best partial graph and revises costs backward.

Practice questions

  1. What is the cost of an AND arc in AO*?
  2. How does AO differ from A?
  3. Give an example of an AND-OR problem.

Answers to the practice questions

  1. The sum of the costs of all its successor nodes plus the arc costs.
  2. It searches AND-OR graphs for a solution sub-graph and back-propagates costs, whereas A* finds a single path.
  3. Theorem proving or planning, where a goal splits into sub-goals that must all be achieved.

Sources

  • Official BCA syllabus Artificial Intelligence, course code 26BCA404DS04, Unit II