Class GraphModifierImpl

  • All Implemented Interfaces:
    EventProducer, GraphModifierEventProducer, GraphModifier<Vertex,​Edge>, TopologicalModifier

    public class GraphModifierImpl
    extends EventProducerImpl
    implements GraphModifier<Vertex,​Edge>
    Apply modifications to the graph in an integrated fashion.

    While graphs are assumed to have a managed id for all their entities it is not a given that the edges, vertices, etc. are the primary containers where these are uniquely tracked. For example a subgraph might only contain a subset of vertices. Therefore, whenever modifications are made to a graph, the incoker of these changes should be aware whether or not the graph entities containers are the primary containers or not. If so, and the ids used are expected to remain contiguous (directly) after completion of the modification, additional effort is required by invoking recreateManagedEntitiesIds() to ensure that all entity containers on the graph are triggered to perform an update of their internally managed ids.

    Author:
    markr
    • Field Detail

      • theGraph

        protected final UntypedGraph<?,​?> theGraph
        the graph to modify
    • Constructor Detail

      • GraphModifierImpl

        public GraphModifierImpl​(UntypedGraph<?,​?> theGraph)
        Constructor
        Parameters:
        theGraph - to use
    • Method Detail

      • updateBrokenEdgeGeometry

        protected static void updateBrokenEdgeGeometry​(Edge brokenEdge,
                                                       Vertex vertexBrokenAt)
        update the geometry of the broken edge, knowing at what vertex it was broken from a previously longer edge
        Parameters:
        brokenEdge - the broken edge
        vertexBrokenAt - the vertex it was broken at
      • processSubNetworkVertex

        protected Set<Vertex> processSubNetworkVertex​(Vertex referenceVertex)
        helper function for subnetwork identification (deliberately NOT recursive to avoid stack overflow on large networks)
        Parameters:
        referenceVertex - to process
        Returns:
        all vertices in the subnetwork connected to passed in reference vertex
      • getGraph

        public UntypedGraph<?,​?> getGraph()
        Access to graph
        Returns:
        the underlying graph
      • fireEvent

        public void fireEvent​(EventListener eventListener,
                              Event event)
        Let derived class deal with the handling of the listener, where based on the derived event implementation the listener's concrete class can be determined which in turn allows for calling the right event callback method which is unknown at this base level since this event mechanism does not force a particular notification method signature on its listener interface

        make public so derived classes can access it as well

        Specified by:
        fireEvent in class EventProducerImpl
        Parameters:
        eventListener - to notify for the event
        event - to process for the listener
      • removeVertex

        public void removeVertex​(Vertex vertex)
        Remove a vertex by removing it from the graph and the edges it is connected to. Any registered events fro vertex removal will be triggered.
        Specified by:
        removeVertex in interface GraphModifier<Vertex,​Edge>
        Parameters:
        vertex - to remove
      • removeEdge

        public void removeEdge​(Edge edge)
        Remove an edge by removing it from the graph and the vertices it is connected to. Any registered events for edge removal will be triggered.
        Specified by:
        removeEdge in interface GraphModifier<Vertex,​Edge>
        Parameters:
        edge - to remove
      • removeDanglingSubGraphs

        public void removeDanglingSubGraphs​(Integer belowSize,
                                            Integer aboveSize,
                                            boolean alwaysKeepLargest)
        remove any dangling subgraphs below a given size from the graph if they exist and subsequently reorder the internal ids if needed
        Specified by:
        removeDanglingSubGraphs in interface GraphModifier<Vertex,​Edge>
        Parameters:
        belowSize - remove subgraphs below the given size
        aboveSize - remove subgraphs above the given size (typically set to maximum value)
        alwaysKeepLargest - indicate if the largest of the subgraphs is always to be kept even if it does not match the criteria
      • removeSubGraph

        public void removeSubGraph​(Set<? extends Vertex> subGraphToRemove)
        remove the subgraph identified by the passed in vertices
        Specified by:
        removeSubGraph in interface GraphModifier<Vertex,​Edge>
        Parameters:
        subGraphToRemove - the one to remove
      • removeSubGraphOf

        public void removeSubGraphOf​(Vertex referenceVertex)
        remove the (sub)graph in which the passed in vertex resides. Apply reordering of internal ids of remaining network.
        Specified by:
        removeSubGraphOf in interface GraphModifier<Vertex,​Edge>
        Parameters:
        referenceVertex - to identify subnetwork by
      • breakEdgesAt

        public <Ex extends EdgeMap<Long,​Pair<Ex,​Ex>> breakEdgesAt​(List<Ex> edgesToBreak,
                                                                                Vertex vertexToBreakAt,
                                                                                org.opengis.referencing.crs.CoordinateReferenceSystem crs)
        Break the passed in edges by inserting the passed in vertex in between. After completion the original edges remain as (VertexA,VertexToBreakAt), and new edges are inserted for (VertexToBreakAt,VertexB).
        Specified by:
        breakEdgesAt in interface GraphModifier<Vertex,​Edge>
        Type Parameters:
        Ex - edge type
        Parameters:
        edgesToBreak - the links to break
        vertexToBreakAt - the node to break at
        crs - required to update edge lengths
        Returns:
        affectedEdges the list of all result edges of the breaking of links by their original link id
      • breakEdgeAt

        public <Ex extends Edge> Ex breakEdgeAt​(Vertex vertexToBreakAt,
                                                Ex edgeToBreak,
                                                PlanitJtsCrsUtils geoUtils)
        Break the passed in edge by inserting the passed in vertex in between. After completion the original edge remains as (VertexA,VertexToBreakAt), and new edges are inserted for (VertexToBreakAt,VertexB).
        Specified by:
        breakEdgeAt in interface GraphModifier<Vertex,​Edge>
        Type Parameters:
        Ex - edge type
        Parameters:
        vertexToBreakAt - the node to break at
        edgeToBreak - the link to break
        geoUtils - required to update edge lengths
        Returns:
        newlyCreatedEdge
      • recreateManagedEntitiesIds

        public void recreateManagedEntitiesIds()
        This method will recreate all ids of the graph's components, e.g., vertices, edges, etc. but only when the containers used for them are the primary ManagedIdEntities containers, i.e., when the graph is responsible of uniquely tracking all entities by their managed id. If not, for example, if this is a subgraph reusing parts of the main graph, it will not recreate the ids.

        The reasoning is that if we would recreate ids of the container while the container does not contain all = let's say - vertices, their managedId is no longer guaranteed to be unique which can lead to issues

        Method can be used in conjunctions with the removal of parts of the graph and the result is required to have unique contiguous ids

        Should fire #RecreatedGraphEntitiesManagedIdsEvent after it has been executed

        Specified by:
        recreateManagedEntitiesIds in interface GraphModifier<Vertex,​Edge>
      • reset

        public void reset()
        reset all state related information of the instance
        Specified by:
        reset in interface GraphModifier<Vertex,​Edge>