本文整理汇总了Python中sage.graphs.digraph.DiGraph.shortest_path方法的典型用法代码示例。如果您正苦于以下问题:Python DiGraph.shortest_path方法的具体用法?Python DiGraph.shortest_path怎么用?Python DiGraph.shortest_path使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类sage.graphs.digraph.DiGraph
的用法示例。
在下文中一共展示了DiGraph.shortest_path方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ParentBigOh
# 需要导入模块: from sage.graphs.digraph import DiGraph [as 别名]
# 或者: from sage.graphs.digraph.DiGraph import shortest_path [as 别名]
class ParentBigOh(Parent,UniqueRepresentation):
def __init__(self,ambiant):
try:
self._uniformizer = ambiant.uniformizer_name()
except NotImplementedError:
raise TypeError("Impossible to determine the name of the uniformizer")
self._ambiant_space = ambiant
self._models = DiGraph(loops=False)
self._default_model = None
Parent.__init__(self,ambiant.base_ring())
if self.base_ring() is None:
self._base_precision = None
else:
if self.base_ring() == ambiant:
self._base_precision = self
else:
self._base_precision = ParentBigOh(self.base_ring())
def __hash__(self):
return id(self)
def base_precision(self):
return self._base_precision
def precision(self):
return self._precision
def default_model(self):
if self._default_mode is None:
self.set_default_model()
return self._default_model
def set_default_model(self,model=None):
if model is None:
self._default_model = self._models.topological_sort()[-1]
else:
if self._models.has_vertex(model):
self._default_model = model
else:
raise ValueError
def add_model(self,model):
from bigoh import BigOh
if not isinstance(model,list):
model = [model]
for m in model:
if not issubclass(m,BigOh):
raise TypeError("A precision model must derive from BigOh but '%s' is not"%m)
self._models.add_vertex(m)
def delete_model(self,model):
if isinstance(model,list):
model = [model]
for m in model:
if self._models.has_vertex(m):
self._models.delete_vertex(m)
def update_model(self,old,new):
from bigoh import BigOh
if self._models.has_vertex(old):
if not issubclass(new,BigOh):
raise TypeError("A precision model must derive from BigOh but '%s' is not"%new)
self._models.relabel({old:new})
else:
raise ValueError("Model '%m' does not exist"%old)
def add_modelconversion(self,domain,codomain,constructor=None,safemode=False):
if not self._models.has_vertex(domain):
if safemode: return
raise ValueError("Model '%s' does not exist"%domain)
if not self._models.has_vertex(codomain):
if safemode: return
raise ValueError("Model '%s' does not exist"%codomain)
path = self._models.shortest_path(codomain,domain)
if len(path) > 0:
raise ValueError("Adding this conversion creates a cycle")
self._models.add_edge(domain,codomain,constructor)
def delete_modelconversion(self,domain,codomain):
if not self._models.has_vertex(domain):
raise ValueError("Model '%s' does not exist"%domain)
if not self._models.has_vertex(codomain):
raise ValueError("Model '%s' does not exist"%codomain)
if not self._models_has_edge(domain,codomain):
raise ValueError("No conversion from %s to %s"%(domain,codomain))
self._modelfs.delete_edge(domain,codomain)
def uniformizer_name(self):
return self._uniformizer
def ambiant_space(self):
return self._ambiant_space
# ?!?
def __call__(self,*args,**kwargs):
return self._element_constructor_(*args,**kwargs)
def _element_constructor_(self, *args, **kwargs):
if kwargs.has_key('model'):
del kwargs['model']
#.........这里部分代码省略.........