Creating a matrix calculated from a formula

You can create a Visum matrix that is calculated from other Visum matrices or zone, main zone or stop area attributes. This formula matrix is automatically recalculated if one of its operands changes.

You are supported by Visum in formal generation of the formula. The syntax is checked on entry and errors are highlighted in color.

The following formula matrices are special cases of matrices which you can calculate through the procedures provided:

  • Total demand matrices
  • Assignment matrix
  • OD pair filter assignment matrices
  • Flow bundle matrices

You can allow assignment and flow bundle matrices to be created automatically by selecting the relevant options in the general procedure settings (Saving flow bundle matrices and assignment matrices automatically as formula matrices)

Notes: You cannot change the values in formula matrices.

If you delete matrices or attributes that are used to calculate a formula matrix, the formula matrix is also deleted.

1.  In the Matrices window, on the toolbar, click the  Create matrices icon.

The Create matrices window opens.

Tip: Alternatively, in the Matrices window, you can right-click in the navigator and select Create matrices from the shortcut menu or select Create from menu Edit > Matrices. The symbol and the shortcut menu entry are both provided in the Matrices list (Opening a list).

2.  Select the Matrix attributes tab.

3.  In the Data source type section, select the Formula matrix option.

4.  Click the Edit formula button.

The Edit formula for matrix <number> window opens.

5.  Into the text box, enter the desired formula for calculation, or click the buttons next to the text box to create a formula.

Notes: You can copy and paste the formula from another formula matrix to use it.

Make sure that your formula does not contain a direct or indirect circular reference. You should also avoid references between output values and input values of the same procedure step in the procedure sequence because they can lead to undesired calculation results.

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).

Element

Description

Click the button to select operands for the formula matrix. The options available depend on the context in which you are creating a formula matrix.

Select matrix directly

If the option is selected you can select a matrix in the Navigator according to your number.

Select matrix by properties

If the option is selected, you can select a matrix according to specific attributes and their values, which you can define using the input fields (Selecting matrices)

Simple attribute (network)

If this option is selected, you can select a network attribute for the formula in the lower part of the window.

Simple attribute (matrix)

If this option is selected, you can select a matrix attribute for the formula in the lower part of the window.

Origin/destination attribute (zone/main zone)

By selecting this option, for each Network object reference type specified, you can apply an origin or destination attribute in the formula. Select the Origin or Target button; in the lower part of the window select the associated attribute.

Variable attribute

For formula matrices, it is possible to add variable attributes to the formula. If this option is selected, you can take up a variable attribute in the formula.

Constant

If this option is selected, you can enter a constant numeric value as an operand.

Click this button to select an operator for the formula. The selection available depends on the operand type, of which the values are used in the formula.

Available operators and their priority:

The parenthesis operator has the highest priority. Click the icon to insert it. In the following, the other operator groups are listed in decreasing priority:

1. unary operator:

  • ! Negation of a subsequent term

2. multiplicative binary operators:

  • * generates the product of two terms
  • / generates the quotient of two terms

3. additive binary operators:

  • + generates the sum of two terms

Note

You can also use this function to merge two texts.

  • - generates the difference of two terms

4. relational binary operators:

  • > compares two terms as to which one is "greater"
  • >= compares two terms as to which one is "greater" or whether they are "equal"
  • <= compares two terms as to which one is "smaller" or whether they are "equal"
  • < compares two terms as to which one is "smaller"

5. binary equality operators:

  • = checks whether the two terms are equal
  • != checks whether the two terms are unequal
  • & links two terms with a logical AND
  • | links two terms with a logical OR

When binary operators have the same priority, the order of evaluation is from left to right (left associative).

Example 4/2/2 is evaluated as (4/2)/2 = 1, not as 4/(2/2) = 4

Click the button to select a function for the formula (Using matrix values for calculations).

  • OnlyActiveODPairs(x,y) applies a value of x to the active OD pairs and a value of y to inactive OD pairs; ONLYACTIVERELATIONS(,) is inserted at the mouse pointer position
  • Min(x,y) forms the minimum of x and y
  • Max(x,y) forms the maximum of x and y
  • Abs(x) absolute value of x
  • Round (x,p) rounds x to p decimal places, the text ROUND(,) is inserted at the mouse pointer position.
  • RandomRound (x,p) randomly rounds x to p decimal places, the text RANDOMROUND(,) is inserted at the mouse pointer position. Variable p is optional. In case of random rounding, the values are rounded depending on the share to be rounded. Random rounding causes the total of the values in the matrix to remain approximately constant.

Example

0.3 is rounded up to 1 with 30% probability and down to 0 with 70% probability.

  • Floor(x) rounds to the highest integer which is smaller or equal to x. FLOOR() is inserted at the mouse pointer position.
  • Ceil(x) rounds to the lowest integer which is higher or equal. CEIL() is inserted at the mouse pointer position.
  • Truncate (x) truncates decimals places of x. TRUNCATE() is inserted at the cursor position
  • Reciprocal(x) generates the reciprocal value of x, that is 1/x; RECIPROCAL() is inserted at the mouse pointer position.
  • Percent(x,y) is equivalent to 100*x/y, PERCENT(,) is inserted at the mouse pointer position
  • Power(x,y) corresponds to xy, POW(,) is inserted at the mouse pointer position
  • Root(x) generates the square root of x. The text SQRT() is inserted at the mouse pointer position.
  • Exponential(x) generates the exponential function of x
  • Logarithm(x) generates the natural logarithm of x
  • GEH statistics(x,y) calculates the GEH statistics for x and y
  • Make symmetrical(x) computes the mean value of the value above and below the matrix diagonal in a matrix x; SYMMETRIZE() is inserted at the mouse pointer position
  • MirrorBottomTriangle(x) mirrors the lower triangle of the matrix x, MIRROR_LOWER() is inserted at the mouse pointer position
  • MirrorTopTriangle(x) mirrors the upper triangle of the matrix x, MIRROR_UPPER() is inserted at the mouse pointer position
  • Transpose(x) swaps the row and column values in a square matrix; TRANSPOSE() is inserted at the mouse pointer position
  • If (b;w;f) forms a conditional branch that outputs value w if condition b is true, or outputs value f if condition b is false. The text If(,,) is inserted at the mouse pointer position.
  • Modulo(x,y) calculates the remainder of a division of dividend x and divisor y. The text MODULO(x,y) is inserted at the mouse pointer position.

Examples

MODULO(5,2) = 1

MODULO(9,3) = 0

  • Integer quotient(x,y) calculates the integer quotient of dividend x and divisor y. The text DIV(,) is inserted at the mouse pointer position.

Examples

DIV(5,2) = 2

DIV(9,3) = 3

DIV(7,−3) = −3

DIV(-7,−3) = 2

  • Sine(x) calculates the sine of x. SIN() is inserted at the mouse point position.
  • Cosine (x) calculates the cosine of x. COS() is inserted at the mouse pointer position.
  • Tangent (x) calculates the tangent of x. TANGENT() is inserted at the mouse pointer position.
  • Arc sine (x) calculates the arc sine of x. ARCSIN() is inserted at the mouse pointer position.
  • Arc cosine (x) calculates arc cosine of x. ARCCOS() is inserted at the mouse pointer position.
  • Arc tangent (x) calculates the arc tangent of x. ARCTAN() is inserted at the mouse pointer position.
  • Current iteration() has no parameters and shows the current value of the iteration counter within a feedback loop. If the function is used in a formula outside of the procedure sequence, zero is always displayed. The text Iterationcounter() is inserted at the mouse pointer position.
  • MSA (x,y) returns the weighted mean of x and y. MSA(,) is inserted at the mouse pointer position. The formula of the calculation is MSA (x, y) = 1 / (IterationCounter() + 1) * x + IterationCounter() / (IterationCounter() + 1) * y. When using the function without a feedback loop, the iteration counter is always 0. The result then equals the value of x (Fundamentals: Average determination using the Method of Successive Averages (MSA)).
  • Sum(MatrixList(...)) calculates for each element the sum of all matrices in the matrix list; SUM(MatrixList() is inserted at the cursor position (Fundamentals: Performing calculations for multiple matrices)
  • Product(MatrixList(...)) calculates for each element the product of all the matrices in the matrix list; PRODUCT(MatrixList() is inserted at the mouse pointer position (Fundamentals: Using matrix combination functions)
  • Average(MatrixList(...)) calculates for each element the average of all the matrices in the matrix list; AVERAGE(MatrixList()) is inserted at the mouse pointer position (Fundamentals: Using matrix combination functions)
  • Total demand matrix (”x”) calculates the total demand matrix of the demand segment x; TOTALDEMANDMATRIX() is inserted at the mouse pointer position
  • Assignment matrix (”x”) calculates the actual assigned demand matrix of the demand segment x; ASSIGNEDVOLUMEMATRIX() is inserted at the mouse pointer position
  • OD pair filter assignment matrix (”x”) calculates the actual assigned demand matrix of the demand segment x after the filter for OD pairs has been applied; FILTEREDASSIGNEDVOLUMEMATRIX() is inserted at the mouse pointer position
  • Flow bundle matrix (“x”) calculates the flow bundle matrix of the demand segment x; FLOWBUNDLEMATRIX() is inserted at the mouse pointer position
  • Flow bundle matrix departure TI ("x", "y") calculates the flow bundle matrix of the demand segment x at the time interval y related to the departure time at the origin zone, FLOWBUNDLEMATRIXDEPARTURETI(,) is inserted at the cursor position
  • Flow bundle matrix arrival TI ("x", "y") calculates the flow bundle matrix of the demand segment x at the time interval y related to the arrival time at the destination zone, FLOWBUNDLEMATRIXARRIVALTI(,) is inserted at the cursor position
  • Direct distance () calculates for a zone matrix (main zone matrix or stop area matrix) the direct distance of the OD pairs (main OD pairs) For stop area matrices, this is the distance between stop areas, DIRECTDISTANCE() is inserted at the mouse cursor position

Note

If under User preferences you selected a point as your decimal separator, a comma is used as separator between the elements. Otherwise, a semicolon is used (Selecting a decimal point).

The button opens the Add ForEach window. Here, you can insert functions of the ForEach type in your formula (Fundamentals: Performing calculations for multiple matrices).

You insert a loop function of the type ForEach in the formula. You can create and calculate a number of matrices in a single procedure step with this function.

Click the button to open the Insert aggregation function window, in which you can select matrix conversion functions (Fundamentals: Using matrix conversion functions).

  • Matrix sum (x, b) calculates the sum of the matrix x, MATRIXSUM(,) is inserted at the mouse cursor position. Variable b is optional. If the value of b is not zero, only active OD pairs will be taken into account.
  • Matrix diagonal sum (x, b) calculates the sum of the diagonal of the matrix x, MATRIXDIAGONALSUM(,) is inserted at the mouse cursor position. Variable b is optional. If the value of b is not zero, only active OD pairs will be taken into account.
  • Matrix row sum (x, i, b) calculates the sum of the row i of the matrix x, MATRIXROWSUM(,,) is inserted at the mouse cursor position. Variable b is optional. If the value of b is not zero, only active OD pairs will be taken into account.
  • Matrix column sum (x, i, b) calculates the sum of the column i of the matrix x, MATRIXCOLSUM(,,) is inserted at the mouse cursor position. Variable b is optional. If the value of b is not zero, only active OD pairs will be taken into account.
  • Matrix minimum (x, b) finds the minimum of the items of matrix x, MATRIXMIN(,) is inserted at the mouse cursor position. Variable b is optional. If the value of b is not zero, only active OD pairs will be taken into account.
  • Matrix maximum (x, b) finds the maximum of the items of matrix x, MATRIXMAX(,) is inserted at the mouse cursor position. Variable b is optional. If the value of b is not zero, only active OD pairs will be taken into account.
  • Matrix average (x, b) calculates the average of all items of matrix x, MATRIXAVG(,) is inserted at the mouse cursor position. Variable b is optional. If the value of b is not zero, only active OD pairs will be taken into account.
  • Matrix value (x, i, j) displays the value of row i and column j of matrix x, MATRIXVAL(,) is inserted at the mouse cursor position. Variable b is optional. If the value of b is not zero, only active OD pairs will be taken into account.

The button opens the Create TableLookup window. Here, you can insert a function of the type TableLookup in your formula (Fundamentals: Using the TableLookup function).

With this function, you can extract a value from any Visum table and edit it in the formula. This is useful, for example, when managing parameter values which are used for the calculation of attributes. Alternatively, you can, for example, transfer data from one network object to another.

Network object type

From the drop-down list, select the network object type which represents the base of the function. All following conditions of the function refer to the selected network object type. Procedure variables can also be selected.

Variable name

Enter a variable name which starts with a letter. The first matching value in the table is used for further calculation. If no matching value is found, an empty value is used.

Click this button to insert a bracket term without content into the formula.

6.  Select the Matrix quantity tab.

7.  Make the desired changes.

Element

Description

Insert a fixed number of matrices

If the option is selected, specify in the appropriate box the number of matrices you would like to insert.

Note

When creating more than one matrix, the matrix numbers will be continuously ascending. All created matrices have the same properties.

Insert matrices via matrix reference

Select this option to create one or more matrices. For new matrices, you can specify the values of the matrix attributes through references which you input as code (Selecting matrices).

Edit new matrices after creating

Select this option to open the created matrices in the Matrix editor and edit them.

8.  Confirm with OK.

9.  Confirm again with OK.

The new formula matrix is created and calculated. It is displayed in the Matrices window, under Formula matrices. If you have developed formulas for matrices needed in the procedure, the respective formula matrices are created when you run the procedure sequence.

Note: If you save a formula matrix as a file, only the current values are saved, not the formula.

 

Note: In the directory C:\Users\Public\Documents\PTV Vision\PTV Visum 2024/Examples, you can find an example of use on this topic. The example Formulas shows the use of formula attributes, formula matrices, and aggregation functions in lists.