コード例 #1
0
def compStructure(v1, v2):
    nr_v = len(v1)

    G1 = Graph()
    G2 = Graph()

    for p in range(len(v1[0])):

        for i in range(1, nr_v + 1):
            G1.AddVertex()
            G2.AddVertex()

        # finding number of unique entries in v1 and v2
        d_v1 = {}
        d_v2 = {}

        v1_ind = 0
        v2_ind = 0
        for i in range(nr_v):
            if not d_v1.has_key(v1[i, p]):
                t = numarray.where(v1[:, p] == v1[i, p])
                #             d_v1[v1[i,p]] =

                v1_ind += 1
            if not d_v2.has_key(v2[i, p]):
                d_v2[v2[i, p]] = v2_ind
                v2_ind += 1
コード例 #2
0
ファイル: GraphCreator.py プロジェクト: pydvlpr/Gato
 def Create(self, theGraphEditor):
     theGraphEditor.config(cursor="watch")
     
     dial = TreeDialog(theGraphEditor, 0, "Create Complete Tree")
     if dial.result is None:
         theGraphEditor.config(cursor="")
         return
         
     degree=dial.result[0]
     height=dial.result[1]
     direction=dial.result[3]
     layout=dial.result[4]
     
     G=Graph()
     G.directed=direction
     
     nodes={}
     nodes[0]=[]
     G.AddVertex()
     nodes[0].append(G.vertices[0])
     for h in range(0,height):
         nodes[h+1]=[]
         for v in nodes[h]:
             for d in range(0,degree):
                 new_v=G.AddVertex()
                 if direction==0: 
                     G.AddEdge(v,new_v, initialize_weight=False)
                 else:
                     if random.randint(0,1):
                         G.AddEdge(v,new_v, initialize_weight=False)
                     else:
                         G.AddEdge(new_v,v, initialize_weight=False)
                 nodes[h+1].append(new_v)
                 
     if layout==0:
         if RandomCoords(G):
             DrawNewGraph(theGraphEditor,G,direction) 
     elif layout==1:
         if CircularCoords(G):
             DrawNewGraph(theGraphEditor,G,direction) 
     elif layout==2:
         if TreeCoords(G,G.vertices[0],"vertical"):
             DrawNewGraph(theGraphEditor,G,direction) 
     else:
         if BFSTreeCoords(G,G.vertices[0],"forward"):
             DrawNewGraph(theGraphEditor,G,direction) 
             
     theGraphEditor.config(cursor="")
コード例 #3
0
ファイル: GraphCreator.py プロジェクト: pydvlpr/Gato
 def Create(self, theGraphEditor):
     theGraphEditor.config(cursor="watch")
     
     dial = Dialog(theGraphEditor, 0, 1, "Create Random Graph")
     if dial.result is None:
         theGraphEditor.config(cursor="")
         return
         
     n=dial.result[0]
     m=dial.result[1]
     direction=dial.result[2]
     layout=dial.result[3]
     
     G=Graph()
     G.directed=direction
     
     for v in range(0,n):
         G.AddVertex()
         
     Edges=CompleteEdges(G,n,direction)
     
     for i in range(0,m):
         pos=random.randint(0,len(Edges)-1)
         G.AddEdge(Edges[pos][0],Edges[pos][1], initialize_weight=False)
         del Edges[pos]
         
     if layout==0:
         if RandomCoords(G):
             DrawNewGraph(theGraphEditor,G,direction)
     else:
         if CircularCoords(G):
             DrawNewGraph(theGraphEditor,G,direction) 
             
     theGraphEditor.config(cursor="")          
コード例 #4
0
ファイル: GraphCreator.py プロジェクト: pydvlpr/Gato
 def Create(self, theGraphEditor):
     theGraphEditor.config(cursor="watch")
     
     dial = Dialog(theGraphEditor, 0, 0, "Create Complete Graph")
     if dial.result is None:
         theGraphEditor.config(cursor="")	    
         return
     
     n=dial.result[0]
     direction=dial.result[2]
     layout=dial.result[3]
     
     G=Graph()
     G.directed=direction
     
     for v in range(0,n):
         G.AddVertex()
         
     Edges=CompleteEdges(G,n,direction)
     
     for e in Edges:
         G.AddEdge(e[0],e[1], initialize_weight=False)
         
     if layout==0:
         if RandomCoords(G):
             DrawNewGraph(theGraphEditor,G,direction)
     else:
         if CircularCoords(G):
             DrawNewGraph(theGraphEditor,G,direction)
             
     theGraphEditor.config(cursor="")
コード例 #5
0
    def Create(self, theGraphEditor):
        theGraphEditor.config(cursor="watch")

        dial = Dialog(theGraphEditor, 1, 1, "Create Random Planar Graph")
        if dial.result is None:
            theGraphEditor.config(cursor="")
            return

        n = dial.result[0]
        if n <= 1: return
        m = dial.result[1]
        direction = dial.result[2]
        layout = dial.result[3]

        G = Graph()
        G.directed = direction

        for v in range(0, n):
            G.AddVertex()

        Edges = MaximalPlanarEdges(G, n, direction)

        for i in range(0, m):
            pos = random.randint(0, len(Edges) - 1)
            G.AddEdge(Edges[pos][0], Edges[pos][1])
            del Edges[pos]

        if layout == 0:
            if RandomCoords(G):
                DrawNewGraph(theGraphEditor, G, direction)
        elif layout == 1:
            if CircularCoords(G):
                DrawNewGraph(theGraphEditor, G, direction)
        elif layout == 2:
            if FPP_PlanarCoords(G):
                DrawNewGraph(theGraphEditor, G, direction)
        else:
            if Schnyder_PlanarCoords(G):
                DrawNewGraph(theGraphEditor, G, direction)

        theGraphEditor.config(cursor="")
コード例 #6
0
ファイル: GraphCreator.py プロジェクト: pydvlpr/Gato
    def Create(self, theGraphEditor):

        theGraphEditor.config(cursor="watch")
        dial = GridDialog(theGraphEditor, 1, "Create Grid Graph")
        if dial.result is None:
            theGraphEditor.config(cursor="")
            return

        maxI = dial.result[0]
        maxJ = dial.result[1]
        deltax = dial.result[2]
        deltay = dial.result[2]
        
        G=Graph()
        G.directed=0
        G.xCoord={}
        G.yCoord={}
        
        nodes = {}
        count = 1
        for i in xrange(maxI):
            for j in xrange(maxJ):
                v = G.AddVertex()
                nodes[(i,j)] = v
                G.xCoord[v] = j * deltax + deltax
                G.yCoord[v] = i * deltay + deltay
                count += 1
                
        for i in xrange(maxI-1):
            for j in xrange(maxJ-1):
                G.AddEdge(nodes[(i,j)], nodes[(i+1,j)], initialize_weight=False)
                G.AddEdge(nodes[(i,j)], nodes[(i,j+1)], initialize_weight=False)
            G.AddEdge(nodes[(i,maxJ-1)], nodes[(i+1,maxJ-1)], initialize_weight=False)
        for  j in xrange(maxJ-1):
            G.AddEdge(nodes[(maxI-1,j)], nodes[(maxI-1,j+1)], initialize_weight=False)
            
        DrawNewGraph(theGraphEditor,G,G.directed) 
        theGraphEditor.config(cursor="")
コード例 #7
0
ファイル: GraphCreator.py プロジェクト: pydvlpr/Gato
 def Create(self, theGraphEditor):
     theGraphEditor.config(cursor="watch")
     
     dial = Dialog(theGraphEditor, 1, 0, "Create Maximal Planar Graph")
     if dial.result is None:
         theGraphEditor.config(cursor="")
         return
         
     n=dial.result[0]
     if n<=1: return
     direction=dial.result[2]
     layout=dial.result[3]
     
     G=Graph()
     G.directed=direction
     
     for v in range(0,n):
         G.AddVertex()
         
     Edges=MaximalPlanarEdges(G,n,direction)
     
     for e in Edges:
         G.AddEdge(e[0],e[1], initialize_weight=False)
         
     if layout==0:
         if RandomCoords(G):
             DrawNewGraph(theGraphEditor,G,direction)
     elif layout==1:
         if CircularCoords(G):
             DrawNewGraph(theGraphEditor,G,direction)
     elif layout==2:
         if FPP_PlanarCoords(G):
             DrawNewGraph(theGraphEditor,G,direction)
     else:
         if Schnyder_PlanarCoords(G):
             DrawNewGraph(theGraphEditor,G,direction)  
             
     theGraphEditor.config(cursor="")
コード例 #8
0
    def Create(self, theGraphEditor):
        theGraphEditor.config(cursor="watch")

        print " FIXME XXX Dialog for #x, #y, delta_x, delta_y is missing"
        ##         dial = TreeDialog(theGraphEditor, 1, "create random tree")
        ##         if dial.result is None:
        ## 	    theGraphEditor.config(cursor="")
        ##             return

        G = Graph()
        G.directed = 0
        G.xCoord = {}
        G.yCoord = {}

        maxI = 10
        maxJ = 8

        nodes = {}
        count = 1
        for i in xrange(maxI):
            for j in xrange(maxJ):
                v = G.AddVertex()
                nodes[(i, j)] = v
                G.xCoord[v] = j * 40 + 40
                G.yCoord[v] = i * 40 + 40
                count += 1

        for i in xrange(maxI - 1):
            for j in xrange(maxJ - 1):
                G.AddEdge(nodes[(i, j)], nodes[(i + 1, j)])
                G.AddEdge(nodes[(i, j)], nodes[(i, j + 1)])
            G.AddEdge(nodes[(i, maxJ - 1)], nodes[(i + 1, maxJ - 1)])
        for j in xrange(maxJ - 1):
            G.AddEdge(nodes[(maxI - 1, j)], nodes[(maxI - 1, j + 1)])

        DrawNewGraph(theGraphEditor, G, G.directed)
        theGraphEditor.config(cursor="")
コード例 #9
0
ファイル: GraphCreator.py プロジェクト: pydvlpr/Gato
 def Create(self, theGraphEditor):
     theGraphEditor.config(cursor="watch")
     
     dial = TreeDialog(theGraphEditor, 1, "Create Random Tree")
     if dial.result is None:
         theGraphEditor.config(cursor="")
         return
         
     degree=dial.result[0]
     height=dial.result[1]
     n=dial.result[2]
     direction=dial.result[3]
     layout=dial.result[4]
     
     G=Graph()
     G.directed=direction
     
     nodes={}
     nodes[0]=[]
     new_v=G.AddVertex()
     nodes[0].append(new_v)
     children_nr={}
     children_nr[new_v]=0
     for h in range(0,height):
         nodes[h+1]=[]
         if degree==1:
             min_nodes=1
             max_nodes=1
         else:
             min_nodes=max(1,ceil(float(n-G.Order())/
                                  float((float(degree)**(height-h)-1)/
                                        (degree-1))))
             max_nodes=min(n-G.Order()-height+h+1,len(nodes[h])*degree)     
         nodes_nr=random.randint(min_nodes,max_nodes)
         for i in range(0,nodes_nr):
             pos=random.randint(0,len(nodes[h])-1)
             v=nodes[h][pos]
             children_nr[v]=children_nr[v]+1
             if children_nr[v]==degree:
                 del nodes[h][pos]
             new_v=G.AddVertex()
             children_nr[new_v]=0
             if direction==0:
                 G.AddEdge(v,new_v, initialize_weight=False)
             else:
                 if random.randint(0,1):
                     G.AddEdge(v,new_v, initialize_weight=False)
                 else:
                     G.AddEdge(new_v,v, initialize_weight=False)
             nodes[h+1].append(new_v)
             
     if layout==0:
         if RandomCoords(G):
             DrawNewGraph(theGraphEditor,G,direction) 
     elif layout==1:
         if CircularCoords(G):
             DrawNewGraph(theGraphEditor,G,direction) 
     elif layout==2:
         if TreeCoords(G,G.vertices[0],"vertical"):
             DrawNewGraph(theGraphEditor,G,direction) 
     else:
         if BFSTreeCoords(G,G.vertices[0],"forward"):
             DrawNewGraph(theGraphEditor,G,direction) 
             
     theGraphEditor.config(cursor="")