Combining matrices and attribute vectors during the procedure sequence run

The procedure Combination of matrices and vectors offers extensive possibilities for the recalculation of individual or multiple matrices. In particular, you can perform similar operations on multiple matrices in a single procedural step. You can also use the given examples for the selection of matrices by properties in many other procedures which use matrices.

1.  On the toolbar, click the  Open 'Procedure sequence' window button.

The Procedure sequence window opens.

2.  In the procedure sequence, at the position of your choice, add the Combination of matrices and vectors procedure of the Matrices category (Setting up and starting the procedure sequence).

3.  In the row of the inserted procedure, click the button in the Reference object(s) column.

The Edit formula for matrix window appears.

4.  Make the desired changes (Creating a matrix calculated from a formula).

Note: You can find examples of applications for the procedure in attachment.

5.  Confirm with OK.

The selected matrix is listed in the Reference object(s) column.

6.  Execute the procedure (Executing procedures in the procedure sequence).

The combination is calculated. The result is saved to the result matrix selected.

Through the procedure, you can calculate a single or multiple matrices.

In the editing field, set both the result matrix (-matrices) itself and the settings for calculating it. Results and calculation instructions are separated by the assignment symbol :=.

Tip: There are several keyboard shortcuts that make it easier for you to work in the formula editor (Key combinations in the formula editor for formula attributes and formula matrices).

Example with result matrix and calculation instruction

Matrix(1):= Matrix(2) + Matrix(3)

The selection of the matrices can be performed alternatively on the matrix number through the properties. For this the following notation is used.

Matrix([Attribute1] = Attribute value1 & [Attribute2] = Attribute value 2 & …)

Attributes are specified with the unique attribute name in square brackets (ID). The attribute ID which is interpreted is case-insensitive.

Except for the combination of attributes by & (And) a combination is alternatively possible through | (logical Or). In addition, the equality of an attribute value can be replaced by other operators, such as !=, >, <. A restriction to specific attribute values consisting of strings is possible by using the keyword IN. The set of attribute values is put in curly brackets and separated by a comma.

Examples for the selection of matrices by properties

Matrix according to properties

Return value

Matrix([NO] = 1)

Returns the matrix with the no. 1.

Matrix(1) is available as an abbreviated form for Matrix([No] = 1).

Matrix([NAME] = "Car")

Returns all matrices with the same Car.

Matrix([CODE] = "TTC" & [DSEGCODE] = "C")

Returns all matrices with the code TTC and demand segment code C.

Matrix([CODE] = "TWT" | [CODE] = "IVT" & [DSEGCODE] = "PT")

Returns all matrices with the code TWT or IVT and demand segment code PT.

Matrix([CODE] IN {"TWT", "IVT"} & [DSEGCODE] = "PT")

Returns all matrices with the code "TWT or "IVT" and the demand segment code "PT"

Matrix([DSEGCODE] IN {“PT“, ““} )

Returns all matrices of which the demand segment code is either PT or empty

Matrix([DSEGCODE] != "" )

Returns all matrices with a non-empty demand segment code.

Matrix([DMODELCODE] = “M01“ & [DSTRATCODE] = “HWc“ & [MODECODE] = "")

All matrices whose demand model code is M01, demand stratum code is HWc and mode code is empty.

Note: Make sure that the matrices used are unambiguously defined by the properties. To do this it may be necessary that attribute values are empty.

Matrix attributes with a limited number of possible values are represented by numbers. The following table contains those matrix attributes with a restricted number of variants which are displayed as numbers in formulas:

Attribute ID

Expression

MATRIXTYPE

1 = external

3 = demand

4 = skim

OBJECTTYPEREF

1 = no network reference

2 = zone

3 = main zone

4 = stop area

DATASOURCETYPE

1 = Data

2 = Formula

You can make all entries directly in the input field or use the buttons to select the operands, operators, functions, loops and brackets. However, some keywords and the assignment symbol := are available only via direct entry in the Edit field.

Key word Description

:=

results from

allocating a calculation instruction (right side of the term) to one or more results matrices (left side of the term)

IN{}

included in

Definition of a quantity of strings whose elements are separated by commas and enclosed by curly brackets.

Context

Use of matrices for multiple editing

For example, in the demand procedure, the dependence on the specific network object (e.g. person group, mode) is generated by the keyword Context and matrix attributes of the input and output matrices are interpreted accordingly.

With multiple editing of matrices in the procedure for combining matrices and vectors (ForEach), the keyword Contextis permitted on the right side of the assignment symbol. Contextdesignates the matrix, which is to be allocated to, and it is therefore on the left-hand side of the assignment symbol. In the calculation formula, attributes of the target matrix can be accessed even if they are not explicitly defined on the right-hand side.

MatrixList()

allows an operation with multiple matrices whose properties are set within round brackets

Sum, Min, Max, Average, Product

Matrix combination functions that, among other things, can be used in conjunction with MatrixList(). Combination functions work element by element.

Examples for calculating individual matrices and user matrix properties

Matrix([CODE] = “C“ & [NAME] = “CAR“ & [DSEGCODE] = “C“) :=

Matrix([CODE] = “privC“ & [NAME] = “private CAR“) +

Matrix([CODE] = “busC“ & [NAME] = “business CAR“)

Both matrices on the right-hand side of the assignment symbol := must be uniquely defined by the CODE and NAME attributes. If the matrix on the left-hand side is created, a matrix should exist with the properties not yet on the network. If the matrix with the properties already exists, the values are overwritten.

Matrix([CODE]="TripDistImpedance" & [NAME]="TripDistImpedance" & [MATRIXTYPE]=4)

:= Matrix([CODE]="TTC" & [DSEGCODE]="C" & [MATRIXTYPE]=4)

To calculate the matrix with the code and name “TripDistImpedance” a skim matrix "TTC“ must be calculated in advance for the demand segment C.

Examples of formulas with the operation MatrixList and matrix combination functions

Matrix(9): = Sum (MatrixList([DSEGCODE] = "C" | [DSEGCODE] = "H"))

The sum of all matrices whose demand segment code is C or H is stored in matrix 9.

Matrix([NAME]="Min JRT") := 0.5*Min(MatrixList([CODE]="JRT" & [DSEGCODE] in {"PuT", "PuT2"}))

For each element, the minimum of the PuT skim matrices for the journey time of demand segments PuT and PuT2 is calculated and multiplied by 0.5. The result is saved to the Min JRT matrix.

Example: Formulas with functions
Operation Matrix formula

Logarithm

Matrix(<Number>) := Ln(Matrix(<Number>))

Exponential function

Matrix(<Number>) := Exp(Matrix(<Number>))

Reciprocal

Matrix(<Number>) := Reciprocal(Matrix(<Number>))

Transpose

Matrix(<Number>) := Transpose(Matrix(<Number>))

Reflect upper triangle

Matrix(<Number>) := Mirror_Upper(Matrix(<Number>))

Reflect lower triangle

Matrix(<Number>) := Mirror_Lower(Matrix(<Number>))

Make symmetrical

Matrix(<Number>) := Symmetrize(Matrix(<Number>))

Examples with ForEach
  • Example 1 Skim matrices average

In a model, skim matrices should be average from iterations following on from one another. For this:

  • Skim matrices are calculated initially
  • Skim matrices are duplicated, whereby a user-defined attribute (UDA) with the ID "S type" is set to the value avg
  • Is averaged within the loop

Skim matrices are uniquely identified by the combination of code, "skim matrix" matrix type and demand segment code. To execute the calculate shown below, the "S type" UDA must be defined in the model. The value is empty for the skim matrices calculated at the beginning. Steps two and three can be carried out by a ForEach loop across all the skim matrices in each of the procedure steps.

ForEach (MATRIX M, M[S-TYPE]= "" & M[MATRIXTYPE]=4)

Matrix([CODE] = M[CODE] & [MATRIXTYPE] = 4 & [S-TYPE] = "avg" & [NAME]

= M[NAME] & [DSEGCODE] = M[DSEGCODE]) := M

All skim matrices (S-TYPE = "" & MATRIXTYPE=4) are iterated and for each skim matrix, a new matrix is created. It only differs in the value of the UDA S-TYPE = "avg". On the right-hand side, a simplified form is used for the matrix formula. M stands for the skim matrix calculated at the beginning, across which it is currently iterated.

Averaging the skim matrices also occurs in one procedure step:

ForEach(MATRIX M, M[S-TYPE]= "" & M[MATRIXTYPE]=4)

Matrix([CODE] = M[CODE] & [MATRIXTYPE] = 4 & [S-TYP] = "avg" & [NAME]= M[NAME] & [DSEGCODE] = M[DSEGCODE]) := Matrix([CODE] = M[CODE] & [MATRIXTYPE] = 4 & [S-TYP] = "avg" & [NAME] = M[NAME] & [DSEGCODE] = M[DSEGCODE]) * 0.5 + Matrix([CODE] = M[CODE] & [MATRIXTYPE] = 4 & [S-TYP] = "" & [NAME] = M[NAME] & [DSEGCODE] = M[DSEGCODE]) * 0.5

On the left-hand side, the skim matrices with the UDA S-TYPE = "avg" are defined as target matrices. The matrix formula on the right-hand side depicts the product from the calculated skim (S-TYPE = "") and the value of the averaged matrix. The matrices are uniquely defined using the combination of properties.

  • Example 2 Generate or reset matrices in the procedure sequence

ForEach(MODE M, M[CODE] in {"Bus", "Tram"}) Matrix([DSEGCODE] = "PT" & [MODECODE] = M[CODE]) := 0

The iteration takes place over the Network object type Mode, for which the quantity is restricted by the condition to the modes "Bus" and "Tram". If result matrices are available with the defined properties, their values are set to null according to the calculation instructions on the right-hand side. If the matrices are not yet available, they are generated and defined with the attributes ModeCode and DSegCode:

Matrix([DSEGCODE] = "PT" & [DSEGCODE] = "Bus") or

Matrix([DSEGCODE] = "PT" & [DSEGCODE] = "Tram")

  • Example 3 Prevent generation of new matrices in the procedure sequence

ForEach (MODE M)

Matrix([DSEGCODE] = "PT" & [MODECODE] = M[CODE] | 0) := 0

This example essentially corresponds to example 2. The Add-on | 0 means that only existing matrices are changed and the generation of new matrices is suppressed.

  • Example 4 Restrict the calculation to specific objects

ForEach (DEMANDSTRATUM N, N[CODE] in {"A","B"} & N[DEMANDMODELCODE = "M01")

Matrix( [DEMANDSTRATUMCODE]=N[CODE]) := …

With this syntax, it is possible to restrict the calculation to demand strata of a demand model "M01". Iteration takes place over the set of demand strata "A" and "B".

  • Example 5 Use UDAs as coefficients

ForEach (DEMANDSTRATUM N)

Matrix([CODE] = "Utility" & [MODECODE] ="C" & [DMODELCODE] = "M01" & [DSTRATCODE] = CONTEXT[DSTRATCODE] & [MATRIXTYPE] = 4)

:= Matrix([CODE] = "TTC" & [MATRIXTYPE] = 4 & [DSEGCODE] = "C") • N[C_TTCCOEFF] + FROM[ACCESSTIMECAR] • N[C_ACCEGRCOEFF] + TO[EGRESSTIMECAR] • N[C_ACCEGRCOEFF] + N[C_CONST]

For each demand stratum a skim matrix (Matrix type = 4) is generated with the name "Utility". The matrix attributes for the code of the demand model "M01", the code of the mode "C" and the code of the demand stratum are defined for these result matrices. The code for the demand stratum is evaluated using the loop variables; all other attribute values are predefined. The calculation of the matrices multiplied by the skim matrix with the code “TTC“ by an attribute value dependent on the demand stratum of the user-defined attribute C_COEFF and adds a value that is also dependent on the demand stratum. C_COEFF and C_CONST are user-defined attributes of the demand stratum, which are accessed via the loop variable; this means that the values are evaluated on the basis of the demand stratum calculated.

  • Example 6 concatenated strings

ForEach (DEMANDSTRATUM N, N[DEMANDMODELCODE] = "M01")

Matrix([CODE] = "Utility" + "-Bike" & [MODECODE] ="Bike" & [DEMANDMODELCODE] = N[DEMANDMODELCODE] & [DEMANDSTRATUMCODE] = N[CODE] & [MATRIXTYPE] = 4)

:= Matrix([CODE] = "TT0" & [MATRIXTYPE] = 4 & [DSEGCODE] = "Bike") * N[BIKE_TT0COEFF] + N[BIKE_CONST]

Over all the demand strata of the demand model "M01", an iteration is carried out in which the loop variable N represents each demand stratum of the loop. For each demand stratum, a skim matrix is calculated for which the matrix attributes CODE, MODECODE, DEMANDMODELCODE and DEMANDSTRATUMCODE are set. As shown here for the value of CODE, strings can be concatenated using + when defining attribute values. The DEMANDSTRATUMCODE results from the CODE attribute of the demand stratum, over which the iteration currently occurs. The calculation defined using the matrix formula on the right-hand side, consists of the skim TT0 and values specific to the demand strata. For the last ones, it concerns the user-defined attributes BIKE_TT0COEFF and BIKE_CONST of the demand stratum.