本文整理汇总了Python中sage.graphs.graph.Graph.order方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.order方法的具体用法?Python Graph.order怎么用?Python Graph.order使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.graphs.graph.Graph
的用法示例。
在下文中一共展示了Graph.order方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: import_graphs
# 需要导入模块: from sage.graphs.graph import Graph [as 别名]
# 或者: from sage.graphs.graph.Graph import order [as 别名]
def import_graphs(file, cl = ZooGraph, db = None, format = "sparse6",
index = "index", verbose = False):
r"""
Import graphs from ``file`` into the database.
This function is used to import new censuses of graphs and is not meant
to be used by users of DiscreteZOO.
To properly import the graphs, all graphs of the same order must be
together in the file, and no graph of this order must be present in the
database.
INPUT:
- ``file`` - the filename containing a graph in each line.
- ``cl`` - the class to be used for imported graphs
(default: ``ZooGraph``).
- ``db`` - the database to import into. The default value of ``None`` means
that the default database should be used.
- ``format`` - the format the graphs are given in. If ``format`` is
``'graph6'`` or ``'sparse6'`` (default), then the graphs are read as
strings, otherwised they are evaluated as Python expressions before
being passed to Sage's ``Graph``.
- ``index``: the name of the parameter of the constructor of ``cl``
to which the serial number of the graph of a given order is passed.
- ``verbose``: whether to print information about the progress of importing
(default: ``False``).
"""
info = ZooInfo(cl)
if db is None:
db = info.getdb()
info.initdb(db = db, commit = False)
previous = 0
i = 0
cur = db.cursor()
with open(file) as f:
for line in f:
data = line.strip()
if format not in ["graph6", "sparse6"]:
data = eval(data)
g = Graph(data)
n = g.order()
if n > previous:
if verbose and previous > 0:
print "Imported %d graphs of order %d" % (i, previous)
previous = n
i = 0
i += 1
cl(graph = g, order = n, cur = cur, db = db, **{index: i})
if verbose:
print "Imported %d graphs of order %d" % (i, n)
f.close()
cur.close()
db.commit()