Class Structure<V extends Vertex,​E extends Edge>

    • Field Detail

      • vertexIdHoles

        public java.util.TreeSet<com.algo.structure.Structure.Interval> vertexIdHoles
      • edgeIdHoles

        public java.util.TreeSet<com.algo.structure.Structure.Interval> edgeIdHoles
    • Constructor Detail

      • Structure

        public Structure()
    • Method Detail

      • loadFromFile

        public static Structure loadFromFile​(java.lang.String fileName)
                                      throws java.lang.Exception
        Throws:
        java.lang.Exception
      • loadFromStream

        public static Structure loadFromStream​(java.io.InputStream stream)
                                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • isEmpty

        public boolean isEmpty()
      • getVertices

        public java.util.Collection<V> getVertices()
        Returns:
        An unmodifiable set of vertices.
      • getRandomEdge

        public Edge getRandomEdge()
        Returns:
        A pseudo-randommly selected vertrex.
      • getRandomVertex

        public Vertex getRandomVertex()
        Returns:
        A pseudo-randommly selected vertrex.
      • getVerticesT

        public java.util.HashMap<java.lang.Integer,​V> getVerticesT()
      • setVerticesT

        public void setVerticesT​(java.util.HashMap<java.lang.Integer,​V> verticesNew)
        Overrides vertices. Only for internal use
      • getEdgesT

        public java.util.HashMap<java.lang.Integer,​E> getEdgesT()
      • setEdgesT

        public void setEdgesT​(java.util.HashMap<java.lang.Integer,​E> edgesNew)
      • getEdges

        public java.util.Set<E> getEdges()
        Returns:
        An unmodifiable set of edges.
      • snapToGrid

        public void snapToGrid​(double gridSize)
      • maximumCoordinate

        public double maximumCoordinate​(int dimension)
        Parameters:
        dimension - 0 for the x-dimension and 1 for the y-dimension.
        Returns:
        The largest x or y value occurring in vertex/edges coordinates.
      • createVertex

        public abstract V createVertex()
        Creates a new vertex instance without adding it to the structure.
        Returns:
        The new vertex.
      • createVertex

        public abstract V createVertex​(Configuration config)
        Creates a new vertex instance without adding it to the structure.
        Returns:
        The new vertex.
      • addVertex

        public V addVertex​(Configuration config,
                           int id)
        Adds a vertex to the structure, and uses the given id, given it is it is stil available. if not, it uses the next free id.
        Parameters:
        config - The configuration of the vertex
        id - The id of which v will soon hopefully be the proud owner
      • mergeStructure

        public void mergeStructure​(Structure<V,​E> s,
                                   V thisVertex,
                                   V thatVertex)
        Adds another structure s to this structure (this) identifying thisVertex from this structure with thatVertex from s. The identified vertex has the properties of thatVertex (only properties from Vertex and Edge, not from their descendants). Structure s remains unchanged (the objects from s are copied to this). If the same structure is given as s, produces a copy an merges it into this structure.
        Parameters:
        s - Another structure
        thisVertex - A vertex from this structure
        thatVertex - A vertex from that structure
      • addVertex

        public V addVertex()
      • addVertex

        @Deprecated
        public void addVertex​(V v)
        Deprecated.
        Don't use this method. Adding vertices this way is deprecated.
        Parameters:
        v -
      • addVertex

        public V addVertex​(Configuration config)
        Adds a vertex to the structure. Has no effect if the vertex already exists in the structure.
        Parameters:
        config - The config with which the vertex will be initialized
        Returns:
        The created vertex
      • addVertex

        public V addVertex​(java.lang.String label)
        Creates a new vertex with the given label and adds it to the structure. This is a convenience function combining createVertex and addVertex. Adding multiple vertices with the same name adds multiple vertices.
        Parameters:
        label - The label of the new vertex to be added.
        Returns:
        The new vertex.
      • addVertex

        public V addVertex​(java.lang.String label,
                           Configuration config)
      • addVertices

        public void addVertices​(java.util.Collection<V> vs)
        Adds a set of vertices to the structure. Incident edges are not added.Vertex IDs are generated automatically.
        Parameters:
        vs - The vertices to be added.
      • clear

        public void clear()
        Clear the structure. Removes all vertices and all edges.
      • getEdgeByEndVertices

        public Edge getEdgeByEndVertices​(Vertex sourceVertex,
                                         Vertex targetVertex)
      • getEdgeByVertexIds

        public Edge getEdgeByVertexIds​(int inputSourceId,
                                       int inputTargetId)
        preliminary method (to be updated with edge id's) for removing an edge very inefficient
      • getEdgeByVertexIdsAndId

        @Deprecated
        public Edge getEdgeByVertexIdsAndId​(int inputSourceId,
                                            int inputTargetId,
                                            int inputEdgeId)
        Deprecated.
      • getEdgeById

        public Edge getEdgeById​(int inputEdgeId)
      • getVertexById

        public V getVertexById​(int id)
        Find the vertex with a given ID. Lookup speed is O(1), since vertices are implemented as a HashMap.
        Parameters:
        id - The id of the vertex
        Returns:
        Returns the Vertex or null if no vertex has the ID
      • removeVertexByID

        public boolean removeVertexByID​(int id)
        Removes vertex from the structure for a given ID. You can remove by Object as well
        Parameters:
        id - The id of the vertex
        Returns:
        True if the vertex was removed, false if either no entry could be found or the associated vertex was null to begin with (see HashMap.remove() for further details)
      • removeVertex

        public void removeVertex​(Vertex v)
        Removes a vertex and its incident edges from the structure.
        Parameters:
        v - The vertex to be removed.
      • removeVertices

        public void removeVertices​(java.util.Collection<V> v)
      • createEdge

        @Deprecated
        public E createEdge​(V source,
                            V target)
        Deprecated.
      • createEdge

        public E createEdge​(int id,
                            Configuration config)
        Creates an edge without adding it to the graph.
        Returns:
        The new edge.
      • addEdge

        public boolean addEdge​(E e,
                               V source,
                               V target)
      • addEdge

        public boolean addEdge​(E e)
        Add an edge to the structure. Has no effect if the edge already exists in the structure.
        Parameters:
        e - The edge to be added.
      • addEdges

        public void addEdges​(java.util.Collection<E> es)
        Adds a set of edges to the structure if their ends are contained in the structure. Edges whose at least one vertex is not in the structure are not addded. IDs are generated automatically.
        Parameters:
        es - The edges to be added.
      • addEdge

        public E addEdge​(int sourceID,
                         int targetID)
        Parameters:
        sourceID - ID of the source vertex
        targetID - ID of the target vertex=
      • addEdge

        public E addEdge​(V source,
                         V target)
      • addEdge

        public E addEdge​(V source,
                         V target,
                         int id)
      • addEdge

        public E addEdge​(V source,
                         V target,
                         int id,
                         Configuration config)
      • removeEdge

        public void removeEdge​(int id)
      • removeEdge

        public void removeEdge​(Edge edge,
                               boolean removeSiblingsEntries)
        Removes an edge from the structure. Does not affect vertices, incident or not.
        Parameters:
        edge - The edge to be removed.
      • removeEdge

        public void removeEdge​(Edge e)
      • adjacent

        public boolean adjacent​(V a,
                                V b)
        Parameters:
        a - The first vertex.
        b - The second vertex.
        Returns:
        True if the given two vertices are adjacent.
      • edgesBetweenVertices

        public java.util.Set<Edge> edgesBetweenVertices​(V a,
                                                        V b)
      • pollNextFreeEdgeID

        public int pollNextFreeEdgeID()
        Returns the next free available ID, so that all vertices' ids are continuously filled on a single interval [0, n)
      • pollNextFreeVertexID

        public int pollNextFreeVertexID()
        Returns the next free available ID, so that all vertices' ids are continuously filled on a single interval [0, n). Updates vertexIdHoles.
      • collapseEdges

        public void collapseEdges​(java.util.Set<java.lang.Object> selection)
        Collapses edges or, when every single edge in the selection is already collapsed, inflates every set of edges.
      • alignHorizontallyMean

        public void alignHorizontallyMean​(java.util.LinkedHashSet<java.lang.Object> selection)
        Aligns all selected vertices along their y coordinate
      • alignHorizontallyFirst

        public void alignHorizontallyFirst​(java.util.LinkedHashSet<java.lang.Object> selection)
        Aligns all selected vertices along the y coordinate of the first selected element
      • alignVerticallyMean

        public void alignVerticallyMean​(java.util.LinkedHashSet<java.lang.Object> selection)
      • toXml

        public org.w3c.dom.Element toXml​(org.w3c.dom.Document doc)
                                  throws java.lang.Exception
        Overrides:
        toXml in class XmlMarshallable
        Throws:
        java.lang.Exception
      • toSimpleXml

        public org.w3c.dom.Element toSimpleXml​(org.w3c.dom.Document doc)
                                        throws java.lang.Exception
        Throws:
        java.lang.Exception
      • toIncM

        public int[][] toIncM()
      • writeToFile

        public void writeToFile​(java.lang.String filename,
                                java.lang.Boolean simple)
                         throws java.lang.Exception
        Throws:
        java.lang.Exception
      • writeToStream

        public void writeToStream​(javax.xml.transform.stream.StreamResult stream,
                                  java.lang.Boolean simple)
                           throws java.lang.Exception
        Throws:
        java.lang.Exception
      • xmlToString

        public java.lang.String xmlToString()
                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • incToString

        public java.lang.String incToString()
                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • tgfToString

        public java.lang.String tgfToString()
                                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • fromXml

        public void fromXml​(org.w3c.dom.Element gnode)
                     throws java.lang.Exception
        Throws:
        java.lang.Exception
      • setFileReference

        public void setFileReference​(boolean hasReference,
                                     java.lang.String ref)
        Was the structure opened from a file or does this structure reference a file? (e.g.: was it saved as...?)

        You can set the file reference here.

      • getFileReference

        public java.lang.String getFileReference()
        Returns:
        A string containing the path of the referenced file. Empty if no file is referenced by this structure.
      • hasFileReference

        public boolean hasFileReference()
        Returns:
        True if the structure is referencing a file
      • getDescription

        public StructureDescription getDescription()
                                            throws java.lang.Exception
        Throws:
        java.lang.Exception