﻿Rule Class
This class represents a Fuzzy Rule, a linguistic expression representing some behavioral aspect of a Fuzzy Inference System.

Namespace:  AForge.Fuzzy
Assembly:  AForge.Fuzzy (in AForge.Fuzzy.dll) Version: 2.2.4.0 (2.2.4.0)

# Syntax

C#
`public class Rule`

# Remarks

A Fuzzy Rule is a fuzzy linguistic instruction that can be executed by a fuzzy system. The format of the Fuzzy Rule is:

IF antecedent THEN consequent

The antecedent is composed by a set of fuzzy clauses (see Clause) connected by fuzzy operations, like AND or OR. The operator NOT can be used to negate expressions:

...Clause1 AND (Clause2 OR Clause3) AND NOT Clause4 ...

Fuzzy clauses are written in form Variable IS Value. The NOT operator can be used to negate linguistic values as well:
...Variable1 IS Value1 AND Variable2 IS NOT Value2 ...

The consequent is a single of fuzzy clauses (Clause). To perform the linguistic computing, the Rule evaluates the clauses and then applies the fuzzy operators. Once this is done a value representing the confidence in the antecedent being true is obtained, and this is called firing strength of the Rule.

The firing strength is used to discover with how much confidence the consequent of a rule is true.

Sample usage:

CopyC#
```// create the linguistic labels (fuzzy sets) that compose the temperature
TrapezoidalFunction function1 = new TrapezoidalFunction(
10, 15, TrapezoidalFunction.EdgeType.Right );
FuzzySet fsCold = new FuzzySet( "Cold", function1 );
TrapezoidalFunction function2 = new TrapezoidalFunction( 10, 15, 20, 25 );
FuzzySet fsCool = new FuzzySet( "Cool", function2 );
TrapezoidalFunction function3 = new TrapezoidalFunction( 20, 25, 30, 35 );
FuzzySet fsWarm = new FuzzySet( "Warm", function3 );
TrapezoidalFunction function4 = new TrapezoidalFunction(
30, 35, TrapezoidalFunction.EdgeType.Left );
FuzzySet fsHot = new FuzzySet( "Hot", function4 );

// create a linguistic variable to represent steel temperature
LinguisticVariable lvSteel = new LinguisticVariable( "Steel", 0, 80 );
// adding labels to the variable

// create a linguistic variable to represent stove temperature
LinguisticVariable lvStove = new LinguisticVariable( "Stove", 0, 80 );
// adding labels to the variable

// create the linguistic labels (fuzzy sets) that compose the pressure
TrapezoidalFunction function5 = new TrapezoidalFunction(
20, 40, TrapezoidalFunction.EdgeType.Right );
FuzzySet fsLow = new FuzzySet( "Low", function5 );
TrapezoidalFunction function6 = new TrapezoidalFunction( 20, 40, 60, 80 );
FuzzySet fsMedium = new FuzzySet( "Medium", function6 );
TrapezoidalFunction function7 = new TrapezoidalFunction(
60, 80, TrapezoidalFunction.EdgeType.Left );
FuzzySet fsHigh = new FuzzySet( "High", function7 );
// create a linguistic variable to represent pressure
LinguisticVariable lvPressure = new LinguisticVariable( "Pressure", 0, 100 );
// adding labels to the variable

// create a linguistic variable database
Database db = new Database( );

// sample rules just to test the expression parsing
Rule r1 = new Rule( db, "Test1", "IF Steel is not Cold and Stove is Hot then Pressure is Low" );
Rule r2 = new Rule( db, "Test2", "IF Steel is Cold and not (Stove is Warm or Stove is Hot) then Pressure is Medium" );
Rule r3 = new Rule( db, "Test3", "IF Steel is Cold and Stove is Warm or Stove is Hot then Pressure is High" );

// testing the firing strength
lvSteel.NumericInput = 12;
lvStove.NumericInput = 35;
float result = r1.EvaluateFiringStrength( );
Console.WriteLine( result.ToString( ) );```

# Inheritance Hierarchy

System..::.Object
AForge.Fuzzy..::.Rule