Пример #1
0
def test_pg_can_be_extended_with_another_graph_with_different_properties():
    pg = PropertyGraph()
    for i in range(5):
        pg.add_vertex(i)
    for i in range(4):
        pg.add_edge(i, i + 1, i)
    pg.add_vertex_property("aprop")
    for vid in pg.vertices():
        pg.vertex_property("aprop")[vid] = 1
    pg.add_edge_property("aprop")
    for eid in pg.edges():
        pg.edge_property("aprop")[eid] = 2
    pg.add_graph_property("gprop", 'a')

    old_len = len(g)
    old_len_vprop = len(g.vertex_property("prop"))
    old_len_eprop = len(g.edge_property("prop"))
    g.extend(pg)
    assert len(g) == old_len + len(pg)
    assert "prop" in g.vertex_property_names()
    assert "aprop" in g.vertex_property_names()
    assert "prop" in g.edge_property_names()
    assert "aprop" in g.edge_property_names()
    assert "gprop" in g.graph_property_names()
    assert len(g.vertex_property("prop")) == old_len_vprop
    assert len(g.edge_property("prop")) == old_len_eprop
    assert len(g.vertex_property("aprop")) == len(pg.vertex_property("aprop"))
    assert len(g.edge_property("aprop")) == len(pg.edge_property("aprop"))
Пример #2
0
    def connect(self, source_pid, target_pid, eid=None):
        """ Connect two ports together.

        Connection can only be created between and output port
        and an input port.

        args:
            - source_pid (pid): global id of output port.
            - target_pid (pid): global if of input port.
            - eid (eid): edge id to use. If None, a new one
                        will be assigned.

        return:
            - eid (eid): id of edge used to make the connection.
        """
        if not self.is_out_port(source_pid):
            msg = "source_pid %s is not an output port" % str(source_pid)
            raise InvalidPort(msg)

        if not self.is_in_port(target_pid):
            msg = "target_pid %s is not an input port" % str(target_pid)
            raise InvalidPort(msg)

        eid = PropertyGraph.add_edge(self,
                                     self.vertex(source_pid),
                                     self.vertex(target_pid),
                                     eid)
        self.edge_property("_source_port")[eid] = source_pid
        self.edge_property("_target_port")[eid] = target_pid

        return eid
Пример #3
0
    def connect(self, source_pid, target_pid, eid=None):
        """ Connect two ports together.

        Connection can only be created between and output port
        and an input port.

        args:
            - source_pid (pid): global id of output port.
            - target_pid (pid): global if of input port.
            - eid (eid): edge id to use. If None, a new one
                        will be assigned.

        return:
            - eid (eid): id of edge used to make the connection.
        """
        if not self.is_out_port(source_pid):
            msg = "source_pid %s is not an output port" % str(source_pid)
            raise InvalidPort(msg)

        if not self.is_in_port(target_pid):
            msg = "target_pid %s is not an input port" % str(target_pid)
            raise InvalidPort(msg)

        eid = PropertyGraph.add_edge(self, self.vertex(source_pid), self.vertex(target_pid), eid)
        self.edge_property("_source_port")[eid] = source_pid
        self.edge_property("_target_port")[eid] = target_pid

        return eid