Rule Based System
Rule based system is a knowledge representation scheme. Production based system consists of a set of production rules, a data structure that models the system’s current state, and a control subsystem or interpreter that interprets the current state and controls its activity by initiating appropriate action. A rule is said to be enabled or triggered when the condition part of the rule is satisfied by the current state of the system. An enabled rule is said to be fired if the action part of a rule is executed.
If the system status is such that more than one rule is triggered, the interpreter may be required to fire one or more of these simultaneously enabled rules; this is referred to as a conflict resolution. The conflict resolution can be enacted using its own set of productions. It uses criteria such as priority or ranking, prior selection, arbitrary or random choice, or doing all actions in parallel. The order in which the conditions are examined can be determined and priority could be adjusted dynamically. The action part can be a single action or a set of procedures that will change the status of the system. The latter change can include disabling a subset of the existing productions and enabling other productions.
An example of a rule based system is given below. This system examines the causes and corrective actions to be performed after failing to start a car. The execution of each action will modify the state of the starting system under considering and if there is more than one problem, all the corrective actions will have to be taken.
/* start a car */
if starter cranks the engine very slowly
then problem may be one or more of:
extreme cold temperature, battery, cables, connections
voltage regulator, alternator; use jumper cable to start
if starter does not crank but solenoid operates
then check cables and tighten and clean terminals and check
if problem is low battery voltage
then problem may be battery:
check specific gravity and replace if not acceptable;
problem may be loose, worn, or broken alternator belt:
do a visual inspection and if belt is okay, tighten
belt, otherwise replace it;
problem may be cables:
visual inspection, clean and tighten connections, and
replace broken connectors or cables;
problem may be voltage regulator:
check and replace;
problem may be alternator:
check and repair or replace alternator;
problem may be shorts in electrical system:
locate and correct
if problem loose or worn alternator belt
then tighten or replace alternator belt
if problem is battery
then check specific gravity and if acceptable charge otherwise
if problem os voltage regulator
then replace voltage regulator
if problem is alternator
then repair or replace alternator
if battery, cables and connections are good, solenoid operates,
but starter does not crank or cranks slowly
then replace the starter
if battery, cables and connections are good but solenoid does
then check ignition switch to solenoid circuit and correct
if battery, cables, connections and ignition switch to solenoid
circuit are good but solenoid does not click
then replace solenoid
if starter cranks the engine, smell of gas in the exhaust, but
the engine does not fire
then check and dry ignition circuit and replace faulty parts
if starter crank the engine but engine does not fire and no
smell of gas
then check and correct problems with fuel lines, fuel pump,
fuel filter, carburetor, fill tank
Since the action part of a rule can modify the state of the system, additional rules may have to be fired. There are two methods of matching rules to the current state of a system; forward chaining and backward chaining.
In forward chaining, the initial sets of facts are used to determine the rules that apply. If more than one rule applies one of these is chosen. The search proceeds by firing this rule and reached.
In backward chaining, all rules that have to be fired are first determined for the desired solution. These rules are then fired sequentially in the forward direction.
Disadvantage of Rule based system
In a large system, the production rules limit the interaction between rules and lead to inefficiencies. These inefficiencies become evident when a number of production rules have to be fired, but can only be executed one at a time. Each such firing is preceded by an interpretation of the current state of the system against the production rules. On average, half of these production rules have to be tested before each firing.