How to use the moltemplate.nbody_graph_search.Dgraph function in moltemplate

To help you get started, we’ve selected a few moltemplate examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github jewettaij / moltemplate / moltemplate / nbody_graph_search.py View on Github external
#         [Ie for Ie in self.ie_to_Ie])
        # version 3:
        #   Recall that the vertices and edges and g have been re-ordered,
        #   so sort the list of Iv indices in the order they would be
        #   matched with the original vertices from the original graph g:
        # match = ([self.iv_to_Iv[self.vorder_g[iv]]
        #          for iv in range(0,self.g.nv)],
        #         [self.ie_to_Ie[self.eorder_g[ie]]
        #          for ie in range(0,self.g.ne)])
        # version 4: Similar to version 3 above, but we also translate
        #            the directed edge id list into a shorter undirected
        #            edge id list.
        match_verts = [self.iv_to_Iv[self.vorder_g[iv]]
                       for iv in range(0, self.g.nv)]

        if type(self.g) is Dgraph:
            match_edges = [self.ie_to_Ie[self.eorder_g[ie]]
                           for ie in range(0, self.g.ne)]
        else:
            #assert(atype(self.g) is Ugraph)
            match_edges = [Dgraph.NULL for ieu in range(0, self.g.neu)]

            for ie in range(0, self.g.ne):
                iv = self.g.edges[ie].start
                jv = self.g.edges[ie].stop
                if iv <= jv:  # <-- avoid duplicating edges (iv,jv) and (jv,iv)
                    ieu = self.g.LookupUndirectedEdgeIdx(ie)
                    Ie = self.ie_to_Ie[ie]
                    Ieu = self.G.LookupUndirectedEdgeIdx(Ie)
                    match_edges[ieu] = Ieu

        return (tuple(match_verts), tuple(match_edges))
github jewettaij / moltemplate / moltemplate / nbody_graph_search.py View on Github external
def Reset(self):
        self.sv = 0
        self.se = 0
        for iv in range(0, self.g.nv):
            self.vvisited[iv] = False
            self.vorder[iv]   = Dgraph.NULL
        for ie in range(0, self.g.ne):
            self.evisited[ie] = False
            self.eorder[ie]   = Dgraph.NULL
github jewettaij / moltemplate / moltemplate / nbody_graph_search.py View on Github external
def ReorderEdges(self, epermutation, invert=False):
        Dgraph.ReorderEdges(self, epermutation, invert)

        # Now update the
        # self.ieu_to_ied and
        # self.ied_to_ieu lookup tables:

        if (invert): # (first invert the permutation if necessary)
            eperm = [-1 for ie in epermutation]
            for ie in range(0, self.ne):
                eperm[ epermutation[ie] ] = ie
        else:
            eperm = epermutation
        #epermutation.reverse()

        ieu_to_ied_orig = [ied for ied in self.ieu_to_ied]
        ied_to_ieu_orig = [ieu for ieu in self.ied_to_ieu]
github jewettaij / moltemplate / moltemplate / nbody_graph_search.py View on Github external
def FindEdge(self, istart, istop):
        """
        A simple function looks up the (undirected) edge id number
        corresponding to an edge connecting vertices istart and istop.
        If not present returns Dgraph.NULL.

        To find the corresponding entry in the self.edges[] list,
        you can either:
            use the LookupDirectedEdge() lookup function
             or
            you can use the parent-class' version of this function
            Dgraph.FindEdge(self, istart, istop) which returns
            this number by default.

        """
        ied = Dgraph.FindEdge(self, istart, istop)
        ieu = self.LookupUndirectedEdgeIdx(ied)
        return ieu
github jewettaij / moltemplate / moltemplate / nbody_graph_search.py View on Github external
def FindEdge(self, istart, istop):
        """
        A simple function looks up the (undirected) edge id number
        corresponding to an edge connecting vertices istart and istop.
        If not present returns Dgraph.NULL.

        To find the corresponding entry in the self.edges[] list,
        you can either:
            use the LookupDirectedEdge() lookup function
             or
            you can use the parent-class' version of this function
            Dgraph.FindEdge(self, istart, istop) which returns
            this number by default.

        """
        ied = Dgraph.FindEdge(self, istart, istop)
        ieu = self.LookupUndirectedEdgeIdx(ied)
        return ieu
github jewettaij / moltemplate / moltemplate / nbody_graph_search.py View on Github external
def __init__(self, edgelist=None):
        Dgraph.__init__(self, edgelist)

        # Now add the extra edges which point in the reverse direction.
        neu = self.ne
        ned = self.ne
        for ieu in range(0, self.ne):
            iv   = self.edges[ieu].start
            jv   = self.edges[ieu].stop
            if iv != jv:
                ned += 1

        self.ieu_to_ied = [Dgraph.NULL for ieu in range(0, neu)]
        self.ied_to_ieu = [Dgraph.NULL for ied in range(0, ned)]

        ied_redundant = neu
        for ie in range(0, neu):
            iv   = self.edges[ie].start
github jewettaij / moltemplate / moltemplate / nbody_graph_search.py View on Github external
else:
                l.append(']')
        l.append(',\n [')
        for ie in range(0, self.ne):
            l.append(str(self.edges[ie]))
            if ie < self.ne - 1:
                l.append(', ')
            else:
                l.append('])\n')
        return ''.join(l)

    def __repr__(self):
        return str(self)


class Ugraph(Dgraph):
    """
    This class is a minimal implementation of an undirected graph.
    Vertices and edges are accessed by integer index only (beginning at 0).
    Multiple edges connecting the same pair of vertices are allowed.
    (One would use the AddEdge() member function to accomplish this.)
    Both vertices and edges have an optional "attr" attribute.

        Undirected graphs (Ugraphs) are represented internally as
        directed graphs.  This means that for every edge in the Ugraph,
        connecting vertex 2 to 3, for example, two edges are stored
        internally, (2 -> 3,   and   3 -> 2),
        Edges which begin and end at the same vertex are stored only once.)

    """

    def __init__(self, edgelist=None):
github jewettaij / moltemplate / moltemplate / nbody_graph_search.py View on Github external
def ReorderEdges(self, epermutation, invert=False):
        Dgraph.ReorderEdges(self, epermutation, invert)

        # Now update the
        # self.ieu_to_ied and
        # self.ied_to_ieu lookup tables:

        if (invert):  # (first invert the permutation if necessary)
            eperm = [-1 for ie in epermutation]
            for ie in range(0, self.ne):
                eperm[epermutation[ie]] = ie
        else:
            eperm = epermutation
        # epermutation.reverse()

        ieu_to_ied_orig = [ied for ied in self.ieu_to_ied]
        ied_to_ieu_orig = [ieu for ieu in self.ied_to_ieu]
github jewettaij / moltemplate / moltemplate / nbody_graph_search.py View on Github external
l.append(str(self.edges[ie]))
            if ie < self.ne-1:
                l.append(', ')
            else:
                l.append('])\n')
        return ''.join(l)

    def __repr__(self):
        return str(self)






class Ugraph(Dgraph):
    """
    This class is a minimal implementation of an undirected graph.
    Vertices and edges are accessed by integer index only (beginning at 0).
    Multiple edges connecting the same pair of vertices are allowed.
    (One would use the AddEdge() member function to accomplish this.)
    Both vertices and edges have an optional "attr" attribute.

        Undirected graphs (Ugraphs) are represented internally as
        directed graphs.  This means that for every edge in the Ugraph,
        connecting vertex 2 to 3, for example, two edges are stored
        internally, (2 -> 3,   and   3 -> 2),
        Edges which begin and end at the same vertex are stored only once.)

    """

    def __init__(self, edgelist=None):