本文整理汇总了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()
示例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))