本文整理汇总了Python中Graph.Graph.directed方法的典型用法代码示例。如果您正苦于以下问题:Python Graph.directed方法的具体用法?Python Graph.directed怎么用?Python Graph.directed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Graph.Graph
的用法示例。
在下文中一共展示了Graph.directed方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: NewGraph
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import directed [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: OpenDotGraph
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import directed [as 别名]
def OpenDotGraph(fileName):
""" Reads in a graph from file fileName. File-format is supposed
to be dot (*.dot) used in """
G = Graph()
G.directed = 1
E = VertexLabeling()
W = EdgeWeight(G)
L = VertexLabeling()
VLabel = VertexLabeling()
ELabel = EdgeLabeling()
import re
file = open(fileName, 'r')
lines = file.readlines()
file.close()
dot2graph = {}
for l in lines[3:]:
items = string.split(l)
if len(items) < 2:
break
if items[1] != '->':
v = G.AddVertex()
dot_v = int(items[0])
L[v] = "%d" % dot_v
dot2graph[dot_v] = v
m = re.search('label=("[^"]+")', l)
VLabel[v] = m.group(1)[1:-1]
m = re.search('pos="(\d+),(\d+)"', l)
x = int(m.group(1))
y = int(m.group(2))
E[v] = Point2D(x,y)
else:
m = re.search('(\d+) -> (\d+)', l)
v = dot2graph[int(m.group(1))]
w = dot2graph[int(m.group(2))]
m = re.search('label=("[^"]+")', l)
#print l
#print v,w,m.group(1)
G.AddEdge(v,w)
weight = float(m.group(1)[1:-1])
W[(v,w)] = weight
ELabel[(v,w)] = "%0.2f" % weight
G.embedding = E
G.labeling = L
G.nrEdgeWeights = 1
G.edgeWeights[0] = W
G.vertexAnnotation = VLabel
G.edgeAnnotation = ELabel
return G
示例3: OpenGMLGraph
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import directed [as 别名]
def OpenGMLGraph(fileName):
""" Reads in a graph from file fileName. File-format is supposed
to be GML (*.gml) """
G = Graph()
G.directed = 0
E = VertexLabeling()
W = EdgeWeight(G)
L = VertexLabeling()
VLabel = VertexLabeling()
ELabel = EdgeLabeling()
file = open(fileName, 'r')
g = ParseGML(file)
file.close()
if g[0][0] != 'graph':
log.error("Serious format error in %s. first key is not graph" % fileName)
return
else:
l = g[0][1]
for i in xrange(len(l)):
key = l[i][0]
value = l[i][1]
if key == 'node':
d = PairListToDictionary(value)
v = G.AddVertex()
try:
VLabel[v] = eval(d['label'])
P = PairListToDictionary(d['graphics'])
E[v] = Point2D(eval(P['x']), eval(P['y']))
except:
d = None
P = None
elif key == 'edge':
d = PairListToDictionary(value)
try:
s = eval(d['source'])
t = eval(d['target'])
G.AddEdge(s,t)
ELabel[(s,t)] = eval(d['label'])
W[(s,t)] = 0
except:
d = None
elif key == 'directed':
G.directed = 1
for v in G.vertices:
L[v] = v
G.embedding = E
G.labeling = L
G.nrEdgeWeights = 1
G.edgeWeights[0] = W
G.vertexAnnotation = VLabel
G.edgeAnnotation = ELabel
return G
示例4: OpenCATBoxGraph
# 需要导入模块: from Graph import Graph [as 别名]
# 或者: from Graph.Graph import directed [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