CUBE Path files

Dear all,

May I inquire if is it possible to specify the Path file from HIGHWAY step in CUBE Voyager as input to a script for post-processing? Also is there a way to access the path file directly and convert it to another format for further analysis.

Hope you can provide some test scripts.

Best regards,

Norlel

  • There is no Voyager program which can read in a path file. The path file can be used in the network window to visualize the paths. We do provide Voyager file APIs which lets you read path files. You can download the API DLLs, Python example and documentation from communities.bentley.com/.../275055

  • Hello Ahmed, hope you are well as always. 

    May I ask if you have an updated Voyager API that can work with Python 3.8 as I am getting incompatible type errors?

    Hoping for your kind assistance.

  • Could you let us know what error you are getting?

  • Hello Ahmed,

    I am getting the following error in Python 3.8.6:

    Attached is the script that I am using where I modified some declaration of data types.

    from ctypes import *
    from decimal import Decimal
    from collections import defaultdict
    import numpy
    import time
    import csv
    from array import array
    import os
    #############################################################
    """
    inPathFile = "C:\\Users\\User\\Desktop\\CUBE6_VoyagerAPI\\PythonExample\\ROADPATHS.PTH"
    outMatFile = "test.mat"
    outLinkVolFile = "SelectLinkVolumes.csv"
    aNode = 436
    bNode = 493
    nVolOut = 3
    precision = (c_char * nVolOut)('D','D','D')
    matNames = (c_char_p * nVolOut)('out1','out2','out3')
    """
    inPathFile = "AM_Total.PTH"
    outMatFile = "test.mat"
    outLinkVolFile = "SelectLinkVolumes.csv"
    aNode = 191908
    bNode = 191923
    nVolOut = 17
    precision = ['D','D','D','D','D','D','D','D','D','D','D','D','D','D','D','D','D']
    matNames = ['Total','HH1','HH2','HH3','HH4','HH5','IC1','IC2','IC3','IC4','AG1','AG2','AG3','AG4','NHB','IX_XI','XX']
    ##############################################################

    class pathReadData(Structure):
    _fields_ = [("nodes",POINTER(c_int)),
    ("costs", POINTER(c_int)),
    ("vols", POINTER(c_float)),
    ("numNodes", c_int),
    ("numCosts", c_int),
    ("highestVol", c_int),
    ("iteration", c_int),
    ("I", c_int),
    ("J", c_int),
    ("table", c_int)]

    errMsg = c_char_p()
    errLen = 256

    voyager = cdll.LoadLibrary("C:\\Users\\User\\Desktop\\CUBE6_VoyagerAPI\\Dlls\\x64\\VoyagerFileAccess.dll")
    voyager.PathReaderReadNext.argtypes = [c_long, POINTER(pathReadData)]
    voyager.MatWriterWriteRow.argtypes = [c_long, c_int, c_int, POINTER(c_double)]

    openPath = voyager.PathReaderOpen(inPathFile, errMsg, errLen)
    print ('Error Message:',errMsg.value)

    nZones = voyager.PathReaderGetNumZones(openPath)
    print ('Number of Zones:',nZones)

    nIters = voyager.PathReaderGetNumIterations(openPath)
    print ('Number of Iterations:',nIters)

    highVolIndex = voyager.PathReaderGetHighestVol(openPath)
    print ('Highest Volume Index:', highVolIndex)

    nPaths = voyager.PathReaderGetNumPaths(openPath)
    print ('Number of Paths:', nPaths)

    lenLongPath = voyager.PathReaderGetMaxPathLen(openPath)
    print ('Length of Longest Path (number of nodes):', lenLongPath)

    nTables = voyager.PathReaderGetNumTables(openPath)
    print ('Number of Tables:',nTables)

    #tblNames = (c_char_p * nTables)(*[c_char_p(create_string_buffer(7963648).raw) for i in xrange(nTables)] )
    tblNames = [(ctypes.create_string_buffer(7963648).raw) for i in range(nTables)]
    voyager.PathReaderGetTableNames(openPath,tblNames)
    print ('Table Names:',', '.join([tblNames[i] for i in range(nTables)]))

    iterFactors = (c_float * nIters)()
    voyager.PathReaderGetIterFactors(openPath,iterFactors)
    print ('Iteration Factors:',', '.join(["{0:.4f}".format(iterFactors[i]) for i in xrange(nIters)]))

    pathData = pathReadData()
    pathData.nodes = (c_int*lenLongPath)()
    pathData.costs = (c_int*lenLongPath)()
    pathData.vols = (c_float*highVolIndex)()

    matrix = numpy.zeros((nVolOut,nZones,nZones), dtype=numpy.double)
    linkVols = defaultdict(lambda: [0.0 for i in xrange(nVolOut)])
    def add(x,y): return x+y

    writeMat = voyager.MatWriterOpen(outMatFile, "SL", 1, nZones, nVolOut, precision, matNames, errMsg, errLen)
    voyager.PathReaderRewind(openPath)

    count=0
    print ("Processing paths....")
    start_time = time.time()
    last_time = time.time()

    while (voyager.PathReaderReadNext(openPath, pathData)) > 0:
    count = count + 1
    nodes = [pathData.I] + list(pathData.nodes[i] for i in xrange(pathData.numNodes))

    if any([aNode,bNode] == nodes[i:i+2] for i in xrange(len(nodes) - 1)):
    volumes = [j * iterFactors[pathData.iteration-1] for j in list(pathData.vols[i] for i in xrange(nVolOut))]
    for i in xrange(nVolOut):
    matrix[i][pathData.I-1][pathData.J-1]= matrix[i][pathData.I-1][pathData.J-1] + volumes[i]

    for i in (nodes[i:i+2] for i in xrange(len(nodes) - 1)):
    linkVols[tuple(i)] = map(add, linkVols[tuple(i)], volumes)

    for i in xrange(highVolIndex):
    pathData.vols[i] = 0.0

    for i in xrange(lenLongPath):
    pathData.nodes[i] = 0

    if ((time.time()-last_time) >= 60):
    print ("{0:.2f}".format((count*100.0)/nPaths), "% processed")
    last_time = time.time()


    for i in xrange(nZones):
    for v in xrange(nVolOut):
    row = numpy.ctypeslib.as_ctypes(matrix[v][i])
    voyager.MatWriterWriteRow(writeMat, v+1, i+1, row)

    with open (outLinkVolFile, 'wb') as volOut:
    writer = csv.writer(volOut)
    for key, value in linkVols.iteritems():
    outString = map(str,key) + map(str,value)
    writer.writerow(outString)

    voyager.MatWriterClose(writeMat)
    voyager.PathReaderClose(openPath)

    print ("Total time:",time.strftime('%H:%M:%S', time.gmtime(time.time()-start_time)))