xfsim

Section: User Commands (1)
Updated: 10 Sep 2001
Index
 

NAME

xfsim - build simulations for xfl-based fuzzy systems  

SYNOPSIS

xfsim [ -O opsfile ] [ -m | -p ] simfile  

DESCRIPTION

xfsim takes a description of a closed-loop system containing one (or more) xfl-based elements and produces a main C source file and a makefile ready to build, run and analyze a simulation of the behavior of this system.

The description of the system allows the definition of:

The variables describing the state of the system and their units and valid ranges.

The behavior of the system, expressed in terms of:

* Fuzzy inference engines derived from xfl.
* C functions.
* Data stored in files.

The output produced when running the simulation.

A set of options which control the building and execution of the simulation.

The result of running xfsim is (by default) a pair of files: A makefile, which (when executed throuhg "make -f") will produce the executable code for the closed-loop simulation, and a source file, written in C, containing the main function for the simulation code. The simulation is built using xfc(1) and the C compiler defined by the environment variable FSCCOMPILER (defaults to "cc" if this variable is not set)

Once built, the simulation code accepts the following arguments:

-d
run in debug mode. The program will sequentially print on stdout the message "^Iteration N", where N is the current iteration of the system loop. When the simulation is complete, it will print the message "^Finished at iteration N".
<num>|'-'
initial values for the system variables. These values can be assigned by calling the simulation executable with as many numerical arguments as variables have been defined. Assignment of values to variables is positional: the first argument is assigned to the first defined variable and so on. To skip the assignment to an specific variable, the numerical value must be substituted by a '-' character. Variables with no specific initial value take the default (the mean of the range assigned in the definition).

In case of any error, the simulation will end (with an exit code of -1) and print on stderr the appropriate message.  

OPTIONS

-O opsfile
Defines the operations file to be used when translating the xfl-based inference engines (see xfc(1) for more details).
-m
Only produce the simulation makefile.
-p
Only produce the simulation main module.
 

THE DEFINITION FILE

The file containing the simulation definition consists in four separate sections. The beginning of each section is marked with an specific keyword and the end with "%%". The format of each of these sections is as follows:  

The variables section

This section is introduced by the keyword "%variables". Each line in this section defines a variable of the closed-loop system and its format is:

name minvalue < maxvalue unit

Apart from these variables, xfsim defines two variables: _n, which holds the iteration index in the simulation, and _t, which holds the simulation time.  

The behavior section

This section is introduced by the keyword "%behaviour". Each line in this section defines a call to a procedure defining the behavior of the system. Procedures are called inside the system loop in the same order they are defined. The format of the procedure lines is:

class : path : call ( params ,...)

where:

class defines the type of procedure. Supported classes are:

fuzzy
An xfl-based fuzzy inference engine, derived from xfc(1).
c
A direct call to a C function.
raw
Values are directly read from a file. The file is assumed to contain lines with data values separated by blanks or tabs. Each time a raw "procedure" is called, a line of values is read and assigned (in positional order) to the variables included as parameters to the call. Lines starting with '#' are ignored.

path defines the source file pathname for the procedure. This parameter is optional for classes fuzzy and c. For the raw class it is mandatory (since it holds the data file pathname).

call defines the name to be used when calling the procedure inside the main simulation code. It is mandatory for classes fuzzy and c and is not used for raw.

params are the actual parameters passed to the procedure. Only variable names defined in the previous section can be used. Parameters are passed by reference (type (FUZZY *), see below), so any value can be changed inside a procedure.  

The output section

This section is introduced by the keyword "%output". Each line in this section defines the format of an output file for the system simulation. Currently, xfsim supports two classes of output modes: a raw output (compatible with the raw "procedure" described for the section above) and a gnuplot(1) compatible format. An output specification has the form:

class ( params ,...)

where:

class can be: file (for the raw output format), stdout (for using a raw format through standard output) or gnuplot (for the gnuplot-compatible format).

params are the variables used for output. Only defined variable identifiers can be used.  

The options section

This section is introduced by the keyword "%options". Each line in this section contains a keyword identifying an option for the building and execution of the simulation. The rest of the line defines the value of the corresponding option. The settings defined in a line override any other settings for the same option in previous lines. Available options keywords are:
$fuzzytype
Defines the type for the variables describing the system. Any valid C type identifier can be used as value, since the value of this option is used in a "typedef FUZZY fuzzytype-value" construct. The default value is "double".
$name
Defines the name for the simulation executable (and the main module, which has the same name with a ".c" suffix). Any valid file name can be used as value. The default is simfile.sim
$makefile
Defines the name for the simulation makefile. Any valid file name can be used as value. The default is simfile.mkf
$cclibpath
Defines the list of directories used when searching for libraries in the linking stage of the makefile (the -L option of the C compiler). The separator for the different elements in the list is the character ':'. By default, it takes the value of the environment variable FSLIBPATH (empty if not set).
$ccincpath
Defines the list of directories used when searching for include files in the compilations made by the makefile (the -I option of the C compiler). The separator for the different elements in the list is the character ':'. By default, it takes the value of the environment variable FSINCPATH (empty if not set).
$cclibs
Defines the libraries to be linked with the simulation executable. The value for this option is of the form: -llib1 -llib2... (as used by the linking command in the makefile). By default, it takes the value of the environment variable FSLIBS (empty if not set).
$ccopts
Defines the options to be passed to the C compiler in all the stages of the simulation building process. Any valid combinations of options accepted by the C compiler can be used. By default, it takes the value of the environment variable FSCCOPS (empty if not set).
$outpfx
Defines a prefix for the output files. This prefix is combined with the variable identifiers, the ouput class identifier and the simulation PID to produce the actual pathname for the output files in each execution. Any valid path component can be used. The default value is simfile.
$startviewers
Selects whether, upon the end of the simulation loop, the viewers defined for each output class must be started on each output file. Can take the values 'y' (the default) or 'n'.
The viewers (as defined in the distribution) are: vi(1) (running in xterm(1)) for raw files, and, for gnuplot, an instance of this program controlled by a specific xterm.
$keepfiles
Selects whether output files are to be kept or are written to a system scratch area (defined by the environment variable FSTMPDIR or "/tmp" if not set). Can take the values 'y' (the default) or 'n'.
$simtic
Defines the simulation tic, i.e., the amount of simulated time corresponding to each iteration of the main loop. Any valid positive real value can be used. The default value is 1.
$timeunit
Defines the unit for the simulation time. Since it is only used for informational purposes in the output files, any string can be used. The default value is "s".
$simwhile
Defines the end condition for the simulation. Any valid C expression returning an integer value and using simulation variables can be used. This expression is used as the controlling condition for a "while" loop in the main module. The default value is "_n < 100".
 

The section for other source files

While the other sections in the definition file are mandatory (even when they are empty), this section is optional and lists any other source files needed to build the simulation executable. The section starts with the keyword "%othersrc" and each line must contain a valid pathname between double quotes. The usual C compiler conventions are used: source files with the ".c" suffix are compiled and the object produced is linked, while files without the suffix are directly passed to the linker.  

ENVIRONMENT

FSCCOMPILER
Defines the C compiler to be used for building the simulation executable. Defaults to "cc" if not set.
FSTMPDIR
Defines the directory to be used for temporary viewer files, if the $keepfiles option is not used inside the simulation file. Defaults to "/tmp" if not set.
FSCCLIBPATH
A colon separated list of directories defining additional places where look for libraries when building the simulation executable.
FSCCINCPATH
A colon separated list of directories defining additional places where look for include files when building the simulation executable.
FSCCLIBS
A list of libraries to be used for building the simulation executable. Libraries must be defined using the C compiler conventions. This is, to use the library libX.a the string "-lX" must be employed.
FSCCOPTS
A list of additional options to be pased to the C compiler when building the simulation executable.
 

FILES

libfrt.a
Runtime library used by the simulation code.
 

SEE ALSO

xfuzzy(1), xfc(1), xfplot(1)

A guide to xfl, Xfuzzy user guide


 

Index

NAME
SYNOPSIS
DESCRIPTION
OPTIONS
THE DEFINITION FILE
The variables section
The behavior section
The output section
The options section
The section for other source files
ENVIRONMENT
FILES
SEE ALSO