Changes in / [df9e412:49db841]


Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • benchmark/convoy/genConvoyStats.py

    rdf9e412 r49db841  
    111111    global handoff, maxCycle, maxCycleSum
    112112
    113     # print("CurrNode: " + str(currNode) + " StartNode: " + str(startNode))
     113    # print("CurrNode: " + str(currNode))
    114114    # print(currCycle)
    115115    # if we visit a node from a previous call then return since we have already
     
    121121    # found a cycle
    122122    if visited[currNode]:
    123         # if currNode == startNode:
    124123        # print("LocalVisited, curr: " + str(currSum) + ", max: " + str(maxCycleSum) + ", Start: " + str(startNode) )
    125124        # if the cycle contains the start node check if it is our new max cycle
     
    131130
    132131    visited[currNode] = True
    133     # print(visited)
     132
    134133    for idx, val in enumerate(handoff[currNode]):
    135134        # continue if no edge
    136         # if val == 0:
    137         #     continue
     135        if val == 0:
     136            continue
    138137
    139138        currCycle.append(currNode)
    140139        findLargestCycle(startNode, idx, visited, globalVisited, currSum + val, currCycle)
    141140        currCycle.pop()
    142     # print(currNode)
     141
    143142    visited[currNode] = False
    144143
     
    148147    global handoff, sumPerRow, handoffTotal, maxCycle, maxCycleSum, minBound, maxBound, expected
    149148    currThds = len(handoff)
     149       
     150    # find largest cycle
     151    globalVisited = [False] * currThds
     152    for i in range(currThds):
     153        visited = [False] * currThds
     154        findLargestCycle(i, i, visited, globalVisited, 0, [])
     155        globalVisited[i] = True
    150156   
    151 
    152     # This is NP-Hard and is currently not tractable so we just estimate the largest cycle
    153     # the code to do so is commented below
    154 
    155     # find largest cycle
    156     # globalVisited = [False] * currThds
    157     # for i in range(currThds):
    158     #     # print(i)
    159     #     visited = [False] * currThds
    160     #     findLargestCycle(i, i, visited, globalVisited, 0, [])
    161     #     globalVisited[i] = True
    162 
    163     # # calculate stats
    164     # cycleHandoffs = []
    165     # cycleHandoffs.append(handoff[maxCycle[-1]][maxCycle[0]])
    166     # sumOfMaxCycleRows = sumPerRow[maxCycle[0]]
    167 
    168     # # expected handoff is MULT P( handoff ) for each handoff in max cycle
    169     # expectedConvoy = handoff[maxCycle[-1]][maxCycle[0]] / sumPerRow[maxCycle[-1]]
    170     # for idx, val in enumerate(maxCycle[1:]):
    171     #     cycleHandoffs.append(handoff[maxCycle[idx]][val])
    172     #     sumOfMaxCycleRows += sumPerRow[val]
    173     #     expectedConvoy = expectedConvoy * handoff[maxCycle[idx]][val] / sumPerRow[maxCycle[idx]]
    174 
    175     # # adjust expected bound
    176     # # if max cycle contains all nodes, sumOfMaxCycleRows / handoffTotal == 1
    177     # # else this adjusts the expected bound to compensate for the cycle not visiting all nodes
    178     # # also mult by 100 to turn into percentage from decimal
    179     # expectedConvoy = expectedConvoy * sumOfMaxCycleRows * 100 / handoffTotal
    180 
    181     ################################
    182 
    183     #start of approximation code is here:
    184 
    185     # instead we take the maximum handoff from each row and assume it is all a cycle as an approximation
    186     maxCycle = []
    187     maxCycleSum = 0
     157    # calculate stats
    188158    cycleHandoffs = []
    189     expectedConvoy = 100
    190     for i in range(currThds):
    191         currMax = max(handoff[i])
    192         maxCycle.append(i)
    193         cycleHandoffs.append(currMax)
    194         maxCycleSum += currMax
    195         expectedConvoy = expectedConvoy * currMax / sumPerRow[i]
    196 
    197     sumOfMaxCycleRows = handoffTotal
    198 
    199     # end of approximation code
    200     ###################################################
     159    cycleHandoffs.append(handoff[maxCycle[-1]][maxCycle[0]])
     160    sumOfMaxCycleRows = sumPerRow[maxCycle[0]]
     161
     162    # expected handoff is MULT P( handoff ) for each handoff in max cycle
     163    expectedConvoy = handoff[maxCycle[-1]][maxCycle[0]] / sumPerRow[maxCycle[-1]]
     164    for idx, val in enumerate(maxCycle[1:]):
     165        cycleHandoffs.append(handoff[maxCycle[idx]][val])
     166        sumOfMaxCycleRows += sumPerRow[val]
     167        expectedConvoy = expectedConvoy * handoff[maxCycle[idx]][val] / sumPerRow[maxCycle[idx]]
     168
     169    # adjust expected bound
     170    # if max cycle contains all nodes, sumOfMaxCycleRows / handoffTotal == 1
     171    # else this adjusts the expected bound to compensate for the cycle not visiting all nodes
     172    # also mult by 100 to turn into percentage from decimal
     173    expectedConvoy = expectedConvoy * sumOfMaxCycleRows * 100 / handoffTotal
    201174
    202175    # upper bound is the percentage of all handoffs that occur in the maximum possible cycle
Note: See TracChangeset for help on using the changeset viewer.