當前位置: 首頁>>代碼示例>>Python>>正文


Python networkx.read_yaml方法代碼示例

本文整理匯總了Python中networkx.read_yaml方法的典型用法代碼示例。如果您正苦於以下問題:Python networkx.read_yaml方法的具體用法?Python networkx.read_yaml怎麽用?Python networkx.read_yaml使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在networkx的用法示例。


在下文中一共展示了networkx.read_yaml方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: read_graph

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import read_yaml [as 別名]
def read_graph(self, subgraph_file=None):
        if subgraph_file is None:
            subraph_file = self.context_graph_file
        logging.info("Writing graph.")
        # write the graph out
        file_format = subgraph_file.split(".")[-1]
        if file_format == "graphml":
            return nx.read_graphml(subgraph_file)
        elif file_format == "gml":
            return nx.read_gml(subgraph_file)
        elif file_format == "gexf":
            return nx.read_gexf(subgraph_file)
        elif file_format == "net":
            return nx.read_pajek(subgraph_file)
        elif file_format == "yaml":
            return nx.read_yaml(subgraph_file)
        elif file_format == "gpickle":
            return nx.read_gpickle(subgraph_file)
        else:
            logging.warning("File format not found, returning empty graph.")
        return nx.MultiDiGraph() 
開發者ID:vz-risk,項目名稱:Verum,代碼行數:23,代碼來源:networkx.py

示例2: graph_generator

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import read_yaml [as 別名]
def graph_generator(model, graph_param, save_path, file_name):
    graph_param[0] = int(graph_param[0])
    if model == 'ws':
        graph_param[1] = int(graph_param[1])
        graph = nx.random_graphs.connected_watts_strogatz_graph(*graph_param)
    elif model == 'er':
        graph = nx.random_graphs.erdos_renyi_graph(*graph_param)
    elif model == 'ba':
        graph_param[1] = int(graph_param[1])
        graph = nx.random_graphs.barabasi_albert_graph(*graph_param)

    if os.path.isfile(save_path + '/' + file_name + '.yaml') is True:
        print('graph loaded')
        dgraph = nx.read_yaml(save_path + '/' + file_name + '.yaml')

    else:
        dgraph = nx.DiGraph()
        dgraph.add_nodes_from(graph.nodes)
        dgraph.add_edges_from(graph.edges)

    in_node = []
    out_node = []
    for indeg, outdeg in zip(dgraph.in_degree, dgraph.out_degree):
        if indeg[1] == 0:
            in_node.append(indeg[0])
        elif outdeg[1] == 0:
            out_node.append(outdeg[0])
    # print(in_node, out_node)
    sorted = list(nx.topological_sort(dgraph))
    # nx.draw(dgraph)
    # plt.draw()
    # plt.show()

    if os.path.isdir(save_path) is False:
        os.makedirs(save_path)

    if os.path.isfile(save_path + '/' + file_name + '.yaml') is False:
        print('graph_saved')
        nx.write_yaml(dgraph, save_path + '/' + file_name + '.yaml')

    return dgraph, sorted, in_node, out_node 
開發者ID:swdsld,項目名稱:RandWire_tensorflow,代碼行數:43,代碼來源:graph_generator.py

示例3: read_yaml

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import read_yaml [as 別名]
def read_yaml(path):
    """Read graph in YAML format from path.

    YAML is a data serialization format designed for human readability 
    and interaction with scripting languages [1]_.

    Parameters
    ----------
    path : file or string
       File or filename to read.  Filenames ending in .gz or .bz2 
       will be uncompressed.

    Returns
    -------
    G : NetworkX graph

    Examples
    --------
    >>> G=nx.path_graph(4)
    >>> nx.write_yaml(G,'test.yaml')
    >>> G=nx.read_yaml('test.yaml')
 
    References
    ----------
    .. [1] http://www.yaml.org

    """
    try:
        import yaml
    except ImportError:
        raise ImportError("read_yaml() requires PyYAML: http://pyyaml.org/")

    G=yaml.load(path)
    return G


# fixture for nose tests 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:39,代碼來源:nx_yaml.py

示例4: assert_equal

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import read_yaml [as 別名]
def assert_equal(self, G, data=False):
        (fd, fname) = tempfile.mkstemp()
        nx.write_yaml(G, fname)
        Gin = nx.read_yaml(fname);

        assert_nodes_equal(G.nodes(), Gin.nodes())
        assert_edges_equal(G.edges(data=data), Gin.edges(data=data))

        os.close(fd)
        os.unlink(fname) 
開發者ID:SpaceGroupUCL,項目名稱:qgisSpaceSyntaxToolkit,代碼行數:12,代碼來源:test_yaml.py

示例5: read_yaml

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import read_yaml [as 別名]
def read_yaml(path):
    """Read graph in YAML format from path.

    YAML is a data serialization format designed for human readability 
    and interaction with scripting languages [1]_.

    Parameters
    ----------
    path : file or string
       File or filename to read.  Filenames ending in .gz or .bz2 
       will be uncompressed.

    Returns
    -------
    G : NetworkX graph

    Examples
    --------
    >>> G=nx.path_graph(4)
    >>> nx.write_yaml(G,'test.yaml')
    >>> G=nx.read_yaml('test.yaml')

    References
    ----------
    .. [1] http://www.yaml.org

    """
    try:
        import yaml
    except ImportError:
        raise ImportError("read_yaml() requires PyYAML: http://pyyaml.org/")

    G = yaml.load(path, Loader=yaml.FullLoader)
    return G


# fixture for nose tests 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:39,代碼來源:nx_yaml.py

示例6: assert_equal

# 需要導入模塊: import networkx [as 別名]
# 或者: from networkx import read_yaml [as 別名]
def assert_equal(self, G, data=False):
        (fd, fname) = tempfile.mkstemp()
        nx.write_yaml(G, fname)
        Gin = nx.read_yaml(fname)

        assert_nodes_equal(list(G), list(Gin))
        assert_edges_equal(G.edges(data=data), Gin.edges(data=data))

        os.close(fd)
        os.unlink(fname) 
開發者ID:holzschu,項目名稱:Carnets,代碼行數:12,代碼來源:test_yaml.py


注:本文中的networkx.read_yaml方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。