How to Significantly Reduce Runtime in Cube Voyager by Handling Matrices in Memory

Cube 6.4 has overcome any memory limitation in Cube Voyager*. When dealing with big matrices and reading matrix cells from disk using MATVAL, looping through complex operations can be slow. Using the following tips for handling matrices in memory, runtime can be reduced by 50 percent or more.

*(See the Community for advice on memory usage.)

Here's how:

To illustrate, we will use a triple indexing application developed by the Western Australia DoT, producing the skim matrix for Park&Ride.

Original script before improvement

Matrix #1: The original script for the Park&Ride skim matrix used MATVAL to access the matrix cells and had a runtime of 00:02:00 on the computer.

LOOP K=1, {Zones_Total}
    IF (INLIST(K,PNR) = 1)
        JLOOP
            IF ((MATVAL(1,1,I,K,99999)<>0) && (MATVAL(2,1,K,J,99999) <>0)) ; EXCLUDE NON PNR ZONES
                ;(....)
                ; MatVal( filenumber, tablenumber, i, j, failvalue)
                MW[8]= (-(WWKMODCH(2,1)+WWKMODCH(2,2)*MATVAL(1,1,I,K,99999)+WWKMODCH(2,3)*MATVAL(1,3,I,K,99999)+
                         WWKMODCH(2,5)*MATVAL(2,2,K,J,99999)+WWKMODCH(2,6)*MATVAL(2,4,K,J,99999)+
                         WWKMODCH(2,7)*MATVAL(2,3,K,J,99999)+WWKMODCH(2,8)*MATVAL(3,1,K,J,99999)+
                         WWKMODCH(2,12)*zonevpl*MATVAL(1,1,I,K,99999))*Cfactor[k]-
                         WWKMODCH(2,4)*MATVAL(4,1,I,J,99999)-WWKMODCH(2,14)*zonevpw)
                IF (MW[8] < MW[10] && MW[8] <> 0)
                    MW[10] = MW[8] ; PNRTIME
                    MW[11] = K
                ENDIF
            ENDIF
        ENDJLOOP
    ENDIF
ENDLOOP

 

Improvement step #1: AUTOMDARRAY_1

Matrix #3 uses AUTOMDARRAY in the modified script.

FILEI MATI[1] = "....\Inputs\MALOO00B_Y2051_target.MAT",
    AUTOMDARRAY=MATI1 MI=1-4

Calling the input cells values stored in memory as below.

IF ((MATI1[1][I][K]<>0) && (MATI2[1][K][J]<>0)) ; EXCLUDE NON PNR ZONES 
    ;(....)
    MW[8]=(-(WWKMODCH(2,1)+WWKMODCH(2,2)*MATI1[1][I][K]+WWKMODCH(2,3)*MATI1[3][I][K]+
    WWKMODCH(2,5)*MATI2[2][K][J]+WWKMODCH(2,6)*MATI2[4][K][J]+
    WWKMODCH(2,7)*MATI2[3][K][J]+WWKMODCH(2,8)*MATI3[K][J]+
    WWKMODCH(2,12)*zonevpl*MATI1[1][I][K])*Cfactor[k]-
    WWKMODCH(2,4)*MATI4[I][J]-WWKMODCH(2,14)*zonevpw)

 

Using this step, our example had a runtime of 00:01:22.

Improvement step #2: AUTOMDARRAY_2

Splitting the process into two steps, in our example, total runtime was reduced to 00:01:06 (circa):

  1. Matrix #6 – calculating the K-J skim matrix: Runtime = 00:00:01
  2. Matrix #8 – calculating the final I-J PNR AM Skim, using the K-J skim matrix from the previous step, as shown in the script below through MATI5: Runtime = 00:01:05
IF ((MATI1[1][I][K]<>0) && (MATI2[1][K][J]<>0)) ; EXCLUDE NON PNR ZONES
    ;(....)
    MW[8]=(-(WWKMODCH(2,1)+WWKMODCH(2,2)*MATI1[1][I][K]+WWKMODCH(2,3)*MATI1[3][I][K]+
    MATI5[1][K][J]+WWKMODCH(2,12)*zonevpl*MATI1[1][I][K])*MATI5[2][K][J]-
    WWKMODCH(2,4)*MATI4[I][J]-WWKMODCH(2,14)*zonevpw)

Therefore, cutting in half the total runtime.

 

Using these tips may provide you with similar or better results.

Do you need more information on how to use AUTOMDARRAY to optimize your process? Our Cube Voyager Reference Guide will provide you with full details about this keyword. And our Citilabs experts are here to help.

Reach out to us if you need a license activation code. And let us know what improvements you are able to gain using these tips. We’d like to hear from you!

 


 

For more information about this topic:
Please visit our Citilabs Community Forum. Here you will find several other interesting topics to help you improve your Cube models and the opportunity to interact with other Cube users.

Support Community


FILIPPO CONTIERO
SENIOR TRANSPORT MODELLER

Filippo is an experienced and passionate transport modeler based in München, Germany. As Senior Transport Modeller at Citilabs, he assists users in optimizing their use of Cube based on their individual needs and goals. In addition, he oversees Cube user support, training courses and “one-to-one” coaching. Prior to Citilabs, he worked as a consultant and transport modeller over a number of different projects, developing transportation models for highway and multimodal studies. He gained a Master Degree in Civil Engineering from Padova University (Italy) and an MSc in Transport Planning and Engineering from the ITS at Leeds University (UK).

 

c