To solve a problem, a computer must first have the problem stated in a form that it can work on. The state space is the standard form.
The State Space
A state is a description of the problem at one moment. The initial state is where we start, and a goal state is where we wish to end. Operators, or actions, change one state into another. The state space is the set of all states that can be reached from the initial state. A solution is a path of operators from the initial state to a goal. It is often drawn as a graph, in which states are nodes and operators are edges, and each step may have a cost.
Definition: State space. The set of all states reachable from the initial state by any sequence of operators, together with the operators that connect them.
Formulating a Problem
To formulate a problem we choose the representation of a state, the initial state, the goal test, the operators with the states that they give, and the path cost. For the water jug problem with a 4-litre and a 3-litre jug, a state is the pair (x, y) of the water in each, the start is (0, 0), the goal is any state with x = 2, and the operators are fill, empty and pour. A good formulation leaves out detail that does not matter.
Production Systems
A production system is a model for solving problems with a set of rules. It has three parts: a set of production rules of the form IF condition THEN action, a working memory (or database) that holds the current state, and a control strategy that chooses which rule to apply when several can apply. The system matches the rules to the state, selects one by the control strategy, applies it, and repeats until the goal is reached. A production system is commutative if the order in which applicable rules are applied does not change the result, and monotonic if applying a rule never stops other rules from applying. Expert systems are built as production systems.
Table 1.2: Parts of a production system
| Part | Role | Example |
|---|---|---|
| Rule set | Conditions and actions | Fill the 4-litre jug |
| Working memory | Current state | (4, 0) |
| Control strategy | Pick a rule | Try the first that fits |
Example 1.2: Water jug problem
Problem: With a 4-litre jug and a 3-litre jug and a tap, measure exactly 2 litres in the 4-litre jug.
Solution: Write states as (x, y):
- Fill the 3-litre jug: (0, 3).
- Pour it into the 4-litre jug: (3, 0).
- Fill the 3-litre jug again: (3, 3).
- Pour into the 4-litre jug until full: (4, 2).
- Empty the 4-litre jug: (0, 2).
- Pour the 2 litres into the 4-litre jug: (2, 0).
Result: The goal (2, 0) is reached in six steps.
path = [(0,0),(0,3),(3,0),(3,3),(4,2),(0,2),(2,0)]
for i, s in enumerate(path):
print(i, s)
print("goal reached:", path[-1][0] == 2)
Output
0 (0, 0)
1 (0, 3)
2 (3, 0)
3 (3, 3)
4 (4, 2)
5 (0, 2)
6 (2, 0)
goal reached: True
Common mistakes
- Stating a problem with too much detail, which makes the space too large.
- Not defining a clear goal test.
- Forgetting that a rule applies only when its condition holds in the current state.
Key takeaways
- A problem has an initial state, operators and a goal test.
- A solution is a path from the initial state to a goal.
- A production system has rules, working memory and a control strategy.
- Expert systems are production systems.
Practice questions
- What is a state space?
- Name the parts of a production system.
- What is a goal test?
Answers to the practice questions
- The set of all states reachable from the initial state by operators.
- Production rules, working memory and a control strategy.
- A test that tells whether a state is a goal state.
Sources
- Official BCA syllabus Artificial Intelligence and Expert Systems, course code 25BCA405DS02, Unit I
