本文整理匯總了Python中openalea.workflow.port_graph.PortGraph.nb_connections方法的典型用法代碼示例。如果您正苦於以下問題:Python PortGraph.nb_connections方法的具體用法?Python PortGraph.nb_connections怎麽用?Python PortGraph.nb_connections使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類openalea.workflow.port_graph.PortGraph
的用法示例。
在下文中一共展示了PortGraph.nb_connections方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: portgraph_nb_connections
# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import nb_connections [as 別名]
def portgraph_nb_connections():
pg = PortGraph()
vid1 = pg.add_vertex()
vid2 = pg.add_vertex()
vid3 = pg.add_vertex()
assert_raises(InvalidPort, lambda: pg.nb_connections(0))
pid1 = pg.add_in_port(vid1, 0)
pid2 = pg.add_in_port(vid1, 1)
pid3 = pg.add_out_port(vid2, 0)
pid4 = pg.add_out_port(vid3, 0)
for pid in (pid1, pid2, pid3, pid4):
assert pg.nb_connections(pid) == 0
pg.connect(pid3, pid1)
assert pg.nb_connections(pid3) == 1
assert pg.nb_connections(pid1) == 1
assert pg.nb_connections(pid2) == 0
assert pg.nb_connections(pid4) == 0
pg.connect(pid4, pid1)
assert pg.nb_connections(pid3) == 1
assert pg.nb_connections(pid4) == 1
assert pg.nb_connections(pid1) == 2
assert pg.nb_connections(pid2) == 0
pg.connect(pid4, pid2)
assert pg.nb_connections(pid3) == 1
assert pg.nb_connections(pid4) == 2
assert pg.nb_connections(pid1) == 2
assert pg.nb_connections(pid2) == 1
示例2: test_portgraph_remove_port
# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import nb_connections [as 別名]
def test_portgraph_remove_port():
pg = PortGraph()
vid1 = pg.add_vertex()
vid2 = pg.add_vertex()
pid1 = pg.add_in_port(vid1, "in")
pid2 = pg.add_out_port(vid2, "out")
pg.connect(pid2, pid1)
# raise error if global port id dos not exist
assert_raises(InvalidPort, lambda: pg.remove_port(pid1 + pid2 + 1))
pg.remove_port(pid1)
assert len(tuple(pg.ports(vid1))) == 0
assert tuple(pg.ports(vid2)) == (pid2,)
assert pg.nb_connections(pid2) == 0
示例3: test_portgraph_remove_vertex
# 需要導入模塊: from openalea.workflow.port_graph import PortGraph [as 別名]
# 或者: from openalea.workflow.port_graph.PortGraph import nb_connections [as 別名]
def test_portgraph_remove_vertex():
pg = PortGraph()
vid1 = pg.add_vertex()
vid2 = pg.add_vertex()
pid1 = pg.add_in_port(vid1, "in")
pid2 = pg.add_out_port(vid2, "out")
pg.connect(pid2, pid1)
assert_raises(InvalidVertex, lambda: pg.remove_vertex(vid1 + vid2 + 1))
pg.remove_vertex(vid1)
assert tuple(pg.ports()) == (pid2,)
assert_raises(InvalidVertex, lambda: pg.ports(vid1).next())
assert tuple(pg.ports(vid2)) == (pid2,)
assert pg.nb_connections(pid2) == 0
assert pg.nb_neighbors(vid2) == 0