data items for every data element, such as node, link, turn or transit line. While in most cases the limit of 3 user data items is acceptable, we have seen several very specific applications in which the storage of more than three additional data items per network element is required. Since this data is usually only available for the existing network (base scenario), a simple solution to this apparent space problem is to define more than one base scenario, with each scenario holding three different user data items. The network calculator, module 2.41, may then be used to import the required data item from the corresponding base network scenario, whenever it is required for a specific task.
Another possibility is available when the data items are limited in their range to only a few digits. Since every user data item has a precision of (at least) six significant digits, more than one attribute value may be packed into a single user data item.
This note explores the latter method and shows how to pack, unpack and otherwise work with such packed user data items. The discussion is limited to the case in which the attributes stored in the user data item are limited to one digit (range 0 to 9), two digits (range 0 to 99) or three digits (0 to 999).
As an example, consider a user defined node data item ui1
in which three
different node attributes are packed as a six-digit value of the form
"CCDEEE
":
C: Municipality to which the node belongs (range 00 to 99, stored in digits "ten thousands" and "hundred thousands" of ui1) D: Downtown / Outside downtown flag (0 or 1 stored in digit "thousands" of ui1) E: Elevation above sea level in meters (range 000m to 999m, stored in digits "ones", "tens" and "hundreds" of ui1)
First, note that the packing operation here is simply
ui1=10000*C+1000*D+E
.
Often, this step is performed implicitly during the coding phase, i.e.
the attributes are read in in their packed format "CCDEEE
".
Let us now look at the arithmetic expressions to extract (unpack) the
three attributes from the (packed) user data item ui1
:
C= int(ui1/10000) expression for municipality D= int(ui1/1000).mod.10 expression for downtown flag E= ui1.mod.1000 expression for elevation
Remember that the X.mod.Y
operator evaluates the remainder of the integer
division X/Y and therefore, with Y=10^N
being a power of ten, can be used
to extract the N rightmost digits of an integer number X. The division of a
number X by a power of ten, say Z=10^M
, will shift the rightmost M digits from
the left of the decimal point to the fraction part on the right of the decimal
point, where they can be easily truncated, using the intrinsic int()
.
In general, we can use the expression
(int(X/10^M).mod.10^N)
to extract from the
packed item X an N digit attribute that is followed (to the right)
by other packed attributes
totaling M digits. These expressions can be inserted into the algebraic
expressions (network editor, matrix editor of functions) whenever the value
of the attribute is needed; thus the unpacking is done implicitly as a part
of the expression evaluation and no special prior step for unpacking
has to be performed.
Sometimes, it might also be necessary to write or replace the value of a attribute within a packed data item. Let's look at the expression that writes (packs) an N digit value Y at position M (defined as above) into the item X:
X:= X+(Y-int(X/10^M).mod.10^N)*10^M
If the value Y is not sure to be an integer value, use int(Y)
in the above
formula.
To illustrate the problem, consider that, in the above example, we want to redefine the downtown flag D of all centroid nodes to contain the new value 2. To do this we use the network calculator, module 2.41, and with the expression
ui1+(2-int(ui1/1000).mod.10)*1000
reevaluate the values of ui1
for all centroids, selected with the
appropriate node subset selection.
Let's now look at a more elaborate example. Suppose we are interested in the slopes of the links, in order to implement a realistic fuel consumption model. The slope of link I to J is given by
SLOPE = 10*(Elevation(J)-Elevation(I))/length
Note the the elevation is given in meters, the link length in kilometers and
the slope in percent. Supposing that the elevation is still stored in
the three rightmost digits of ui1
, the parameter SLOPE in the expression
for the fuel consumption model can thus be directly replaced by the term
\(10*(uj1.mod.1000-ui1.mod.1000)/length)
without any need to store the link slope explicitly as one of the link user data items.
As we can see, several attributes can be stored in a single user data item
and each of them can still be accessed quite easily in volume-delay
functions and / or network calculations. Moreover, it is also possible
to access individual attributes of a packed item during the link and node
subset selection dialog. We consider again an N digit attribute that starts
at position M (see above) in node user data item 1 (ul1
). The line
corresponding to the inclusion of those elements with an attribute value X
in the link selection dialog can be written in general as
ul1=X,999999,10^N,10^M
Of course the same general form is applicable to any user data item; e.g. the line
ui1=1,999999,10,1000
selects all the nodes that are outside downtown in the example above (i.e. D=1). Along the same lines, the dialog
Enter: Link types or attributes (from,to) = ui1=23,99999,100,10000 = and uj1=25,99999,100,10000 =
selects all those links joining municipality 23 with municipality 25. (Refer also to section III-5.3 of the EMME/2 User's Manual for details on the node / link subset selection dialog.)