User Defined Variables in the Optimisation Shell INVERSE
(for Version 3.11)
Igor Grešovnik
Ljubljana, 27 September, 2005
5.1.1.1 How
this Chapter is Organised
5.2 Important Note: Naming Recommendations
5.3 Basic Concepts of User-defined Variables
5.3.1.1 Addressing
Variable Elements
5.3.1.2 Addressing Variables
and Variable Element Sub-tables
5.3.1.3 Addressing Variables Using String Objects
5.3.1.4 Operations on Variable Sub-tables
5.4 Basic Operations on User-defined Variables
5.5 Variables with Local Definition Scope
5.5.1 Definition
of Local Scopes
5.5.2 deflocvar { varname1 varname2 … }
5.6 Special
Expression Evaluator's Functions varindex and varcomponent
5.7.1 File
Interpreter’s Functions for Manipulation of Matrix Variables
5.7.1.1 newmatrix { varname < [ dim1, dim2, ... ] > }
5.7.1.2 dimmatrix { varname < [ dim1, dim2, ... ] > }
5.7.1.3 setmatrix { elspec
matspec }
5.7.1.4 initmatrix { subspec
matspec }
5.7.1.5 copymatrixvar { varname1 varname2 }
5.7.1.6 movematrixvar { varname1 varname2 }
5.7.1.7 deletematrixvar { varname }
5.7.1.8 printmatrixvar { varname
}
5.7.1.9 fprintmatrixvar { varname
}
5.7.1.10 dprintmatrixvar { varname
}
5.7.1.11 copymatrix { subspec1 subspec2 }
5.7.1.12 movematrix { subspec1 subspec2 }
5.7.1.13 deletematrix { subspec }
5.7.1.14 printmatrix { subspec }
5.7.1.15 fprintmatrix { subspec }
5.7.1.16 dprintmatrix { subspec }
5.7.1.17 setmatrixcomponents { subspec
expr }, shortly setmatcomp_
5.7.1.18 setmatcompcond { subspec (cond) expr }
5.7.1.19 matrixsum { subspec1 subspec2 subspecres }
5.7.1.20 matrixdif { subspec1 subspec2 subspecres }
5.7.1.21 matrixop { spec = < operator > spec <
operator spec > }, matop
5.7.2 Expression
Evaluator’s Functions for Manipulating Matrix Variables
5.7.2.1 getmatrix [ varname rownum colnum <
elind1, elind2, ... > ]
5.7.2.2 getmatrixdim [ varname dimnum ]
5.8.1 File
Interpreter’s Functions for Manipulating Vector Variables
5.8.1.1 newvector { varname < [ dim1, dim2, ... ] > }
5.8.1.2 dimvector { varname < [ dim1, dim2, ... ] > }
5.8.1.3 setvector { elspec
vecspec }
5.8.1.4 initvector { subspec
vecspec }
5.8.1.5 copyvectorvar { varname1 varname2 }
5.8.1.6 movevectorvar { varname1 varname2 }
5.8.1.7 deletevectorvar { varname }
5.8.1.8 printvectorvar { varname
}
5.8.1.9 fprintvectorvar { varname
}
5.8.1.10 dprintvectorvar { varname
}
5.8.1.11 copyvector { subspec1 subspec2 }
5.8.1.12 movevector { subspec1 subspec2 }
5.8.1.13 deletevector { subspec }
5.8.1.14 printvector { subspec }
5.8.1.15 fprintvector { subspec }
5.8.1.16 dprintvector { subspec }
5.8.1.17 setvectorcomponents { subspec
expr }, shortly setveccomp_
5.8.1.18 setveccompcond { subspec (cond) expr }
5.8.1.19 vectorsum { subspec1 subspec2 subspecres }
5.8.1.20 vectordif { subspec1 subspec2 subspecres }
5.8.2 Expression
Evaluator’s Functions for Manipulating Vector Variables
5.8.2.1 getvector [ varname compnum <
elind1, elind2, ... > ]
5.8.2.2 getvectordim [ varname dimnum ]
5.9.1 File
Interpreter’s Functions for Manipulating Scalar Variables
5.9.1.1 newscalar { varname < [ dim1, dim2, ... ] > }
5.9.1.2 dimscalar { varname < [ dim1, dim2, ... ] > }
5.9.1.3 setscalar { elspec
scalspec }
5.9.1.4 initscalar { subspec
scalspec }
5.9.1.5 copyscalarvar { varname1 varname2 }
5.9.1.6 movescalarvar { varname1 varname2 }
5.9.1.7 deletescalarvar { varname }
5.9.1.8 printscalarvar { varname
}
5.9.1.9 fprintscalarvar { varname
}
5.9.1.10 dprintscalarvar { varname
}
5.9.1.11 copyscalar { subspec1 subspec2 }
5.9.1.12 movescalar { subspec1 subspec2 }
5.9.1.13 deletescalar { subspec }
5.9.1.14 printscalar { subspec }
5.9.1.15 fprintscalar { subspec }
5.9.1.16 dprintscalar { subspec }
5.9.1.17 setscalarcomponents { subspec
expr }, shortly setscalcomp_
5.9.1.18 setscalcompcond { subspec (cond) expr }
5.9.1.19 scalarsum { subspec1 subspec2 subspecres }
5.9.1.20 scalardif { subspec1 subspec2 subspecres }
5.9.2 Expression
Evaluator’s Functions for Manipulating Scalar Variables
5.9.2.1 getscalar [ varname < elind1, elind2, ...
> ]
5.9.2.2 getscalardim [ varname dimnum ]
5.10.1 File
Interpreter’s Functions for Manipulating Field Variables
5.10.1.1 newfield { varname < [ dim1, dim2, ... ] > }
5.10.1.2 dimfield { varname < [ dim1, dim2, ... ] > }
5.10.1.3 setfield { elspec fieldspec }
5.10.1.4 initfield
{subspec fieldspec }
5.10.1.5 copyfieldvar
{varname1 varname2}
5.10.1.6 movefieldvar
{ varname1 varname2 }
5.10.1.7 deletefieldvar
{ varname }
5.10.1.8 printfieldvar
{ varname }
5.10.1.9 fprintfieldvar
{ varname }
5.10.1.10 copyfield
{ subspec1 subspec2 }
5.10.1.11 movefield
{ subspec1 subspec2 }
5.10.1.12 deletefield
{ subspec }
5.10.1.13 printfield
{ subspec }
5.10.1.14 fprintfield
{ subspec }
5.10.1.15 setfieldcomponents
{ subspec expr }
5.10.1.16 setfldcompcond
{ subspec (cond) expr }
5.10.2 Expression
Evaluator's Functions for manipulating Field Variables
5.10.2.1 getfield
{varname <elind1, elind2,...>
rownum colnum }
5.10.2.2 getfielddim
{varname dimnum }
5.11.1 File
Interpreter’s Functions for Manipulating Counter Variables
5.11.1.1 newcounter { varname < [ dim1, dim2, ... ] > }
5.11.1.2 dimcounter { varname < [ dim1, dim2, ... ] > }
5.11.1.3 setcounter { elspec
countspec }
5.11.1.4 initcounter { subspec
countspec }
5.11.1.5 copycountervar { varname1 varname2 }
5.11.1.6 movecountervar { varname1 varname2 }
5.11.1.7 deletecountervar { varname }
5.11.1.8 printcountervar { varname
}
5.11.1.9 fprintcountervar { varname
}
5.11.1.10 dprintcountervar { varname
}
5.11.1.11 copycounter { subspec1 subspec2 }
5.11.1.12 movecounter { subspec1 subspec2 }
5.11.1.13 deletecounter { subspec }
5.11.1.14 printcounter { subspec }
5.11.1.15 fprintcounter { subspec }
5.11.1.16 dprintcounter { subspec }
5.11.1.17 setcountercomponents { subspec
expr }, shortly setcountcomp
5.11.1.18 setcountcompcond { subspec (cond) expr }
5.11.1.19 countersum { subspec1 subspec2 subspecres }
5.11.2 Expression
Evaluator’s Functions for Manipulating Counter Variables
5.11.2.1 getcounter [ varname < elind1, elind2, ...
> ]
5.11.2.2 getcounterdim [ varname dimnum ]
5.12.1 File
Interpreter’s Functions for Handling Options
5.12.1.1 setoption { optspec }
5.12.1.2 clearoption { optspec }
5.12.2 Expression
Evaluator’s Functions for Handling Options
5.12.2.1 getoption [ varname < elind1, elind2, ...
> ]
5.13.1.1 setoption { optspec }
5.13.1.2 clearoption { optspec }
5.14.1 File
Interpreter Functions for Manipulating String Variables
5.14.1.1 newstring { varname < [ dim1, dim2, ... ] > }
5.14.1.2 dimstring { varname < [ dim1, dim2, ... ] > }
5.14.1.3 setstring { elspec
strspec }
5.14.1.4 initstring { subspec
strspec }
5.14.1.5 copystringvar { varname1 varname2 }
5.14.1.6 movestringvar { varname1 varname2 }
5.14.1.7 deletestringvar { varname }
5.14.1.8 printstringvar { varname
}
5.14.1.9 fprintstringvar { varname
}
5.14.1.10 dprintstringvar { varname
}
5.14.1.11 copystring { subspec1 subspec2 }
5.14.1.12 movestring { subspec1 subspec2 }
5.14.1.13 deletestring { subspec }
5.14.1.14 printstring { subspec }
5.14.1.15 fprintstring { subspec }
5.14.1.16 dprintstring { subspec }
5.14.1.17 printstring0 { elspec }
5.14.1.18 fprintstring0 { elspec }
5.14.1.19 fileprintstring0 { filespec elspec }
5.14.1.20 setstringcomponents { subspec
expr }, shortly setstrcomp_
5.14.1.21 setstrcompcond { subspec (cond) expr }
5.14.1.22 stringcat {
subspec1 subspec2 subspec3 }
5.14.1.23 copystringpart
{ subspec1 subspec2 from to }
5.14.1.24 stringwrite
{ elspec arg1 arg2 arg3 … }
5.14.1.25 stringappend
{ elspec arg1 arg2 arg3 … }
5.14.1.26 numtostring
{ elspec num < numdigits > }
5.14.1.27 appendnumtostring { elspec num < numdigits > }
5.14.1.28 stringtonum
{ elspec varname }
5.14.2 Expression
Evaluator Functions for Manipulating String Variables
5.14.2.1 getstring [ varname which < elind1, elind2, ...
> ]
5.14.2.2 getstringdim [ varname dimnum ]
5.15.1 File
Interpreter’s Functions for Manipulating File Variables
5.15.1.1 newfile { varname < [ dim1, dim2, ... ] > }
5.15.1.2 dimfile { varname < [ dim1, dim2, ... ] > }
5.15.1.3 setfile { elspec
filespec }
5.15.1.4 copyfilevar { varname1 varname2 }
5.15.1.5 movefilevar { varname1 varname2 }
5.15.1.6 deletefilevar { varname }
5.15.1.7 printfilevar { varname
}
5.15.1.8 fprintfilevar { varname
}
5.15.1.9 dprintfilevar { varname
}
5.15.1.10 copyfile { subspec1 subspec2 }
5.15.1.11 movefile { subspec1 subspec2 }
5.15.1.12 deletefile { subspec }
5.15.1.13 closefile { subspec }
5.15.1.14 flushfile { subspec }
5.15.1.15 printfile { subspec }
5.15.1.16 fprintfile { subspec }
5.15.1.17 dprintfile { subspec }
5.15.2 Expression
Evaluator’s Functions for Manipulating File Variables
5.15.2.1 getfile [ varname dataid < elind1, elind2, ...
> ]
5.15.2.2 getfiledim [ varname dimnum ]
5.16 Shell Variables with a Pre-defined Meaning
5.16.1 Pre-defined
Matrix, Vector and Scalar Variables
5.16.1.1 Counter Pre-defined variables
5.16.1.2 Scalar
Pre-defined Variables
5.16.1.3 Vector
Pre-defined Variables
5.16.1.4 Matrix
Pre-defined Variables
5.16.2.2 setnumobjectives { val }
5.16.2.3 setnumconstraints { val }
5.16.3.3 getnumconstraints [ ]
5.16.4 Pre-defined
File Variables
5.16.4.1 File
Pre-defined Variables
User-defined variables are used to store different types of data in the shell. Results of various operations and algorithms can be stored in these variables for further use in the solution procedure.
Another important use of user-defined variables is for transferring data between different modules, operations and algorithms of the shell. A typical example of that is passing data between optimisation algorithms and the function which performs direct analyses. Variables with a pre-defined meaning are used for this task.
Variable types that are currently implemented in the shell are scalar, vector, matrix, file and field.
In the first sub-chapter some basic concepts of user-defined variables and functions for variable manipulation are explained. Understanding these concepts can help the user to understand the behaviour of the supporting interpreter’s and calculator’s functions. However, it is not absolutely necessary to read through this chapter to comprehend the next ones. Therefore if you find the chapter boring and dry, simply skip it. You can return back later when you will have some insight about what everything is about, or when you feel the need for clearing some conceptual things.
The first part of the first sub-chapter explains what user-defined variables of the shell actually are. The second part offers somehow more practical information about how to address parts of the data stored in user-defined variables in the argument blocks of the user-defined functions. The third part explains the concepts of operations which affect groups of data objects of a given type. Storing groups of objects in a single variable and performing operations on them is a strong feature of the shell. An experienced user can easily take the advantage of this feature.
In the second sub-chapter a rough overview over the basic functions for variable manipulation is made. The examples refer to matrix variables, but similar functions exist for most of the variable types. The user is advised to read this sub-chapter to get a compact view on the subject.
The third sub-chapter describes the functions which enable an advanced way of setting components of the variables. The chapter is in that place because the described functions are used for several variable types. The user is advised to skip the chapter and return to it when needed.
The following sub-chapters include description of functions for handling of different types of variables. The first of these sub-chapters is dedicated to matrix variables. Many things described here are similar for other variable types. Especially the treatment of vector, scalar and field variables is in many terms the same. The user can therefore take this as an representative example which can ease the introduction to the treatment of other variable types. In many cases it will happen, for example, that the user will not need to read a description of a specific function for vector manipulation if he is already familiar with the appropriate function for matrix manipulation.
The last sub-chapter is dedicated to variables with a pre-defined meaning. These variables provide the necessary data links between different modules and operations of the shell. They are of great importance for setting optimisation and inverse problems.
Finally, let me conclude with a useful hint. Maybe it is not bad at all to start at the chapter about matrix variables. At least you will quickly get a feeling about which information you miss to get a clear insight. Have a nice reading!
Although it is currently possible to name two variables of different types by the same name, this should be avoided in Inverse command files. The variable system will undergo substantial changes in the future, and backward compatibility will only be provided for scripts that follow this recommendation. Beside that, variable names should be restricted to those which can be used in C and other language. Names should consist of alphabetic characters (‘A’ to ‘Z’ and ‘a’ to ‘z’), underscores (‘_’) and digits (‘0’ to ‘9’) and should begin either by an alphabetic character or an underscore.
Each type of the shell’s user-defined variables has its own set of file interpreter’s and expression evaluator’s functions for manipulating variables of that type. Basic manipulation includes creating, copying, renaming and deleting variables. Beside that, for each type of variables there exists a specific set of operations typical for that type, i.e. algebraic operations and setting or obtaining components for vector and matrix variables.
Each user-defined
variable can hold a multi-dimensional table of elements of a specific data
type. Number of dimensions of this table is called rank of a variable.
Variable’s element tables can be thought of as a recursive tables, where the
basic level holds a specific number of sub-tables, each of which again holds a
number of sub-tables, etc., until the last level which holds a table of
elements of a specific type. Numbers of sub-tables or element which level holds
are called variable dimensions,
and the umber of levels (or
dimensions) of a variable is called variable rank. Variables with rank 0
can hold only one element. Variables with rank greater than 0 can hold as many
data elements as is the product of variable dimensions.
Example:
Suppose we have a vector variable v
with rank 3 and dimensions 2, 3 and 2. The variable can hold 3*2*2=12 elements
which are organised in the following way:
Table v: contains 3 sub-tables (because
the first dimension is )
Sub-table v[1]: contains 2 sub-tables (because
the second dimension is 2)
Sub-table v[1,1]: contains 2 elements (because the third
dimension is 2)
Element v[1,1,1]
Element v[1,1,2]
Sub-table v[1,2]: contains 2 elements (because the third dimension is
2)
Element v[1,2,1]
Element v[1,2,2]
Sub-table v[2]: contains 2 sub-tables (because
the second dimension is 2)
Sub-table v[2,1]: contains 2 elements (because the third
dimension is 2)
Element v[2,1,1]
Element v[2,1,2]
Sub-table v[2,2]: contains 2 elements (because the third dimension is
2)
Element v[2,2,1]
Element v[2,2,2]
Sub-table v[3]: contains 2 sub-tables (because
the second dimension is 2)
Sub-table v[3,1]: contains 2 elements (because the third
dimension is 2)
Element v[3,1,1]
Element v[3,1,2]
Sub-table v[3,2]: contains 2 elements (because the third dimension is
2)
Element v[3,2,1]
Element v[3,2,2]
The variable v containd three sub-tables, each of
which contains two sub-sub tables, each of which contains two vectors. Variable
lazout is also shwn in Table 1.
Table 1: Variable v with dimensions
3*2*2.
In the case of variables that hold elements which themselves contain tables
of elements, e.g. vectors and matrices, the same variable can contain elements
of different dimensions. Exept at variables with a pre-defined meaning, it is
completely upon user's will which are the dimensions of elements stored in a
specific variable. However, this freedom is seldomly used because it decreases
the level of organisation.
In the case of multi-dimensional tables, each sub-table of the same level holds the same number of sub-tables or elements, which equals the dimension of that level. Of course, some elements can contain no data.
In the above
example, the first level (i.e. the variable itself) contains three sub-tables
of the second level (because the first dimension is 3), i.e. v[1], v[2] and v[3]. Each of these contains two sub-tables of the third level (because the second dimension is 2), i.e. v[1] contains v[1,1] and v[1,2], v[2] contains v[2,1] and v[2,2] and v[3] contains v[3,1] and v[3,2]. And each of these sub-tables of the third level contains
two elements because the third dimension is 2.
Special conventions exist about referencing shell’s user-defined variables and their elements in the argument blocks o