User Defined Variables in the Optimisation Shell INVERSE  

 

(for Version 3.11)

 

 

Igor Grešovnik

 

Ljubljana, 27 September, 2005

 


Contents:

 

5.     User-defined Variables 6

5.1.1.1        How this Chapter is Organised_ 1

5.2       Important Note: Naming Recommendations 2

5.3       Basic Concepts of User-defined Variables 2

5.3.1      Tables of Elements 2

5.3.1.1        Addressing Variable Elements 4

5.3.1.2        Addressing Variables and Variable Element Sub-tables 4

5.3.1.3        Addressing Variables Using String Objects 5

5.3.1.4        Operations on Variable Sub-tables 5

5.4       Basic Operations on User-defined Variables 8

5.5       Variables with Local Definition Scope_ 9

5.5.1      Definition of Local Scopes 10

5.5.2      deflocvar { varname1 varname2 … } 11

5.5.3      undeflocvar {  } 12

5.5.4      marklocvar {  } 12

5.5.5      checklocvar {  } 12

5.6       Special Expression Evaluator's Functions varindex and varcomponent 13

5.6.1      varindex [ indexnum ] 13

5.6.2      varcomponent [compnum ] 13

5.7       Matrix Variables 14

5.7.1      File Interpreter’s Functions for Manipulation of Matrix Variables 14

5.7.1.1        newmatrix { varname < [ dim1, dim2, ... ] > } 14

5.7.1.2        dimmatrix { varname < [ dim1, dim2, ... ] > } 15

5.7.1.3        setmatrix { elspec  matspec } 15

5.7.1.4        initmatrix { subspec  matspec } 17

5.7.1.5        copymatrixvar { varname1 varname2 } 17

5.7.1.6        movematrixvar { varname1 varname2 } 17

5.7.1.7        deletematrixvar { varname } 17

5.7.1.8        printmatrixvar { varname  } 17

5.7.1.9        fprintmatrixvar { varname  } 17

5.7.1.10      dprintmatrixvar { varname  } 18

5.7.1.11      copymatrix { subspec1 subspec2 } 18

5.7.1.12      movematrix { subspec1 subspec2 } 18

5.7.1.13      deletematrix { subspec } 18

5.7.1.14      printmatrix { subspec } 18

5.7.1.15      fprintmatrix { subspec } 18

5.7.1.16      dprintmatrix { subspec } 18

5.7.1.17      setmatrixcomponents { subspec  expr }, shortly setmatcomp_ 19

5.7.1.18      setmatcompcond { subspec (cond) expr } 19

5.7.1.19      matrixsum { subspec1 subspec2 subspecres  } 19

5.7.1.20      matrixdif { subspec1 subspec2 subspecres  } 20

5.7.1.21      matrixop { spec = < operator > spec < operator spec > }, matop_ 20

5.7.2      Expression Evaluator’s Functions for Manipulating Matrix Variables 21

5.7.2.1        getmatrix [ varname rownum colnum < elind1, elind2, ... > ] 21

5.7.2.2        getmatrixdim [ varname dimnum ] 22

5.8       Vector Variables 22

5.8.1      File Interpreter’s Functions for Manipulating Vector Variables 22

5.8.1.1        newvector { varname < [ dim1, dim2, ... ] > } 22

5.8.1.2        dimvector { varname < [ dim1, dim2, ... ] > } 22

5.8.1.3        setvector { elspec  vecspec } 22

5.8.1.4        initvector { subspec  vecspec } 24

5.8.1.5        copyvectorvar { varname1 varname2 } 24

5.8.1.6        movevectorvar { varname1 varname2 } 24

5.8.1.7        deletevectorvar { varname } 25

5.8.1.8        printvectorvar { varname  } 25

5.8.1.9        fprintvectorvar { varname  } 25

5.8.1.10      dprintvectorvar { varname  } 25

5.8.1.11      copyvector { subspec1 subspec2 } 25

5.8.1.12      movevector { subspec1 subspec2 } 25

5.8.1.13      deletevector { subspec } 25

5.8.1.14      printvector { subspec } 25

5.8.1.15      fprintvector { subspec } 25

5.8.1.16      dprintvector { subspec } 25

5.8.1.17      setvectorcomponents { subspec  expr }, shortly setveccomp_ 25

5.8.1.18      setveccompcond { subspec (cond) expr } 26

5.8.1.19      vectorsum { subspec1 subspec2 subspecres  } 26

5.8.1.20      vectordif { subspec1 subspec2 subspecres  } 26

5.8.2      Expression Evaluator’s Functions for Manipulating Vector Variables 26

5.8.2.1        getvector [ varname compnum < elind1, elind2, ... > ] 26

5.8.2.2        getvectordim [ varname dimnum ] 27

5.9       Scalar Variables 27

5.9.1      File Interpreter’s Functions for Manipulating Scalar Variables 27

5.9.1.1        newscalar { varname < [ dim1, dim2, ... ] > } 27

5.9.1.2        dimscalar { varname < [ dim1, dim2, ... ] > } 27

5.9.1.3        setscalar { elspec  scalspec } 27

5.9.1.4        initscalar { subspec  scalspec } 28

5.9.1.5        copyscalarvar { varname1 varname2 } 28

5.9.1.6        movescalarvar { varname1 varname2 } 28

5.9.1.7        deletescalarvar { varname } 28

5.9.1.8        printscalarvar { varname  } 28

5.9.1.9        fprintscalarvar { varname  } 28

5.9.1.10      dprintscalarvar { varname  } 28

5.9.1.11      copyscalar { subspec1 subspec2 } 28

5.9.1.12      movescalar { subspec1 subspec2 } 28

5.9.1.13      deletescalar { subspec } 28

5.9.1.14      printscalar { subspec } 28

5.9.1.15      fprintscalar { subspec } 28

5.9.1.16      dprintscalar { subspec } 28

5.9.1.17      setscalarcomponents { subspec  expr }, shortly setscalcomp_ 29

5.9.1.18      setscalcompcond { subspec (cond) expr } 29

5.9.1.19      scalarsum { subspec1 subspec2 subspecres  } 29

5.9.1.20      scalardif { subspec1 subspec2 subspecres  } 29

5.9.2      Expression Evaluator’s Functions for Manipulating Scalar Variables 30

5.9.2.1        getscalar [ varname < elind1, elind2, ... > ] 30

5.9.2.2        getscalardim [ varname dimnum ] 30

5.10     Field Variables 30

5.10.1         File Interpreter’s Functions for Manipulating Field Variables 30

5.10.1.1      newfield { varname < [ dim1, dim2, ... ] > } 30

5.10.1.2      dimfield { varname < [ dim1, dim2, ... ] > } 30

5.10.1.3      setfield { elspec fieldspec } 30

5.10.1.4      initfield {subspec fieldspec } 30

5.10.1.5      copyfieldvar {varname1 varname2} 30

5.10.1.6      movefieldvar { varname1 varname2 } 31

5.10.1.7      deletefieldvar { varname } 31

5.10.1.8      printfieldvar { varname } 31

5.10.1.9      fprintfieldvar { varname } 31

5.10.1.10         copyfield { subspec1 subspec2 } 31

5.10.1.11         movefield { subspec1 subspec2 } 31

5.10.1.12         deletefield { subspec } 31

5.10.1.13         printfield { subspec } 31

5.10.1.14         fprintfield { subspec } 31

5.10.1.15         setfieldcomponents { subspec expr } 31

5.10.1.16         setfldcompcond { subspec (cond) expr } 31

5.10.2         Expression Evaluator's Functions for manipulating Field Variables 31

5.10.2.1      getfield {varname <elind1, elind2,...> rownum colnum } 31

5.10.2.2      getfielddim {varname dimnum } 32

5.11     Counter Variables 32

5.11.1         File Interpreter’s Functions for Manipulating Counter Variables 32

5.11.1.1      newcounter { varname < [ dim1, dim2, ... ] > } 32

5.11.1.2      dimcounter { varname < [ dim1, dim2, ... ] > } 32

5.11.1.3      setcounter { elspec  countspec } 32

5.11.1.4      initcounter { subspec  countspec } 33

5.11.1.5      copycountervar { varname1 varname2 } 33

5.11.1.6      movecountervar { varname1 varname2 } 33

5.11.1.7      deletecountervar { varname } 33

5.11.1.8      printcountervar { varname  } 33

5.11.1.9      fprintcountervar { varname  } 33

5.11.1.10         dprintcountervar { varname  } 33

5.11.1.11         copycounter { subspec1 subspec2 } 33

5.11.1.12         movecounter { subspec1 subspec2 } 33

5.11.1.13         deletecounter { subspec } 33

5.11.1.14         printcounter { subspec } 33

5.11.1.15         fprintcounter { subspec } 33

5.11.1.16         dprintcounter { subspec } 33

5.11.1.17         setcountercomponents { subspec  expr }, shortly setcountcomp_ 34

5.11.1.18         setcountcompcond { subspec (cond) expr } 34

5.11.1.19         countersum { subspec1 subspec2 subspecres  } 34

5.11.2         Expression Evaluator’s Functions for Manipulating Counter Variables 35

5.11.2.1      getcounter [ varname < elind1, elind2, ... > ] 35

5.11.2.2      getcounterdim [ varname dimnum ] 35

5.12     Options 35

5.12.1         File Interpreter’s Functions for Handling Options 35

5.12.1.1      setoption { optspec } 35

5.12.1.2      clearoption { optspec } 36

5.12.2         Expression Evaluator’s Functions for Handling Options 36

5.12.2.1      getoption [ varname < elind1, elind2, ... > ] 36

5.13     Options 36

5.13.1.1      setoption { optspec } 36

5.13.1.2      clearoption { optspec } 36

5.14     String Variables 36

5.14.1         File Interpreter Functions for Manipulating String Variables 37

5.14.1.1      newstring { varname < [ dim1, dim2, ... ] > } 37

5.14.1.2      dimstring { varname < [ dim1, dim2, ... ] > } 37

5.14.1.3      setstring { elspec  strspec } 37

5.14.1.4      initstring { subspec  strspec } 37

5.14.1.5      copystringvar { varname1 varname2 } 37

5.14.1.6      movestringvar { varname1 varname2 } 38

5.14.1.7      deletestringvar { varname } 38

5.14.1.8      printstringvar { varname  } 38

5.14.1.9      fprintstringvar { varname  } 38

5.14.1.10         dprintstringvar { varname  } 38

5.14.1.11         copystring { subspec1 subspec2 } 38

5.14.1.12         movestring { subspec1 subspec2 } 38

5.14.1.13         deletestring { subspec } 38

5.14.1.14         printstring { subspec } 38

5.14.1.15         fprintstring { subspec } 38

5.14.1.16         dprintstring { subspec } 38

5.14.1.17       printstring0 { elspec } 38

5.14.1.18       fprintstring0 { elspec } 38

5.14.1.19       fileprintstring0 { filespec elspec } 39

5.14.1.20         setstringcomponents { subspec  expr }, shortly setstrcomp_ 39

5.14.1.21         setstrcompcond { subspec (cond) expr } 39

5.14.1.22         stringcat { subspec1 subspec2 subspec3 } 39

5.14.1.23         copystringpart { subspec1 subspec2 from to } 40

5.14.1.24         stringwrite { elspec arg1 arg2 arg3 … } 40

5.14.1.25         stringappend { elspec arg1 arg2 arg3 … } 40

5.14.1.26         numtostring { elspec num < numdigits > } 41

5.14.1.27         appendnumtostring { elspec num < numdigits > } 41

5.14.1.28         stringtonum { elspec varname } 41

5.14.2         Expression Evaluator Functions for Manipulating String Variables 42

5.14.2.1      getstring [ varname which < elind1, elind2, ... > ] 42

5.14.2.2      getstringdim [ varname dimnum ] 42

5.15     File Variables 42

5.15.1         File Interpreter’s Functions for Manipulating File Variables 42

5.15.1.1      newfile { varname < [ dim1, dim2, ... ] > } 42

5.15.1.2      dimfile { varname < [ dim1, dim2, ... ] > } 43

5.15.1.3      setfile { elspec  filespec } 43

5.15.1.4      copyfilevar { varname1 varname2 } 44

5.15.1.5      movefilevar { varname1 varname2 } 44

5.15.1.6      deletefilevar { varname } 44

5.15.1.7      printfilevar { varname  } 44

5.15.1.8      fprintfilevar { varname  } 44

5.15.1.9      dprintfilevar { varname  } 44

5.15.1.10         copyfile { subspec1 subspec2 } 44

5.15.1.11         movefile { subspec1 subspec2 } 44

5.15.1.12         deletefile { subspec } 45

5.15.1.13         closefile { subspec } 45

5.15.1.14         flushfile { subspec } 45

5.15.1.15         printfile { subspec } 45

5.15.1.16         fprintfile { subspec } 45

5.15.1.17         dprintfile { subspec } 45

5.15.2         Expression Evaluator’s Functions for Manipulating File Variables 45

5.15.2.1      getfile [ varname dataid < elind1, elind2, ... > ] 45

5.15.2.2      getfiledim [ varname dimnum ] 46

5.16     Shell Variables with a Pre-defined Meaning_ 46

5.16.1         Pre-defined Matrix, Vector and Scalar Variables 47

5.16.1.1      Counter Pre-defined variables 48

5.16.1.2      Scalar Pre-defined Variables 49

5.16.1.3      Vector Pre-defined Variables 49

5.16.1.4      Matrix Pre-defined Variables 50

5.16.2         File Interpreter’s Functions for Setting Shell’s Internal Data Related to Pre-defined Variables  50

5.16.2.1      setnumparam { val } 50

5.16.2.2      setnumobjectives { val } 51

5.16.2.3      setnumconstraints { val } 51

5.16.2.4      setnummeas { val } 51

5.16.3         Expression Evaluator’s Functions for Accessing Shell’s Internal Data Related to Pre-defined Variables  51

5.16.3.1      getnumparam [ ] 51

5.16.3.2      getnumobjectives [ ] 51

5.16.3.3      getnumconstraints [ ] 51

5.16.3.4      getnummeas [ ] 51

5.16.4         Pre-defined File Variables 51

5.16.4.1      File Pre-defined Variables 52

 

 

 


 

 

 

5.   User-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.

5.1.1.1     How this Chapter is Organised

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!

5.2      Important Note: Naming Recommendations

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.

5.3      Basic Concepts of User-defined Variables

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.

5.3.1    Tables of Elements

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.

Level 1:

variable v

 

 

 

 

 

Level 2:

v[1]

 

v[2]

 

v[3]

 

Level 3:

v[1,1]

v[1,2]

v[2,1]

v[2,2]

v[3,1]

v[3,2]

Elements:

v[1,1,1]

v[1,1,2]

v[1,2,1]

v[1,2,2]

v[2,1,1]

v[2,1,2]

v[2,2,1]

v[2,2,2]

v[3,1,1]

v[3,1,1,2]

v[3,2,1]

v[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.

5.3.1.1     Addressing Variable Elements

Special conventions exist about referencing shell’s user-defined variables and their elements in the argument blocks o