Пример #1
0
def pygraphCrit(edgePairs, nameMap, timeMap, allEdts, allEvts, mainGuid):
    G = digraph()
    srcs = []
    dsts = []
    for i in range(len(edgePairs)):
        srcs.append(edgePairs[i][0])
        dsts.append(edgePairs[i][1])

    allNodes = set(srcs+dsts)
    for i in allNodes:
        if i == mainGuid:
            continue
        else:
            G.add_node(str(i))
    for i in range(len(edgePairs)):
        curTime = 0
        curSrc = str(edgePairs[i][0])
        curDst = str(edgePairs[i][1])
        if curSrc == mainGuid or curDst == mainGuid:
            continue
        if getNodeType(curSrc, allEdts, allEvts) == 'Event':
            curTime = 1
        else:
            curTime = edtGuidToTime(curSrc, timeMap)
        G.add_edge((curSrc, curDst), curTime)

    if len(critical_path(G)) == 0:
        print 'Cycle Detected, exiting; Please check that the OCR conifiguration file uses GUID type of COUNTED_MAP, and the application has no cycles.'
        print 'Dumping cycle below.'
        print find_cycle(G)
        os.remove(HTML_FILE_NAME)
        sys.exit(0)

    return critical_path(G)
Пример #2
0
def pygraphCrit(edgePairs, nameMap, timeMap, allEdts, allEvts, mainGuid):
    G = digraph()
    srcs = []
    dsts = []
    for i in range(len(edgePairs)):
        srcs.append(edgePairs[i][0])
        dsts.append(edgePairs[i][1])

    allNodes = set(srcs + dsts)
    for i in allNodes:
        if i == mainGuid:
            continue
        else:
            G.add_node(str(i))
    for i in range(len(edgePairs)):
        curTime = 0
        curSrc = str(edgePairs[i][0])
        curDst = str(edgePairs[i][1])
        if curSrc == mainGuid or curDst == mainGuid:
            continue
        if getNodeType(curSrc, allEdts, allEvts) == 'Event':
            curTime = 1
        else:
            curTime = edtGuidToTime(curSrc, timeMap)
        G.add_edge((curSrc, curDst), curTime)

    if len(critical_path(G)) == 0:
        print 'Cycle Detected, exiting; Please check that the OCR conifiguration file uses GUID type of COUNTED_MAP, and the application has no cycles.'
        print 'Dumping cycle below.'
        print find_cycle(G)
        os.remove(HTML_FILE_NAME)
        sys.exit(0)

    return critical_path(G)
Пример #3
0
 def test_critical_path(self):
     G = generate_test_graph()
     assert critical_path(G) == [1, 2, 3, 5, 6]
Пример #4
0
 def test_critical_path_with_cycle(self):
     G = generate_test_graph()
     G.add_edge((5, 2), 3)  #add cycle
     assert critical_path(G) == []
Пример #5
0
 def test_critical_path(self):
     G = generate_test_graph()
     assert critical_path(G) == [1,2,3,5,6]
Пример #6
0
 def test_critical_path_with_cycle(self):
     G = generate_test_graph()
     G.add_edge((5,2),3)#add cycle
     assert critical_path(G) == []
Пример #7
0
sys.path.append('..')
import pygraph
from pygraph.algorithms.critical import transitive_edges, critical_path

#demo of the critical path algorithm and the transitivity detection algorithm

G = pygraph.digraph()

G.add_node('A')
G.add_node('B')
G.add_node('C')
G.add_node('D')
G.add_node('E')
G.add_node('F')

G.add_edge('A','B',1)
G.add_edge('A','C',2)
G.add_edge('B','C',10)
G.add_edge('B','D',2)
G.add_edge('B','E',8)
G.add_edge('C','D',7)
G.add_edge('C','E',3)
G.add_edge('E','D',1)
G.add_edge('D','F',3)
G.add_edge('E','F',1)
#add this edge to add a cycle
#G.add_edge('E','A',1)

print transitive_edges(G)
print critical_path(G)