当前位置: 首页>>代码示例>>Python>>正文


Python AutoNetkit.load_graphml方法代码示例

本文整理汇总了Python中AutoNetkit.load_graphml方法的典型用法代码示例。如果您正苦于以下问题:Python AutoNetkit.load_graphml方法的具体用法?Python AutoNetkit.load_graphml怎么用?Python AutoNetkit.load_graphml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在AutoNetkit的用法示例。


在下文中一共展示了AutoNetkit.load_graphml方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: load

# 需要导入模块: import AutoNetkit [as 别名]
# 或者: from AutoNetkit import load_graphml [as 别名]
    def load(self, filename):   
        """Loads the network description from a graph file.
        Note this is done automatically if a filename is given to
        the Internet constructor.

        Args:
           filename:    The file to load from

        Returns:
           None

        Example usage:

        >>> inet = ank.internet.Internet()
        >>> inet.load("simple")
        >>> sorted(inet.network.graph.nodes())
        [RouterB.AS1, RouterA.AS1, RouterD.AS2, RouterC.AS1, RouterA.AS2, RouterA.AS3, RouterB.AS2, RouterC.AS2]

        >>> inet = ank.internet.Internet()
        >>> inet.load("singleas")
        >>> sorted(inet.network.graph.nodes())
        [1a.AS1, 1b.AS1, 1d.AS1, 1c.AS1]

        >>> inet = ank.internet.Internet()
        >>> inet.load("multias")
        >>> sorted(inet.network.graph.nodes())
        [1b.AS1, 1a.AS1, 2d.AS2, 1c.AS1, 2a.AS2, 3a.AS3, 2b.AS2, 2c.AS2]

        """
        LOG.info("Loading")
        ext = os.path.splitext(filename)[1]
        if ext == "":
            #TODO: use try/except block here
            self.network.graph = ank.load_example(filename)

#TODO: allow url to be entered, eg from zoo, if so then download the file and proceed on as normal

        elif ext == ".gml":
            # GML file from Topology Zoo
            ank.load_zoo(self.network, filename)
        elif ext == ".graphml":
            self.network.graph = ank.load_graphml(filename)
        elif ext == ".pickle":
            LOG.warn("AutoNetkit no longer supports pickle file format, please use GraphML")
        elif ext == ".yaml":
            # Legacy ANK file format
            LOG.warn("AutoNetkit no longer supports YAML file format, please use GraphML")
        else:
            LOG.warn("AutoNetkit does not support file format %s" % ext)

        #TODO: check that loaded network has at least one node, if not throw exception
        self.network.instantiate_nodes()
开发者ID:coaj,项目名称:autonetkit,代码行数:54,代码来源:internet.py

示例2: load_example

# 需要导入模块: import AutoNetkit [as 别名]
# 或者: from AutoNetkit import load_graphml [as 别名]
def load_example(filename):
    """
    Load example network
    """
    # No extension, see if filename is an included example Topology
    topology_dir = resource_filename("AutoNetkit", os.path.join("lib", "examples", "topologies"))
    test_filename = os.path.join(topology_dir, "%s.graphml" % filename)
    if os.path.isfile(test_filename):
        LOG.info("Loading example topology %s " % filename)
        return ank.load_graphml(test_filename)
    else:
        example_files = glob.glob(topology_dir + os.sep + "*.graphml")
        # Remove path
        example_files = (os.path.split(filename)[1] for filename in example_files)
        # Remove extension
        example_files = (os.path.splitext(filename)[0] for filename in example_files)
        LOG.warn("Unable to find example topology %s" % filename)
        LOG.info("Valid example topologies are: " + ", ".join(example_files))
开发者ID:ntwrkguru,项目名称:autonetkit,代码行数:20,代码来源:example_topologies.py


注:本文中的AutoNetkit.load_graphml方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。