本文整理汇总了Python中edge.Edge类的典型用法代码示例。如果您正苦于以下问题:Python Edge类的具体用法?Python Edge怎么用?Python Edge使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Edge类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _proc_edge_stmt
def _proc_edge_stmt(self, toks):
""" Returns a tuple of the form (ADD_EDGE, src, dest, options).
"""
opts = toks[3]
dummy_edge = Edge("dummy1", "dummy2")
# Coerce attribute types.
for key, value in opts.iteritems():
trait = dummy_edge.trait(key)
if trait is not None:
# FIXME: Implement Graphviz spline types.
if trait.is_trait_type( List ):
p = [] # List of float doublets.
for t in value.split( " " ):
l = t.split( "," )
if len(l) == 3: # pos="e,39,61 39,97 39,89 39,80 39,71"
l.pop(0)
f = [ float(a) for a in l ]
p.append( tuple(f) )
opts[key] = p
elif trait.is_trait_type( Float ):
opts[key] = float( value )
elif trait.is_trait_type( Tuple ):
opts[key] = tuple( [float(c) for c in value.split(",")] )
return super(GodotDataParser, self)._proc_edge_stmt(toks)
示例2: __init__
def __init__(self, query=None, router=None):
self._events = {}
self._results = {}
self._query = query
if not query:
self._shadow = True
manager = Manager()
self._edge = Edge(core=manager.core)
self._vrtx = Vrtx(core=manager.core)
self._attr = Attr(core=manager.core)
self._data = Data(self._vrtx, self._edge, self._attr, core=manager.core)
from lib.link import Uplink
self._link = Uplink(manager)
else:
manager = None
self._shadow = False
self._edge = Edge(router=router)
self._vrtx = Vrtx(router=router)
self._attr = Attr(router=router, rdonly=False)
self._data = Data(self._vrtx, self._edge, self._attr, router=router, rdonly=False)
from lib.link import Downlink
link = Downlink(query)
self._query.link = link
self._link = link
self._manager = manager
self._lock = NamedLock()
if manager:
manager.start()
示例3: _get_link_details
def _get_link_details(entity, link_name):
""""Lookup the (edge_class, left_edge_id, right_edge_id, node_class)
for the given entity and link_name.
param entity: The current entity Node subclass
:param str link_name: The association proxy name
edge_class: The Edge subclass the association is proxied through
left_edge_id: The edge.{src,dst}_id
right_edge_id: The edge.{dst,src}_id (opposit of left_edge_id)
node_class: The target node the association_proxy points to
"""
# Look for the link_name in OUTBOUND edges from the current
# entity
for edge in Edge._get_edges_with_src(entity.__name__):
if edge.__src_dst_assoc__ == link_name:
return (edge, edge.src_id, edge.dst_id,
Node.get_subclass_named(edge.__dst_class__))
# Look for the link_name in INBOUND edges from the current
# entity
for edge in Edge._get_edges_with_dst(entity.__name__):
if edge.__dst_src_assoc__ == link_name:
return (edge, edge.dst_id, edge.src_id,
Node.get_subclass_named(edge.__src_class__))
raise AttributeError(
"type object '{}' has no attribute '{}'"
.format(entity.__name__, link_name))
示例4: __addNode
def __addNode(self, current_time, nodeStatData):
# adding nodes
key = nodeStatData[0] #(file_path, ligne_number, method_name)
value = nodeStatData[1] #(count, countWithRecursive, exclusiveTime, cummulatedTime, callersData)
node = self.__searchNode(key)
count_data = StampedData(value[0], value[1], value[2], value[3])
if node is None:
node = Node(key[0], key[1], key[2], self.__program_folder, self.__program_path)
self.__nodes.append(node)
node.setStats(current_time, count_data)
# adding edges
callersData = value[4]
for c in callersData.items():
caller = c[0] # same structure as key: (file_path, ligne_number, method_name)
callerStats = c[1] # same structure as value (without callersData): (count, countWithRecursive, exclusiveTime, cummulatedTime)
count_data = StampedData(callerStats[0], callerStats[1], callerStats[2], callerStats[3])
callerNode = self.__searchNode(caller)
if callerNode is None:
callerNode = Node(caller[0], caller[1], caller[2], self.__program_folder, self.__program_path)
self.__nodes.append(callerNode)
edge = self.__searchEdge(callerNode.getId(), node.getId())
if edge is None:
edge = Edge(callerNode.getId(), node.getId())
self.__edges.append(edge)
edge.setStats(current_time, count_data)
示例5: setUp
def setUp(self):
self.v1 = Vertex(1)
self.v2 = Vertex(2)
self.x = Vertex('x')
self.another_x = Vertex('x')
self.e12 = Edge(self.v1, self.v2)
self.e21 = Edge(self.v2, self.v1)
示例6: TestEdge
class TestEdge(unittest.TestCase):
def setUp(self):
self.v1 = Vertex(1)
self.v2 = Vertex(2)
self.x = Vertex('x')
self.another_x = Vertex('x')
self.e12 = Edge(self.v1, self.v2)
self.e21 = Edge(self.v2, self.v1)
def test_a_edge_cant_have_autoloop(self):
"""Uma aresta não possui autoloop"""
with self.assertRaises(Exception):
Edge(self.x, self.another_x)
def test_two_edges_are_equal_independent_of_vertices_order(self):
"""Duas arestas são iguais, independentemente da ordem dos vértice"""
self.assertEqual(self.e12, self.e21)
def test_incide(self):
"""Um Vértice incide numa aresta, se ele é um de seus componentes"""
self.assertTrue(self.e12.incide(self.v1))
self.assertTrue(self.e21.incide(self.v1))
self.assertTrue(self.e12.incide(self.v2))
self.assertTrue(self.e21.incide(self.v2))
self.assertFalse(self.e12.incide(self.x))
self.assertFalse(self.e21.incide(self.x))
self.assertTrue(self.x not in self.e21)
self.assertTrue(self.v1 in self.e12)
self.assertTrue(self.v1 in self.e21)
self.assertTrue(self.v2 in self.e12)
self.assertTrue(self.v2 in self.e12)
def test_adjacent(self):
"""Os vértices que são pontas das arestas são adjacentes"""
self.assertTrue(self.e12.adjacent(self.v1), self.v2)
self.assertTrue(self.e12.adjacent(self.v2), self.v1)
self.assertTrue(self.e21.adjacent(self.v1), self.v2)
self.assertTrue(self.e21.adjacent(self.v2), self.v1)
def test_adjacent_error(self):
"""Se um vértice não pertence à aresta, adjacent retorna um erro"""
with self.assertRaises(Exception):
self.e12.adjacent(self.x)
def test_edge_iteration(self):
"""É possível iterar sobre os vértices de uma aresta"""
i = 0
for u in self.e12:
if i == 0:
self.assertTrue(u == self.v1)
if i == 1:
self.assertTrue(u == self.v2)
i = i + 1
示例7: delete_all_edges
def delete_all_edges(options):
""" Function to delete all edges on given VSM
@param options cli options to this script
@return None
"""
edge = Edge(vsm_obj)
edges = (edge.query())
edge_id = None
for item in edges.edgePage.list_schema:
edge.id = item.objectId
edge.delete()
示例8: edge
def edge(self, value): # intermediates=set()
if value not in self.edges:
edge = Edge(value, self)
self.edges[value] = edge
for condition in value.conditions:
self.connector(condition).connect(edge)
if CONNECT_EFFECTS and hasattr(value, 'effects'):
for variable, effect in value.effects.iteritems():
if isinstance(effect, ValueEffect):
print effect
edge.connect(self.vertex(Substate({variable: effect(None)})))
return self.edges[value]
示例9: testEdgeNormal
def testEdgeNormal(self):
a = Node((0,0),(0,0))
b = Node((1,0),(0,0))
c = Node((0,1),(0,0))
t = Triangle(a, b, c)
xaxisedge = t.edges[0]
reversedxaxisedge = Edge(xaxisedge.nodes[1], xaxisedge.nodes[0])
diagonaledge = t.edges[1]
yaxisedge = t.edges[2]
self.assertTrue((xaxisedge.getNormal(t) == (0, -1)).all())
self.assertTrue((reversedxaxisedge.getNormal(t) == (0, -1)).all())
self.assertTrue((yaxisedge.getNormal(t) == (-1, 0)).all())
self.assertTrue((diagonaledge.getNormal(t) == (1/sqrt(2), 1/sqrt(2))).all())
示例10: test_creat_edge
def test_creat_edge(self):
# create a box
b = get_test_box_shape()
# take the first edge
t = Topo(b)
edge_0 = t.edges().next() # it's a TopoDS_Edge
assert not edge_0.IsNull()
# then create an edge
my_edge = Edge(edge_0)
assert not my_edge.IsNull()
assert my_edge.tolerance == 1e-06
assert my_edge.type == 'line'
assert my_edge.length() == 30.
示例11: PreStopAcc
class PreStopAcc(Rule):
"""classify the trip as high based on the minimum of pre_stop_acc, which is the maximum of deceleration"""
def __init__(self):
self.name = "PreStopAcc"
self.high_edge = Edge(self.name, "high")
def classify(self, vertex):
min_pre_stop_acc = vertex.stop_points[2]
if min_pre_stop_acc < -3.0:
self.high_edge.add_vertex(vertex)
return self.high_edge.id
def edges(self):
return [self.high_edge]
示例12: PostStopAcc
class PostStopAcc(Rule):
"""classify the trip as high based on maximum of post_stop_acc"""
def __init__(self):
self.name = "PostStopAcc"
self.high_edge = Edge(self.name, "high")
def classify(self, vertex):
max_post_stop_acc = vertex.stop_points[5]
if max_post_stop_acc > 2.0:
self.high_edge.add_vertex(vertex)
return self.high_edge.id
def edges(self):
return [self.high_edge]
示例13: delete_network
def delete_network(options, vsm_obj):
""" function to delete network
@param options cli options to this script
@param vsm_obj reference to vsm client object
@return True/False True - success False - error
"""
print("Disconnecting edge interface attached to this network")
edge_id = get_edge(vsm_obj)
edge = Edge(vsm_obj, '4.0')
edge.id = edge_id
vnics = Vnics(edge)
vnics_schema = vnics.query()
network = get_network_id(options, get_network_name_on_vc(options))
for vnic in vnics_schema.vnics:
if network and vnic.portgroupId == network:
print("Found a matching vnic %s %s" % (options.name, vnic.index))
vnic.isConnected = "False"
vnic.portgroupId = None
vnic.name = "vnic%s" % vnic.index
vnics_schema = VnicsSchema()
vnics_schema.vnics = [vnic]
result = vnics.create(vnics_schema)
if (result[0].response.status != 204):
print "update vnic error: %s %s" \
% (result[0].response.status, result[0].response.reason)
return False
else:
break
else:
print ("No matching vnic found")
vdn_scope = get_transport_zone(options)
virtual_wire = VirtualWire(vdn_scope)
vwire = virtual_wire.read_by_name(get_network_name(options))
name = get_network_name(options)
if vwire != "FAILURE":
print("Found a matching network %s" % (options.name))
virtual_wire.id = vwire.objectId
result = virtual_wire.delete()
if (result.response.status != 200):
print ("Delete vwire error: %s" % result.response.reason)
return False
else:
print ("No matching network found")
print("Network %s deleted" % (options.name))
return True
示例14: __declare_last__
def __declare_last__(cls):
src_ids, dst_ids = [], []
for scls in Edge.get_subclasses():
name = scls.__name__
name_in = '_{}_in'.format(name)
name_out = '_{}_out'.format(name)
src_assoc = getattr(scls, SRC_DST_ASSOC)
dst_assoc = getattr(scls, DST_SRC_ASSOC)
if scls.__dst_class__ == cls.__name__:
if not hasattr(cls, name_in):
edge_in = relationship(
name,
foreign_keys=[scls.dst_id],
backref='dst',
cascade='all, delete, delete-orphan',
)
setattr(cls, name_in, edge_in)
cls._edges_in.append(name_in)
dst_ids.append(scls.dst_id)
cls._set_association_proxy(scls, dst_assoc, name_in, 'src')
if scls.__src_class__ == cls.__name__:
if not hasattr(cls, name_out):
edge_out = relationship(
name,
foreign_keys=[scls.src_id],
backref='src',
cascade='all, delete, delete-orphan',
)
setattr(cls, name_out, edge_out)
cls._edges_out.append(name_out)
src_ids.append(scls.src_id)
cls._set_association_proxy(scls, src_assoc, name_out, 'dst')
示例15: addEdge
def addEdge(self, beginPoint, endPoint, beginSide, endSide, edgeSelfLoops, src, dst, tokenValues, pRates, cRates, color):
newEdge = Edge(beginPoint, endPoint, beginSide, endSide, edgeSelfLoops, pRates, cRates, color)
#Place edges always behind nodes
newEdge.setZValue(1)
#Give edge a cluster of tokens
tokenCluster = TokenCluster(self, self.scene, self.view, newEdge, src, dst, tokenValues)
self.scene.addItem(tokenCluster)
self.clusterList.append(tokenCluster)
#Add edge to the scene and list
self.scene.addItem(newEdge)
self.edgeList.append(newEdge)
return newEdge