Class ReplicatingGraph

java.lang.Object
edu.cmu.tetrad.graph.EdgeListGraph
edu.cmu.tetrad.graph.ReplicatingGraph
All Implemented Interfaces:
Graph, TripleClassifier, TetradSerializable, Serializable

public class ReplicatingGraph extends EdgeListGraph
EdgeListGraph subclass that applies an EdgeReplicationPolicy whenever edges are added/removed or endpoints are oriented.

Only the mutating operations are overridden; everything else uses the standard EdgeListGraph behavior.

See Also:
  • Constructor Details

    • ReplicatingGraph

      public ReplicatingGraph(EdgeReplicationPolicy policy)
      Creates an empty repeating graph using the given policy.
      Parameters:
      policy - The policy.
    • ReplicatingGraph

      public ReplicatingGraph(ReplicatingGraph g)
      Copies nodes+edges from g and installs the policy.
      Parameters:
      g - the graph to copy.
    • ReplicatingGraph

      public ReplicatingGraph(Graph g, EdgeReplicationPolicy policy)
      Creates a new ReplicatingGraph by copying the structure and attributes from the provided graph and applying the specified edge replication policy.
      Parameters:
      g - the original graph to be replicated; must not be null
      policy - the edge replication policy to apply to the new graph; must not be null
    • ReplicatingGraph

      public ReplicatingGraph(List<Node> nodes, EdgeReplicationPolicy policy)
      Constructs a new ReplicatingGraph using the provided list of nodes and edge replication policy.
      Parameters:
      nodes - the list of nodes to initialize the graph with
      policy - the edge replication policy to be applied in the graph; must not be null
  • Method Details

    • svar

      public static ReplicatingGraph svar(List<Node> nodes)
      Constructs a ReplicatingGraph using the given list of nodes and applies a default LagReplicationPolicy for edge replication.
      Parameters:
      nodes - the list of nodes to initialize the graph with; must not be null
      Returns:
      a new instance of ReplicatingGraph with the provided nodes and a default edge replication policy
    • svar

      public static ReplicatingGraph svar()
      Creates a new instance of ReplicatingGraph using a default LagReplicationPolicy.
      Returns:
      a new ReplicatingGraph instance with the default LagReplicationPolicy.
    • addEdge

      public boolean addEdge(Edge e) throws IllegalArgumentException
      Adds an edge to the graph and performs additional processing to mirror edges based on the defined edge replication policy.
      Specified by:
      addEdge in interface Graph
      Overrides:
      addEdge in class EdgeListGraph
      Parameters:
      e - the edge to be added to the graph; must not be null
      Returns:
      true if the graph was modified as a result of this operation, false otherwise
      Throws:
      IllegalArgumentException - if the provided edge is invalid or does not meet the requirements
    • removeEdge

      public boolean removeEdge(Edge e)
      Removes an edge from the graph, and if applicable, removes its mirrored counterparts according to the edge replication policy.
      Specified by:
      removeEdge in interface Graph
      Overrides:
      removeEdge in class EdgeListGraph
      Parameters:
      e - the edge to be removed; must not be null
      Returns:
      true if the graph was modified as a result of this operation, false otherwise
    • removeEdge

      public boolean removeEdge(Node a, Node b)
      Removes an edge between the specified nodes, if such an edge exists in the graph. This operation is synchronized to ensure thread safety.
      Specified by:
      removeEdge in interface Graph
      Overrides:
      removeEdge in class EdgeListGraph
      Parameters:
      a - the first node of the edge
      b - the second node of the edge
      Returns:
      true if the edge was successfully removed and the graph was modified, false otherwise
    • setEndpoint

      public boolean setEndpoint(Node from, Node to, Endpoint ep) throws IllegalArgumentException
      Mirrors endpoint changes across all policy-mirrored edges. This keeps algorithms that orient by setEndpoint() fully SVAR-aware without needing a custom endpoint strategy.
      Specified by:
      setEndpoint in interface Graph
      Overrides:
      setEndpoint in class EdgeListGraph
      Parameters:
      from - the node from which the edge originates
      to - the node to which the edge points
      ep - a Endpoint object
      Returns:
      true if the endpoint was successfully set and the graph was modified, false otherwise
      Throws:
      IllegalArgumentException
    • reorientAllWith

      public void reorientAllWith(Endpoint ep)
      Reorients all applicable edges in the graph to align with the specified endpoint. This method leverages the superclass implementation to perform the reorientation and ensures that any custom mirroring behavior required by this class is preserved.
      Specified by:
      reorientAllWith in interface Graph
      Overrides:
      reorientAllWith in class EdgeListGraph
      Parameters:
      ep - the endpoint configuration to apply to all applicable edges; must not be null
    • getReplicationPolicy

      public EdgeReplicationPolicy getReplicationPolicy()
      Retrieves the current edge replication policy for the graph.
      Returns:
      the EdgeReplicationPolicy used by the graph for determining how edges should be mirrored and synchronized.