def network(self):
     row_no = self.tableWidget.rowCount()
     column_no = self.tableWidget.columnCount()
     row_no_list = list(range(0, row_no))
     column_no_list = list(range(0, column_no))
     in_concpets = []
     out_concepts = []
     relations = []
     for i in row_no_list:
         in_concpets.append(str(self.tableWidget.item(i, 0).text()))
     for j in row_no_list:
         out_concepts.append(str(self.tableWidget.item(j, 2).text()))
     for k in row_no_list:
         relations.append(str(self.tableWidget.item(k, 1).text()))
     print(in_concpets)
     G = nx.Graph()
     for i in list(zip(in_concpets, relations, out_concepts)):
         G.add_edge(i[0], i[1])
         G.add_edge(i[1], i[2])
         G.node[i[1]]['color'] = 'green'
         G.node[i[1]]['fill'] = 'green'
     G.remove_nodes_from(['.'])
     import config
     config.graph = G
     graph = G
     Ui_MainWindow.graph = G
     app = Viewer(G)
     app.mainloop()
Exemplo n.º 2
0
def draw():
    edge_list_path = r"edges.txt"
    DG = nx.read_edgelist(edge_list_path, create_using=nx.DiGraph())

    try:
        app = Viewer(DG)
        app.mainloop()
    except IndexError:
        print("(!) Citation network is empty. Try adding more papers...")
Exemplo n.º 3
0
import networkx as nx
from networkx_viewer import Viewer
G = nx.DiGraph()
G.add_edge('usb_uicc_daemon','usb_uicc_daemon')
G.edge['usb_uicc_daemon']['usb_uicc_daemon']['write-read'] = '[open open][write read][append read][open open][write read][add_name search][remove_name search][setattr getattr][write read][append read][setopt getopt][open open]'
G.add_edge('usb_uicc_daemon','usb_uicc_daemon')
G.edge['usb_uicc_daemon']['usb_uicc_daemon']['write-read'] = '[open open][write read][append read][open open][write read][add_name search][remove_name search][setattr getattr][write read][append read][setopt getopt][open open][write read]'
G.edge['usb_uicc_daemon']['usb_uicc_daemon']['fill'] = 'red'
G.add_edge('usb_uicc_daemon','usb_uicc_daemon')
G.edge['usb_uicc_daemon']['usb_uicc_daemon']['write-read'] = '[open open][write read][append read][open open][write read][add_name search][remove_name search][setattr getattr][write read][append read][setopt getopt][open open][write read][append read]'
app = Viewer(G)
app.mainloop()
Exemplo n.º 4
0
#app.mainloop()

## a union ##
#U = nx.Graph()
#U.add_edges_from(G.edges(data=True)+H.edges(data=True))

##U=nx.intersection(G,H)
###Ux=nx.disjoint_union(U,J)
##print U.nodes()
##app=Viewer(U)
##app.mainloop()

## MAIN ##
n = 3
T = n_disjoint_unions(G, n)

app = Viewer(T)
app.mainloop()

## I think it works!! Here is a quick rundown of the current process: takes a nx graph G and creates a disjoint union of G
## w itself n times. Then, looks thru the nodes of the new graph H and considers the degree centrality. This indicates
## that it is on the outside of the graph and can be connected to another. If it is sufficiently
## small, it adds it to a list of nodes w small degree. Then, scans thru this created list, adding edges between small degree nodes
## on each iteration of original G.

## ISSUES: 1) There are a couple nodes w less connections to other iterations, namely the first and last ones considered.
##         2) Will it work for n v large? (works n=3,5) DOES NOT WORK n=2 (a hardcoded pbm) (.1 is ideal for n=3 only)
##         3) The < value for degree centrality is currently hardcoded, based on my small test graph. Will need to be adjusted
##            for an actual street network. Is there a way to generalize this variable or should be determined empirically for each case?
##         4) A solution to above? Parse thru nodes and examine range of values to determine lowest, make if == this value.
Exemplo n.º 5
0
Arquivo: test.py Projeto: simdax/super
import networkx as nx
from networkx_viewer import Viewer

G = nx.MultiGraph()
G.add_edge('a','b')
G.add_edge('b','c')
G.add_edge('c','a',0,{'fill':'green'})
G.add_edge('c','d')
G.add_edge('c','d',1,{'dash':(2,2)})
G.node['a']['outline'] = 'blue'
G.node['d']['label_fill'] = 'red'

app = Viewer(G)
app.mainloop()
Exemplo n.º 6
0
def draw_Gui():
    app = Viewer(G)
    app.mainloop()
    # code to edit graph
    app.canvas.refresh()
Exemplo n.º 7
0
### Filter example
for n in G.nodes_iter():
    G.node[n]['real'] = True

# Now we're going to add a couple of "fake" nodes; IE, nodes
#  that should be not be displayed because they are not in the filter.
#  If they do show up, they'll cause us to fail some of the base checks
G.add_edge('out', 'fake1')
G.add_edge('a', 'fake2')
G.add_edge('qqqq', 'fake3')
G.add_edge('fake3', 'fake4')
G.add_node('fake_alone')
###

app = Viewer(G, home_node='a', levels=2)
#app = GraphViewerApp(G, home_node='a', levels=2)
#app.mainloop()

### Example 2 ###
G = nx.MultiGraph()
G.add_edge('a', 'b')
G.add_edge('b', 'c')
G.add_edge('c', 'a', 0, {'fill': 'green'})
G.add_edge('c', 'd')
G.add_edge('c', 'd', 1, {'dash': (2, 2)})
G.node['a']['outline'] = 'blue'
G.node['d']['label_fill'] = 'red'

app = Viewer(G)
app.mainloop()
Exemplo n.º 8
0
def draw_graph(graph_nodes):
    app=Viewer(graph_nodes)
    app.mainloop()
Exemplo n.º 9
0
import networkx as nx
from networkx_viewer import Viewer

u = nx.readwrite.read_gpickle('multiverse/universe_body_nodes_experi.uni')

app = Viewer(u)
app.mainloop()
    def run(self):
        # Set up the networkx graph/board
        G = nx.MultiGraph()
        G.add_node(self.num_points)
        G.add_edges_from(self.links)
        status = None

        # Color all nodes blue except for special nodes which are red
        for node in G.node:
            # red nodes are special
            if node not in self.special:
                G.node[node]["fill"] = "blue"

        # Designate which mode Player 1 will be
        first = raw_input("Who do you want to go first? Type SHORT or CUT>> ")
        if first.upper() == "SHORT":
            status = "SHORT"
        elif first.upper() == "CUT":
            status = "CUT"
        else:
            print "Bad input"
            sys.exit(1)

        playing = True

        # Once user has chosen the mode, start playing the game
        while playing:

            # Display the network using NetworkX Viewer for each loop
            Viewer(G).mainloop()

            # Display text to user and prompt for a move
            # the user input is stored in raw
            if status == "SHORT":
                print "\nSHORT's move. Type EXIT to end. a b to short the edge between a and b."
                raw = raw_input("What would you like to do? ")

            if status == "CUT":
                print "\nCUT's move. Type EXIT to end. a b to delete the edge between a and b."
                raw = raw_input("What would you like to do? ")

            # option to exit the game
            if raw.upper() == "EXIT":
                playing = False
                continue

            # option to display the board if the user forgets or closes by accident
            if raw.upper() == "SHOW BOARD":
                continue


            # play with the user input, which should be two integers
            else:
                if status == "SHORT":

                    try:
                        # maps the user input to two integers c,d
                        c, d = map(int, raw.split())

                        # switch the two values to keep the special node
                        # This is because contracted edge technically merges second node into the first node
                        if d in self.special:
                            c,d = d,c

                        # contracted_edge(network, location as tuple)
                        G = nx.contracted_edge(G,(c,d))

                        # If the code gets to this point, that means c and d are indeed connected
                        # Then we should see if we shorted the link between two special points
                        # If so, then we win!
                        if c in self.special and d in self.special:
                            print "Short wins"
                            playing=False

                        # Otherwise, it's the next player's turn
                        else:
                            status= "CUT"
                        continue
                    # If anything fails, then catch exception
                    except:
                        print "Bad input!"

                if status == "CUT":
                    # If you cut, the connection is gone

                    try:
                        a, b = map(int, raw.split()) #this works there just has to be a space between the two numbers
                        G.remove_edge(a,b)

                        # Check if there is any path between the two special points
                        # If not, cut wins!
                        if (nx.has_path(G,self.special[0],self.special[1])==False):
                            print "Cut wins"
                            playing= False

                        else:
                            # Next player's move
                            status="SHORT"
                        continue

                    except:
                        print "Bad input!"


        print "Bye!"
Exemplo n.º 11
0
def see_graph(g):
    # Viewer

    app	=	Viewer(g)
    app.mainloop()