Exemple #1
0
    def getHash(self, node: ODNode):

        # hashCode = hash(nodee.origin.toString()) + hash(nodee.destination.toString())
        # hashCode = hash(hashCode)
        # hashCode = hash(node.toString())

        coder = hashlib.sha1()
        encodedString = node.toString().encode()
        coder.update(encodedString)
        hashCode = coder.hexdigest()
        hashCode = int(hashCode, 16)

        return hashCode
Exemple #2
0
    def toString(self):
        string = "HashTable: "

        # the empty node, sigals no element at this index
        empty = ODNode.ODNode(Coordinate.Coordinate(0, 0),
                              Coordinate.Coordinate(0, 0), 0)

        index = 0
        '''iterate through the odnodes'''
        for odnode in self.table:
            if odnode.__eq__(empty) is False:
                # if True:
                if odnode.getCount() >= 0:
                    string = string + ("\nIndex[" + str(index) + "]")

                    direction = "Out-Bound"

                    if odnode.getInbound() is True:
                        direction = "In-Bound"
                    '''the to string method of the odnode'''
                    string = string + \
                             "\n\tOrigin: " + odnode.origin.toString() + \
                             "\n\tDestination: " + odnode.destination.toString() + \
                             "\n\tDirection: " + direction + \
                             "\n\tCount: " + str(odnode.count) + \
                             "\n\tAMCount: " + str(odnode.getAmCount()) + \
                             "\n\tPMCount: " + str(odnode.getPmCount()) + \
                             "\n\tTimes:"
                    '''iterate through timenodes'''
                    for time in odnode.times:
                        timeNode = odnode.times[time]
                        timeNodePaths = timeNode.getPaths()
                        '''only print if the count is not 0'''
                        if timeNode.getCount() > 0:
                            add = "\n\t\tWeekDay: " + str(timeNode.getWeekDay()) + " TimeID: " + \
                                    str(timeNode.getTimeID()) + " Count: " + str(timeNode.getCount())
                            string = string + add

                            if len(timeNodePaths) > 0:

                                string = string + "\n\t\tPaths:"
                                # for each time iterate through all of the trips
                                for path in timeNodePaths:
                                    pathNode = timeNodePaths[path]
                                    more = "\n\t\t\tPathID: " + str(
                                        pathNode.getPathID()
                                    ) + " Count: " + str(pathNode.getCount())
                                    string = string + more
            index += 1

        return string
Exemple #3
0
    def print(self):

        # the empty node, sigals no element at this index
        empty = ODNode.ODNode(Coordinate.Coordinate(0, 0),
                              Coordinate.Coordinate(0, 0), 0)

        index = 0

        print("HashTable: ")
        for this in self.table:
            if this.__eq__(empty) is False:
                if this.getCount() > 0:
                    print("Index[" + str(index) + "] " + this.toString())
            index += 1
Exemple #4
0
    def __init__(self, num: int, factor: int = 2):
        """num is the number of elements the table needs to hold, not the size of the table
        factor is the loading factor for the hashtable, the size and speed of the table increase as this increases
        a factor of 2 is normal, 3 is faster and requires more space"""

        # the size of the hashTable, must be prime
        size = find_next_prime(num * factor)

        dummyCoordinate = Coordinate.Coordinate(0, 0)
        dummyNode = ODNode.ODNode(dummyCoordinate, dummyCoordinate, 0)
        '''create the array'''
        table = []
        self.table = table
        for dumbNode in range(0, size):
            table.append(dummyNode)
Exemple #5
0
 '''get the direction of the node'''
 direction = outputTextFile1.readline().strip()
 '''get the count of the od node'''
 vcountLine = outputTextFile1.readline().strip()
 vcount = vcountLine[7:]
 '''get the am count of the od node'''
 vamCountLine = outputTextFile1.readline().strip()
 vamCount = vamCountLine[9:]
 '''get the pm count of the od node'''
 vpmCountLine = outputTextFile1.readline().strip()
 vpmCount = vpmCountLine[9:]
 '''increment the global time period totals'''
 totalAM += int(vamCount)
 totalPM += int(vpmCount)
 '''create the od node'''
 vodnode = ODNode.ODNode(voriginC, vdestC, int(vcount))
 if direction.__contains__("In-Bound"):
     vodnode.setInbound(True)
 else:
     vodnode.setInbound(False)
 '''update the period counts of the od node'''
 vodnode.setAmCount(int(vamCount))
 vodnode.setPmCount(int(vpmCount))
 '''readout the "Times: "'''
 readOut = outputTextFile1.readline().strip()
 '''update the times of the od node'''
 vt = outputTextFile1.readline().strip()
 '''for all the timenodes listed'''
 while vt.__contains__("WeekDay"):
     '''get the weekday, time, and count'''
     weekday = int(vt[9:11])
Exemple #6
0
 '''readout the direction'''
 direction = inputfile17.readline()
 '''get the count of the od node'''
 vcountLine = inputfile17.readline().strip()
 vcount = vcountLine[7:]
 '''get the am count of the od node'''
 vamCountLine = inputfile17.readline().strip()
 vamCount = vamCountLine[9:]
 '''get the pm count of the od node'''
 vpmCountLine = inputfile17.readline().strip()
 vpmCount = vpmCountLine[9:]
 '''increment the global time period totals'''
 totalAM += int(vamCount)
 totalPM += int(vpmCount)
 '''create the od node'''
 vodnode = ODNode.ODNode(voriginC, vdestC, int(vcount))
 '''update the period counts of the od node'''
 vodnode.setAmCount(int(vamCount))
 vodnode.setPmCount(int(vpmCount))
 '''set the direction of the node'''
 if direction.__contains__("In-"):
     vodnode.setInbound(True)
 else:
     vodnode.setInbound(False)
 '''readout the "Times: "'''
 readOut = inputfile17.readline().strip()
 '''update the times of the od node'''
 vt = inputfile17.readline().strip()
 '''for all the timenodes listed'''
 while vt.__contains__("WeekDay"):
     '''get the weekday, time, and count'''
Exemple #7
0
dcClose = (1 / 2) * (dcSize / (dcNum - 1)) * math.sqrt(2)

# the time information
startAM = "00:00"
endAM = "24:00"
timeInterval = 30

# create a complete list of OD nodes
# each origin has all of the destinations
minSizeOfHashTable = dcGrid.__len__() * novaGrid.__len__() * 2
ODNodes = HashTable.HashTable(minSizeOfHashTable)  # a container of OD Nodes

for nova in novaGrid:
    for dc in dcGrid:
        # create inbound node
        inBoundNode = ODNode.ODNode(nova, dc, 0)
        inBoundNode.createTimeIntervals(startAM, endAM, timeInterval)
        inBoundNode.setInbound(True)

        # create outbound node
        outBoundNode = ODNode.ODNode(dc, nova, 0)
        outBoundNode.createTimeIntervals(startAM, endAM, timeInterval)
        outBoundNode.setInbound(False)

        # append to container
        ODNodes.insert(inBoundNode)
        ODNodes.insert(outBoundNode)

# print progression statement
if printProgramProgression:
    print("HashTable of OD Nodes created of size: " + str(ODNodes.table.__len__()))
Exemple #8
0
def getODNodesFromFile(fileName: str, timeInterval: int):
    """

    :param fileName: the name of the file to get the info
    :return: a list of all the od nodes the file contained
    """
    '''list of od nodes'''
    ODNodes = []

    with open(fileName, 'r') as inputfile17:

        for line in inputfile17:
            line = line.strip()
            '''get the general attributes from the outputfile'''
            if line.__contains__("Total Trips"):
                totalTripCount = int(line[13:])
            if line.__contains__("Int Trips"):
                interestTripCount = int(line[13:])
            if line.__contains__("OD Maps"):
                odMapCount = int(line[13:])
            if line.__contains__("Time Maps"):
                timeMapCount = int(line[13:])
            if line.__contains__("Path Maps"):
                pathMapCount = int(line[13:])
            '''if we are looking at a new od node'''
            while line.__contains__("Index"):
                '''get the origin of the od node'''
                voriginLine = inputfile17.readline().strip()
                if voriginLine == '':
                    break

                vorigin = voriginLine[8:]
                vcommaIndex = vorigin.index(",")
                voriginLat = vorigin[:vcommaIndex]
                voriginLong = vorigin[vcommaIndex + 1:]
                voriginC = Coordinate.Coordinate(float(voriginLat),
                                                 float(voriginLong))
                '''get the destination of the od node'''
                vdestLine = inputfile17.readline().strip()
                vdestination = vdestLine[13:]
                vcommaIndex = vdestination.index(",")
                vdestlat = vdestination[:vcommaIndex]
                vdestlong = vdestination[vcommaIndex + 1:]
                vdestC = Coordinate.Coordinate(float(vdestlat),
                                               float(vdestlong))
                '''readout the direction'''
                direction = inputfile17.readline()
                '''get the count of the od node'''
                vcountLine = inputfile17.readline().strip()
                vcount = vcountLine[7:]
                '''get the am count of the od node'''
                vamCountLine = inputfile17.readline().strip()
                vamCount = vamCountLine[9:]
                '''get the pm count of the od node'''
                vpmCountLine = inputfile17.readline().strip()
                vpmCount = vpmCountLine[9:]
                '''create the od node'''
                vodnode = ODNode.ODNode(voriginC, vdestC, int(vcount))
                '''update the period counts of the od node'''
                vodnode.setAmCount(int(vamCount))
                vodnode.setPmCount(int(vpmCount))
                '''set the direction of the node'''
                if direction.__contains__("In-"):
                    vodnode.setInbound(True)
                else:
                    vodnode.setInbound(False)
                '''readout the "Times: "'''
                readOut = inputfile17.readline().strip()
                '''update the times of the od node'''
                vt = inputfile17.readline().strip()
                '''for all the timenodes listed'''
                while vt.__contains__("WeekDay"):
                    '''get the weekday, time, and count'''
                    weekday = int(vt[9:11])
                    vtime = vt[19:24]
                    vcount = int(vt[32:])
                    '''create the TimeNode'''
                    vdt = datetime.strptime(vtime, "%H:%M")
                    vtimenode = TimeNode.TimeNode(vdt, weekday, timeInterval)
                    vtimenode.setCount(vcount)
                    '''the dict to be used as the dict of paths for timenode'''
                    paths = {}
                    '''read the next line in the file'''
                    nl = inputfile17.readline().strip()

                    # changed the output of the hashtable to be correct
                    if nl.__contains__("Paths"):

                        nl = inputfile17.readline().strip()

                        while nl.__contains__("PathID"):
                            '''get the PathNode attributes'''
                            countIndex = nl.index("Count:")
                            path = nl[8:countIndex - 1]
                            count = nl[countIndex + 7:]
                            '''create the pathNode'''
                            pathNode = PathNode.PathNode(path)
                            pathNode.setCount(int(count))
                            '''add the PathNode to the dict of PathNodes'''
                            paths[path] = pathNode

                            nl = inputfile17.readline().strip()

                        vt = nl
                    '''set the paths of the time node'''
                    vtimenode.setPaths(paths)

                    vt = nl
                    '''add the time node to the list of times in od node'''
                    vodnode.addTimeNode(vtimenode)

                if vt.__contains__("Index"):
                    line = vt
                '''add the od node to the list of od nodes'''
                '''only if it is not an empty node'''
                e = Coordinate.Coordinate(0, 0)
                empty = ODNode.ODNode(e, e, 0)
                if vodnode.__eq__(empty) is False:
                    ODNodes.append(vodnode)

    inputfile17.close()

    return ODNodes
# the time information
startAM = "00:00"
endAM = "24:00"
timeInterval = 30

# create a complete list of OD nodes
# each origin has all of the destinations
minSizeOfHashTable = dcGrid.__len__() * novaGrid.__len__() * 2
ODNodes = HashTable.HashTable(minSizeOfHashTable)  # a container of OD Nodes

print("creating od grid...")
for nova in novaGrid:
    for dc in dcGrid:
        # create inbound node
        inBoundNode = ODNode.ODNode(nova, dc, 0)
        inBoundNode.createTimeIntervals(startAM, endAM, timeInterval)
        inBoundNode.setInbound(True)

        # create outbound node
        outBoundNode = ODNode.ODNode(dc, nova, 0)
        outBoundNode.createTimeIntervals(startAM, endAM, timeInterval)
        outBoundNode.setInbound(False)

        # append to container
        ODNodes.insert(inBoundNode)
        ODNodes.insert(outBoundNode)

for i in range(0, fileNumber):

    fileNum = str(i)
Exemple #10
0
 def getHashTwo(self, noda: ODNode):
     return hash(noda.toString())