FCL Construction
A segment is the basic module in the GAF system. A typical FCL file
contains a segment and optional configuration like this.
configuration_declaration
segment_declaration
cycle_declaration
variable_declaration(s)
symbol_declaration(s)
preset_declaration(s)
init_run_declaration
rule_declaration(s)
end_declaration
Configuration: configuration_declaration
FCL allows configuration information been declared for specific
module(s). The configuration declaration must be enclosed inside
following key words. Please refer GAF.DOC for more detail about
configurable attributes and values.
CONFIGURATION
attribute = value;
. . .
END_CONFIGURATION;
Declare Segment: segment_declaration, end_declaration
There are three types of segments: normal control segment, feedback
segment, and evaluation segment.
Format for segment_declaration:
FORMAT SEGMENT seg_name
FEEDBACK seg_name
Format for end_declaration:
FORMAT END seg_name ;
Where
seg_name : the name of the segment
Example
SEGMENT main_control
CYCLE_TIME 0.1
. . .
END main_control;
The key SEGMENT declares a normal control segment or an evaluation
segment. Use the key FEEDBACK to declare a feedback segment. In
simulation and adapt modes the feedback segment's output value will be
feed back to the control segment(s) based on variable name(s).
Define Cycle Time: cycle_declaration
FORMAT CYCLE_TIME value
Where
value : the cycle time in seconds
Example
SEGMENT main_control
CYCLE_TIME 0.1
. . .
END main_control;
Cycle_time defines how frequently the segment runs. For example a
value of 0.1 defines the segment runs every 100 milliseconds. Note that
actual delay time between two consecutive runs may be longer than 100
milliseconds if GAF is heavily loaded with segments.
Declare Variable: variable_declaration
There are four different kinds of variables: IN, OUT, INOUT, and LOCAL.
The segment will only read (reference) from those IN variables, and write
(generate new value) to the OUT variables. The segment can read and
write to both INOUT and LOCAL variables, however, local variables are
not visible from outside the segment.
FORMAT var_type seg_name (min_value, max_value)
Where
var_type : one of the 4 types IN OUT INOUT LOCAL
var_name : the variable name
min_value : the minimum value of the variable
max_value : the maximum value of the variable
Example
SEGMENT main_control
CYCLE_TIME 0.1
IN Reference (0, 100)
OUT Result (0, 10)
LOCAL Temp (-1, 1)
. . .
END main_control;
Variable name must be unique in the same segment. A variable should not
be declared as an output variable (OUT or INOUT) in more than one
segments.
Declare Fuzzy Symbol: symbol_declaration
The basic fuzzy membership set definition is a trapezoid with 4 points
below, low, high, above, and a max_truth value.
_____ <----- max_truth: maximum truth value
/ \
/ \
/ \
-------+--+-----+--+------- <----- 0: minimum truth value
| | | |
| | | above: false above
| | high: high truth
| low: low truth
below: false below
As depicted in above diagram, the truth for different values are:
if value <= below truth = 0
if value >= above truth = 0
if low <= value <= high truth = max_truth
for other values use interpolation to derive truth
The range of truth value is 0.0 to 1.0.
FORMAT SYMBOL sym_name [OF var_name] fuzzy_membership_set
Format for fuzzy_membership_set
( below, low, high, above [, truth [, center ] ] )
Where
sym_name : the name of the symbol
var_name : the name of the variable for this symbol
fuzzy_membership_set
: defines the four points of a membership set and
truth : the max truth value
center : the center value
Example
SEGMENT main_control
CYCLE_TIME 0.1
IN Reference (0, 100)
OUT Result (0, 10)
LOCAL Temp (-1, 1)
SYMBOL small OF Reference (0, 0, 10, 20, 1.0)
SYMBOL strong (8, 9, 10, 10, 1, 10)
. . .
END main_control;
The fuzzy symbol declaration is used to declare a named fuzzy
membership set. This named symbol can then be used in the fuzzy rules.
The symbol defines the shape of a trapezoid fuzzy membership set, as
described above, and the optional truth value and the center value. If
the center value is specified, GAF uses this value, otherwise GAF
calculates the center of gravity as the center value. A generic symbol
can be defined for all variables or defined for a specific variable with
"OF var_name" option. If a symbol is defined for a specific variable, it
can only be used for that variable. Symbol names are not required to be
unique in a segment. For example, two symbols "VERY_SMALL" can be
defined for two different variables "SPEED" and "POPULATION" with two
different shapes.
Initialization and Run : init_run_declaration
Initialization declaration is a sequence of assignments to initialize the
segment. The run declaration is a sequence of assignments with
conditional branch to be executed every cycle.
FORMAT INITIALIZATION
calc_statement(s)
BEGIN
calc_statement(s)
END;
Where calc_statement is a math calculation statement, in C++ C syntax
with optional conditional IF THEN ELSE ENDIF constructions. The
supported calc operators are: + - * / > < >= <= = and <>. For example:
Example
INITIALIZATION
speed = 0;
BEGIN
IF position > 50 THEN
speed = 3.5;
ELSE
speed = speed + 2;
END IF;
END;
The statements between INITIALIZATION and BEGIN defines how to
initialize the segment at startup or requested by user. The statements
between BEGIN and END define the run calculation of this segment. Every
time GAF runs this segment, it goes through all statements defined then
evaluates all fuzzy rules.
Declare Preset: preset_declaration
Just like the initialization declaration, a preset declaration is a
sequence of assignments to setup the segment to a known state.
Normally this is done by assigning values (constants) to local and output
variables. There is no limit of the number of presets in a segment.
Presets are used for genetic adapt for testing new rules' result. They
also can be requested by user during simulation and check modes. Please
refer to INITIALIZATION for format.
Example
PRESET
Reference = 100;
Position = 0;
END ;
Define Rule: rule_declaration
FCL uses IF THEN construct to define a fuzzy rule. The IF statement
contains multiple fuzzy evaluations bound with AND or OR. The format of
fuzzy evaluation is defined as:
variable IS symbol
which describes "What is the truth value of the current value of
'variable' in the fuzzy membership set 'symbol'?". The result of the
evaluation will be the truth value between 0 and 1 as described in the
symbol_declaration. The overall result of the IF statement will be the
fuzzy AND/OR result (min/max of all truth values).
The THEN statement contains only one fuzzy induction. The format of a
fuzzy induction is one of these forms:
variable IS symbol
variable + symbol
variable - symbol
The variable must be an OUT, INOUT, or LOCAL variable. The first format
simply defines the result of 'variable' is the 'symbol' fuzzy membership
set with the max truth be the overall result from the IF statement. The
second and third format is to increment/decrement the current 'variable'
by the amount defined by 'symbol'.
Example
SEGMENT main_control
CYCLE_TIME 0.1
IN Reference (0, 100)
IN Speed (-1, 1)
OUT Result (0, 10)
LOCAL Temp (-1, 1)
SYMBOL small OF Reference (0, 0, 10, 20, 1.0)
SYMBOL slow OF Speed (0, 1, 2, 3, 1)
SYMBOL strong (8, 9, 10, 10, 1, 10)
IF Reference IS small AND Speed IS slow
THEN Result IS strong
. . . .
END main_control;
A rule can be repeated more than once in a segment to intensify the
effect of the rule.