Class SparseTCGraph<E extends Edge>

java.lang.Object
it.univr.di.cstnu.graph.SparseTCGraph<E>
Type Parameters:
E - concrete type of temporal constraints stored as edges
All Implemented Interfaces:
TemporalConstraintGraph<E>, PropertyChangeListener, EventListener

public final class SparseTCGraph<E extends Edge> extends Object implements TemporalConstraintGraph<E>, PropertyChangeListener
JUNG-independent implementation of a temporal constraint graph, optimized for sparse temporal constraint networks.

The representation stores only existing edges. It maintains an index by edge name, a directed endpoint index, and incoming/outgoing edge-entry indexes for every vertex. Consequently, endpoint lookup and edge lookup are expected O(1), while enumerating the incident edges of a vertex is O(degree(vertex)). This is the intended representation for the usual CSTNU workload: hundreds or thousands of time-points and a small number of constraints per time-point.

This class deliberately does not implement a JUNG interface. DenseTCGraph remains the JUNG-compatible implementation needed by the current editor. SparseTCGraph is not intended as a replacement for that editor-facing graph, nor as an optimized representation for genuinely dense networks.

As in DenseTCGraph, an edge name and an ordered endpoint pair must each be unique. Vertex identity in the graph is its name: methods receiving a LabeledNode resolve it through AbstractComponent.getName(). Clients must therefore not rename a vertex or an edge while it is contained in this graph.

Author:
posenato
  • Constructor Details

    • SparseTCGraph

      public <E1 extends E> SparseTCGraph(@Nonnull String graphName, @Nonnull Class<E1> inputEdgeImplClass)
      Creates an empty sparse temporal constraint graph.
      Type Parameters:
      E1 - concrete edge type, possibly narrower than E
      Parameters:
      graphName - name used for diagnostics
      inputEdgeImplClass - concrete edge implementation to create from TemporalConstraintGraph.makeNewEdge(String, Edge.ConstraintType)
  • Method Details

    • addAnnotation

      public void addAnnotation(@Nonnull GraphAnnotation annotation)
      Description copied from interface: TemporalConstraintGraph
      Adds a presentation-only plain-text annotation to this graph.
      Specified by:
      addAnnotation in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      annotation - the annotation to add
    • addEdge

      public boolean addEdge(@Nonnull E edge, @Nonnull LabeledNode source, @Nonnull LabeledNode destination)
      Adds an edge, adding missing endpoints first. An edge name and its ordered endpoint pair must both be unused.
      Specified by:
      addEdge in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      edge - edge to add
      source - source endpoint
      destination - destination endpoint
      Returns:
      true if the graph changed
      Throws:
      IllegalArgumentException - if an edge name or endpoint pair is already present
    • addEdge

      public void addEdge(@Nonnull E edge, @Nonnull String sourceName, @Nonnull String destinationName)
      Adds an edge between vertices identified by name, creating ordinary vertices when necessary.
      Specified by:
      addEdge in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      edge - edge to add
      sourceName - source endpoint name
      destinationName - destination endpoint name
      Throws:
      IllegalArgumentException - if an edge name or endpoint pair is already present
    • addVertex

      public boolean addVertex(@Nonnull LabeledNode vertex)
      Adds a vertex with a unique name.
      Specified by:
      addVertex in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      vertex - time-point to add
      Returns:
      true if the graph changed
      Throws:
      IllegalArgumentException - if the name is already present or another vertex observes the same proposition
    • clear

      public void clear()
      Removes every vertex, edge, and the distinguished zero time-point.
      Specified by:
      clear in interface TemporalConstraintGraph<E extends Edge>
    • clearAnnotations

      public void clearAnnotations()
      Description copied from interface: TemporalConstraintGraph
      Removes every presentation-only annotation from this graph.
      Specified by:
      clearAnnotations in interface TemporalConstraintGraph<E extends Edge>
    • clearCache

      public void clearCache()
      Invalidates snapshots and rebuilds the contingent-edge index without changing graph content.
      Specified by:
      clearCache in interface TemporalConstraintGraph<E extends Edge>
    • containsEdge

      public boolean containsEdge(@Nonnull E edge)
      Description copied from interface: TemporalConstraintGraph
      Tests whether this graph contains an edge whose name matches the name of the supplied edge.

      Identification is by name, within this graph: this method looks up the edge by the edge's name and does not compare the supplied object by identity. Querying with an edge that belongs to a different graph but whose name coincides with a local edge returns true and resolves to the local element, not false.

      To test whether a specific edge object is the one actually stored in this graph (by identity, not by name), use ownsEdge.

      Specified by:
      containsEdge in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      edge - edge to test
      Returns:
      whether there is an edge with the given name in this graph
    • containsVertex

      public boolean containsVertex(@Nonnull LabeledNode vertex)
      Specified by:
      containsVertex in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      vertex - time-point to test
      Returns:
      whether the time-point belongs to this graph
    • findEdge

      @Nullable public E findEdge(@Nullable String sourceName, @Nullable String destinationName)
      Description copied from interface: TemporalConstraintGraph
      Finds the directed edge identified by its endpoint names, or null.
      Specified by:
      findEdge in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      sourceName - source endpoint name, possibly null
      destinationName - destination endpoint name, possibly null
      Returns:
      matching edge, or null when absent
    • getALabelAlphabet

      @Nullable public ALabelAlphabet getALabelAlphabet()
      Specified by:
      getALabelAlphabet in interface TemporalConstraintGraph<E extends Edge>
      Returns:
      the shared alphabet used for contingent-node A-Labels, or null for network kinds that do not use upper/lower-case values (e.g., plain CSTN)
    • getAnnotations

      @Nonnull public List<GraphAnnotation> getAnnotations()
      Description copied from interface: TemporalConstraintGraph
      Returns the annotations in their drawing order. The returned list must not be modified directly.
      Specified by:
      getAnnotations in interface TemporalConstraintGraph<E extends Edge>
      Returns:
      the annotations in their drawing order
    • getContingentNodeCount

      public int getContingentNodeCount()
      Returns half the maintained contingent-edge count, matching DenseTCGraph's historical contingent-link convention.
      Specified by:
      getContingentNodeCount in interface TemporalConstraintGraph<E extends Edge>
      Returns:
      the number of contingent links, namely half the number of contingent edges
    • getDest

      @Nullable public LabeledNode getDest(@Nonnull E edge)
      Description copied from interface: TemporalConstraintGraph
      Returns the destination endpoint of the edge identified by the supplied edge's name.

      Identification is by name, within this graph: the supplied edge's name is used to look up the local edge, and the destination node of that local edge is returned. Querying with an edge that belongs to a different graph but whose name coincides with a local edge returns the local destination node, not null.

      To test whether a specific edge object is the one actually stored in this graph, use ownsEdge.

      Specified by:
      getDest in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      edge - edge whose destination endpoint is requested
      Returns:
      the node whose name matches the destination endpoint of the edge, or null if the edge is absent
    • getEdge

      @Nullable public E getEdge(@Nonnull String edgeName)
      Description copied from interface: TemporalConstraintGraph
      Returns the edge having edgeName, or null when absent.
      Specified by:
      getEdge in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      edgeName - edge name
      Returns:
      matching edge, or null when absent
    • getEdgeCount

      public int getEdgeCount()
      Specified by:
      getEdgeCount in interface TemporalConstraintGraph<E extends Edge>
      Returns:
      the number of edges
    • getEdgeImplClass

      @Nonnull public Class<? extends E> getEdgeImplClass()
      Returns the concrete class that this graph uses to instantiate its edges.

      Every edge created by TemporalConstraintGraph.newEdgeInstance(String, Edge.ConstraintType) or TemporalConstraintGraph.makeNewEdge(String, Edge.ConstraintType) belongs to this class. Callers that need to construct a companion graph with the same edge implementation — for example when copying or converting a graph — can pass the returned class directly to TemporalConstraintGraph.newInstance(String, Class, int).

      Delegates to the internal edge factory of this graph.

      Specified by:
      getEdgeImplClass in interface TemporalConstraintGraph<E extends Edge>
      Returns:
      concrete edge implementation class; never null
    • getEdges

      @Nonnull public Collection<E> getEdges()
      Specified by:
      getEdges in interface TemporalConstraintGraph<E extends Edge>
      Returns:
      an independent collection containing all edges
    • getInEdges

      @Nonnull public Collection<E> getInEdges(@Nonnull LabeledNode vertex)
      Specified by:
      getInEdges in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      vertex - time-point whose incoming edges are requested
      Returns:
      incoming edges of vertex, or an empty collection if absent or isolated
    • getInEdgesAndSources

      @Nonnull public Collection<TemporalConstraintGraph.EdgeAndNode<E>> getInEdgesAndSources(@Nonnull LabeledNode vertex)
      Description copied from interface: TemporalConstraintGraph
      Returns an unmodifiable snapshot of pairs (edge, canonical source) for all incoming edges of vertex. The node in each pair is the canonical source stored in this graph. An absent or isolated vertex returns an empty collection. Iteration order is not contractual, but is deterministic for each backend; construction is proportional to the vertex degree.
      Specified by:
      getInEdgesAndSources in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      vertex - time-point whose incoming edges are requested
      Returns:
      immutable snapshot of incoming edge/source pairs
    • getInputFile

      @Nullable public File getInputFile()
      Specified by:
      getInputFile in interface TemporalConstraintGraph<E extends Edge>
      Returns:
      the file from which this graph was read, or null when unavailable
    • setInputFile

      public void setInputFile(@Nullable File newInputFile)
      Associates this graph with its input file for diagnostics and benchmark reporting.
      Specified by:
      setInputFile in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      newInputFile - input file, or null to clear the association
    • getName

      @Nonnull public String getName()
      Specified by:
      getName in interface TemporalConstraintGraph<E extends Edge>
      Returns:
      the graph name used in diagnostics and serialized representations
    • setName

      public void setName(@Nonnull String inputName)
      Sets the graph name.
      Specified by:
      setName in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      inputName - the new name for the graph.
    • getNode

      @Nullable public LabeledNode getNode(@Nonnull String nodeName)
      Description copied from interface: TemporalConstraintGraph
      Returns the time-point with name, or null when absent.
      Specified by:
      getNode in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      nodeName - time-point name
      Returns:
      matching time-point, or null when absent
    • getObserver

      @Nullable public LabeledNode getObserver(char proposition)
      Specified by:
      getObserver in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      proposition - a proposition
      Returns:
      the vertex observing proposition, or null if no vertex does
    • getObservers

      @Nonnull public Collection<LabeledNode> getObservers()
      Specified by:
      getObservers in interface TemporalConstraintGraph<E extends Edge>
      Returns:
      every observer vertex in this graph, i.e., every vertex associated with an observed proposition
    • getOutEdges

      @Nonnull public Collection<E> getOutEdges(@Nonnull LabeledNode vertex)
      Specified by:
      getOutEdges in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      vertex - time-point whose outgoing edges are requested
      Returns:
      outgoing edges of vertex, or an empty collection if absent or isolated
    • getOutEdgesAndDestinations

      @Nonnull public Collection<TemporalConstraintGraph.EdgeAndNode<E>> getOutEdgesAndDestinations(@Nonnull LabeledNode vertex)
      Description copied from interface: TemporalConstraintGraph
      Returns an unmodifiable snapshot of pairs (edge, canonical destination) for all outgoing edges of vertex. The node in each pair is the canonical destination stored in this graph. An absent or isolated vertex returns an empty collection. Iteration order is not contractual, but is deterministic for each backend; construction is proportional to the vertex degree.
      Specified by:
      getOutEdgesAndDestinations in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      vertex - time-point whose outgoing edges are requested
      Returns:
      immutable snapshot of outgoing edge/destination pairs
    • getPropositions

      @Nonnull public it.unimi.dsi.fastutil.chars.CharSet getPropositions()
      Specified by:
      getPropositions in interface TemporalConstraintGraph<E extends Edge>
      Returns:
      the propositions observed by nodes in this graph
    • getSource

      @Nullable public LabeledNode getSource(@Nonnull E edge)
      Description copied from interface: TemporalConstraintGraph
      Returns the source endpoint of the edge identified by the supplied edge's name.

      Identification is by name, within this graph: the supplied edge's name is used to look up the local edge, and the source node of that local edge is returned. Querying with an edge that belongs to a different graph but whose name coincides with a local edge returns the local source node, not null.

      To test whether a specific edge object is the one actually stored in this graph, use ownsEdge.

      Specified by:
      getSource in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      edge - edge whose source endpoint is requested
      Returns:
      the node whose name matches the source endpoint of the edge, or null if the edge is absent
    • getType

      Specified by:
      getType in interface TemporalConstraintGraph<E extends Edge>
      Returns:
      the temporal-network kind represented by this graph
    • getCheckOutcome

      @Nullable public CheckOutcome getCheckOutcome()
      Specified by:
      getCheckOutcome in interface TemporalConstraintGraph<E extends Edge>
      Returns:
      the persisted check result, or null when no trusted result is available.
    • getDispatchabilityOutcome

      @Nullable public DispatchabilityOutcome getDispatchabilityOutcome()
      Specified by:
      getDispatchabilityOutcome in interface TemporalConstraintGraph<E extends Edge>
      Returns:
      the persisted dispatchability representation, or null when absent.
    • setCheckOutcome

      public void setCheckOutcome(@Nullable CheckOutcome outcome)
      Description copied from interface: TemporalConstraintGraph
      Sets or clears the persisted check result.
      Specified by:
      setCheckOutcome in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      outcome - the check outcome to store, or null to clear
    • setDispatchabilityOutcome

      public void setDispatchabilityOutcome(@Nullable DispatchabilityOutcome outcome)
      Description copied from interface: TemporalConstraintGraph
      Sets or clears the persisted dispatchability representation.
      Specified by:
      setDispatchabilityOutcome in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      outcome - the dispatchability outcome to store, or null to clear
    • setType

      public void setType(@Nullable TemporalConstraintNetworkType newType)
      Description copied from interface: TemporalConstraintGraph
      Declares the temporal-network kind represented by this graph.

      A graph infers its kind from its edge implementation at construction time, and for most kinds that is enough. Two kinds cannot be inferred that way, because they share their edge implementation with another kind: a PCSTNU uses the same edges as a CSTNU and differs by having parameter nodes, and a PSTN uses the same edges as an STNU. For those two the caller has to say so — which is what this method is for, and it is the reason it belongs here rather than to one concrete backend: whoever creates a PCSTNU must be able to declare it whichever backend it lives on.

      Only such an ambiguity may be resolved: a request to change the kind into one that this graph's edges cannot represent is rejected with an IllegalArgumentException, since it would make the graph describe itself as something it cannot be. Use TemporalConstraintGraph.isTypeChangeAllowed(TemporalConstraintNetworkType, TemporalConstraintNetworkType) to ask in advance. A null argument is ignored.

      Specified by:
      setType in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      newType - the kind this graph represents
    • getVertexCount

      public int getVertexCount()
      Specified by:
      getVertexCount in interface TemporalConstraintGraph<E extends Edge>
      Returns:
      the number of time-points
    • getVertices

      @Nonnull public Collection<LabeledNode> getVertices()
      Specified by:
      getVertices in interface TemporalConstraintGraph<E extends Edge>
      Returns:
      all time-points in the graph
    • getZ

      @Nullable public LabeledNode getZ()
      Specified by:
      getZ in interface TemporalConstraintGraph<E extends Edge>
      Returns:
      the distinguished zero time-point, or null when it is not set
    • setZ

      public void setZ(@Nullable LabeledNode newZ)
      Description copied from interface: TemporalConstraintGraph
      Sets the distinguished zero time-point, or clears it when z is null.
      Specified by:
      setZ in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      newZ - zero time-point, or null to clear it
    • inDegree

      public int inDegree(@Nonnull LabeledNode vertex)
      Specified by:
      inDegree in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      vertex - time-point whose incoming degree is requested
      Returns:
      number of incoming edges
    • newEdgeInstance

      @Nonnull public E newEdgeInstance(@Nonnull String edgeName, @Nonnull Edge.ConstraintType edgeType)
      Description copied from interface: TemporalConstraintGraph
      Creates an edge instance without reserving or normalizing its name against this graph. This is intended for temporary edges that have not yet been inserted into a graph.
      Specified by:
      newEdgeInstance in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      edgeName - the name for the new edge
      edgeType - the type for the new edge
      Returns:
      the new edge object
    • newInstance

      @Nonnull public SparseTCGraph<E> newInstance(@Nonnull String inputName, int initialCapacity)
      Creates a new, empty temporal-constraint graph with the same concrete backend and the same concrete edge implementation as this graph.

      This lets an algorithm that only knows TemporalConstraintGraph<E> create a companion graph (e.g., a predecessor subgraph) without naming a concrete class such as DenseTCGraph or SparseTCGraph, without a Class<? extends E> parameter, and without a builder: every implementation already knows its own concrete backend and edge type, so it returns an instance of itself. Consequently, calling this method on a DenseTCGraph yields a DenseTCGraph, and calling it on SparseTCGraph yields a SparseTCGraph.

      The returned graph has no vertices, no edges, no distinguished zero time-point, and no cached data: it does not copy anything from this graph, it is only "the same kind of empty graph".

      Returns a new SparseTCGraph with the same concrete edge implementation as this graph. SparseTCGraph does not yet have a capacity-aware constructor (its indexes are hash-based and grow on demand), so initialCapacity is accepted for API symmetry with DenseTCGraph and is currently ignored.

      Specified by:
      newInstance in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      inputName - new graph's name, for diagnostics
      initialCapacity - expected vertex count, used as a pre-sizing hint by implementations whose internal storage benefits from it (e.g., DenseTCGraph's adjacency matrix, to avoid intermediate regrowth); implementations without a capacity-aware constructor may ignore it
      Returns:
      a new, empty graph of the same concrete backend and edge implementation as this graph
    • newInstance

      @Nonnull public <F extends Edge, I extends F> SparseTCGraph<F> newInstance(@Nonnull String inputName, @Nonnull Class<I> edgeImplClass, int initialCapacity)
      Creates a new, empty graph of the same concrete backend as this graph, but with a different edge implementation.

      This is the overload to use when an algorithm must translate a network from one edge kind to another (e.g., a CSTNU-edge graph reduced to a CSTN-edge graph) while still preserving the caller's choice of backend (DenseTCGraph stays DenseTCGraph, SparseTCGraph stays SparseTCGraph). It does not copy anything from this graph: no vertices, no edges, no distinguished zero time-point, and no cached data.

      Returns a new SparseTCGraph using edgeImplClass. initialCapacity is accepted for API symmetry with DenseTCGraph and is currently ignored, as with newInstance(String, int).

      Specified by:
      newInstance in interface TemporalConstraintGraph<E extends Edge>
      Type Parameters:
      F - the new graph's API-level edge type (e.g., CSTNEdge)
      I - the concrete edge implementation, a subtype of F (e.g., CSTNEdgePluggable); kept distinct from F so that callers can assign the result to a TemporalConstraintGraph<F> variable without an unchecked cast, while edgeImplClass stays the concrete, instantiable class
      Parameters:
      inputName - new graph's name, for diagnostics
      edgeImplClass - concrete edge implementation for the new graph
      initialCapacity - expected vertex count, used as a pre-sizing hint by implementations whose internal storage benefits from it (e.g., DenseTCGraph's adjacency matrix); implementations without a capacity-aware constructor may ignore it
      Returns:
      a new, empty graph of the same concrete backend as this graph and of the requested edge type
    • newPredecessorInstance

      @Nonnull public TemporalConstraintPredecessorGraph<E> newPredecessorInstance()
      Description copied from interface: TemporalConstraintGraph
      Creates an empty predecessor-relation container suitable for algorithms running on this graph.

      The returned object is independent of this graph. Its representation is an implementation detail: graph backends may share a compact predecessor container when that is more efficient. This factory keeps algorithm code independent of that choice.

      Specified by:
      newPredecessorInstance in interface TemporalConstraintGraph<E extends Edge>
      Returns:
      a new, empty predecessor-relation container
    • outDegree

      public int outDegree(@Nonnull LabeledNode vertex)
      Specified by:
      outDegree in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      vertex - time-point whose outgoing degree is requested
      Returns:
      number of outgoing edges
    • propertyChange

      public void propertyChange(@Nonnull PropertyChangeEvent event)
      Maintains the observer index when a stored node changes its observed proposition.

      Both lookup and mutation remain expected O(1): the previous and proposed propositions address the index directly, avoiding a scan of the graph's vertices.

      Specified by:
      propertyChange in interface PropertyChangeListener
    • removeAnnotation

      public void removeAnnotation(@Nonnull GraphAnnotation annotation)
      Description copied from interface: TemporalConstraintGraph
      Removes a presentation-only annotation from this graph.
      Specified by:
      removeAnnotation in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      annotation - annotation to remove
    • removeEdge

      public boolean removeEdge(@Nonnull String edgeName)
      Description copied from interface: TemporalConstraintGraph
      Removes an edge by name.
      Specified by:
      removeEdge in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      edgeName - name of the edge to remove
      Returns:
      true if the graph changed
    • removeVertex

      public boolean removeVertex(@Nonnull LabeledNode vertex)
      Description copied from interface: TemporalConstraintGraph
      Removes a time-point and all its incident edges.
      Specified by:
      removeVertex in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      vertex - time-point to remove
      Returns:
      true if the graph changed
    • renameEdge

      public void renameEdge(@Nonnull E edge, @Nonnull String newName)
      Renames an edge already contained in this graph, atomically, in O(1) time beyond the usual name-keyed cache invalidation.

      On success, the edge-name index (and any other name-keyed structure of this graph) is updated. The edge's endpoints, constraint type, and values are left untouched: an edge's name carries no semantic reference elsewhere (unlike a node's, see TemporalConstraintGraph.renameNode(LabeledNode, String)), so no further rewrite is needed.

      On failure, this graph and the edge are left exactly as they were: this method validates before mutating anything. This is the only supported way to rename an edge already added to a graph; Component.setName(String) rejects a direct call once the edge has been added.

      Re-keys every edge-name-keyed sparse index in place, preserving both the stored edge object and this graph's edge-enumeration order (getEdges() iterates edgesByName itself). Runs in O(degree) of the edge's two endpoints, beyond the O(1) name-index update.

      Specified by:
      renameEdge in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      edge - an edge already contained in this graph
      newName - the new, non-empty, not-already-used name
    • renameNode

      public void renameNode(@Nonnull LabeledNode node, @Nonnull String newName)
      Renames a node already contained in this graph, atomically.

      On success, every structural index and name-keyed cache of this graph is updated, and every A-Label-based semantic reference to the node's old name — its own LabeledNode.getALabel(), STNUEdge.CaseLabels, upper/lower-case labeled values, and labeled potentials that mention it — is rewritten to the new name, using each structure's own remove/merge API (see TemporalConstraintGraph.rewriteALetterReferences(ALetter, ALetter)). The node's endpoints and every other attribute are left untouched.

      On failure, this graph, the node, and every structure above are left exactly as they were: this method validates before mutating anything. This is the only supported way to rename a node already added to a graph; LabeledNode.setName(String) rejects a direct call once the node has been added (see Component.setName(String)).

      Re-keys every name-keyed sparse index in place, preserving both the stored node object and this graph's vertex-enumeration order (getVertices() iterates verticesByName itself).

      Specified by:
      renameNode in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      node - a node already contained in this graph
      newName - the new, non-empty, not-already-used name
    • replaceContentsFrom

      public void replaceContentsFrom(@Nonnull TemporalConstraintGraph<E> source)
      Replaces this graph's contents with those of source, which must use the same concrete backend and edge implementation. Implementations may transfer their internal representation directly when that is safe; otherwise they retain the nodes and edges while rebuilding their indexes. This operation is intended for algorithms that construct a same-backend companion graph and then install it as the result without exposing a concrete graph class.

      The sparse indexes are rebuilt in O(|V| + |E|) while retaining the canonical node and edge objects. This is linear in the result size and avoids any dense intermediate graph.

      source's check outcome and dispatchability outcome are carried over: unlike a copy, this method installs source's already-finished content, verdict included, into this while keeping this's own object identity — exactly the case where a verdict just established on source must not be silently lost.

      Specified by:
      replaceContentsFrom in interface TemporalConstraintGraph<E extends Edge>
      Parameters:
      source - same-backend graph whose contents become this graph's contents
    • transpose

      public void transpose()
      Reverses every directed edge while retaining the same edge objects and names.

      The endpoint and incidence indexes are rebuilt in O(|E|) time; no O(|V|²) matrix traversal is performed.

      Specified by:
      transpose in interface TemporalConstraintGraph<E extends Edge>