本文整理汇总了Python中Graph.Graph.euclidian方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.euclidian方法的具体用法?Python Graph.euclidian怎么用?Python Graph.euclidian使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph.Graph
的用法示例。
在下文中一共展示了Graph.euclidian方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NewGraph
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import euclidian [as 别名]
def NewGraph(self, Directed=1, Euclidean=1, IntegerVertexWeights=0, VertexWeights='None',
IntegerEdgeWeights=0, EdgeWeights='One', Grid=1):
if self.dirty == 1:
if not askokcancel("New Graph","Graph changed since last saved. Do you want to overwrite it?"):
return
G=None
self.SetGraphMenuDirected(Directed)
self.SetGraphMenuEuclidean(Euclidean)
self.SetGraphMenuIntegerVertexWeights(IntegerVertexWeights)
self.SetGraphMenuVertexWeights(VertexWeights)
self.SetGraphMenuIntegerEdgeWeights(IntegerEdgeWeights)
self.SetGraphMenuEdgeWeights(EdgeWeights)
self.SetGraphMenuGrid(Grid)
self.defaultButton.select()
G = Graph()
G.directed = Directed
G.euclidian = Euclidean
self.graphName = "New"
self.ShowGraph(G,self.graphName)
self.RegisterGraphInformer(WeightedGraphInformer(G,"weight"))
self.fileName = None
self.makeDirty()
self.dirty = 0
self.SetTitle("Gred %s - New Graph" % gatoVersion)
示例2: OpenCATBoxGraph
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import euclidian [as 别名]
def OpenCATBoxGraph(_file):
""" Reads in a graph from file fileName. File-format is supposed
to be from old CATBOX++ (*.cat) """
G = Graph()
E = VertexLabeling()
W = EdgeWeight(G)
L = VertexLabeling()
# get file from name or file object
graphFile=None
if type(_file) in types.StringTypes:
graphFile = open(_file, 'r')
elif type(_file)==types.FileType or issubclass(_file.__class__,StringIO.StringIO):
graphFile=_file
else:
raise Exception("got wrong argument")
lineNr = 1
firstVertexLineNr = -1
lastVertexLineNr = -1
firstEdgeLineNr = -1
lastEdgeLineNr = -1
intWeights = 0
while 1:
line = graphFile.readline()
if not line:
break
if lineNr == 2: # Read directed and euclidian
splitLine = split(line[:-1],';')
G.directed = eval(split(splitLine[0],':')[1])
G.simple = eval(split(splitLine[1],':')[1])
G.euclidian = eval(split(splitLine[2],':')[1])
intWeights = eval(split(splitLine[3],':')[1])
nrOfEdgeWeights = eval(split(splitLine[4],':')[1])
nrOfVertexWeights = eval(split(splitLine[5],':')[1])
for i in xrange(nrOfEdgeWeights):
G.edgeWeights[i] = EdgeWeight(G)
for i in xrange(nrOfVertexWeights):
G.vertexWeights[i] = VertexWeight(G)
if lineNr == 5: # Read nr of vertices
nrOfVertices = eval(split(line[:-2],':')[1]) # Strip of "\n" and ;
firstVertexLineNr = lineNr + 1
lastVertexLineNr = lineNr + nrOfVertices
if firstVertexLineNr <= lineNr and lineNr <= lastVertexLineNr:
splitLine = split(line[:-1],';')
v = G.AddVertex()
x = eval(split(splitLine[1],':')[1])
y = eval(split(splitLine[2],':')[1])
for i in xrange(nrOfVertexWeights):
w = eval(split(splitLine[3+i],':')[1])
G.vertexWeights[i][v] = w
E[v] = Point2D(x,y)
if lineNr == lastVertexLineNr + 1: # Read Nr of edges
nrOfEdges = eval(split(line[:-2],':')[1]) # Strip of "\n" and ;
firstEdgeLineNr = lineNr + 1
lastEdgeLineNr = lineNr + nrOfEdges
if firstEdgeLineNr <= lineNr and lineNr <= lastEdgeLineNr:
splitLine = split(line[:-1],';')
h = eval(split(splitLine[0],':')[1])
t = eval(split(splitLine[1],':')[1])
G.AddEdge(t,h)
for i in xrange(nrOfEdgeWeights):
G.edgeWeights[i][(t,h)] = eval(split(splitLine[3+i],':')[1])
lineNr = lineNr + 1
graphFile.close()
for v in G.vertices:
L[v] = v
G.embedding = E
G.labeling = L
if intWeights:
G.Integerize('all')
for i in xrange(nrOfVertexWeights):
G.vertexWeights[i].Integerize()
return G