Interface Graph

All Superinterfaces:
Serializable, TetradSerializable
All Known Implementing Classes:
Dag, EdgeListGraph, LagGraph, SemGraph, TimeLagGraph

public interface Graph extends TetradSerializable
Implements a graph capable of storing edges of type N1 *-# N2 where * and # are endpoints of type Endpoint.

We stipulate by extending TetradSerializable that all graphs implementing this interface are serializable. This is because for Tetrad they must be serializable. (For randomUtil, in order to be able to cancelAll operations, they must be serializable.)

Author:
josephramsey
See Also:
  • Field Details

  • Method Details

    • addBidirectedEdge

      boolean addBidirectedEdge(Node node1, Node node2)
      Adds a bidirected edges <-> to the graph.
    • addDirectedEdge

      boolean addDirectedEdge(Node node1, Node node2)
      Adds a directed edge --> to the graph.
    • addUndirectedEdge

      boolean addUndirectedEdge(Node node1, Node node2)
      Adds an undirected edge --- to the graph.
    • addNondirectedEdge

      boolean addNondirectedEdge(Node node1, Node node2)
      Adds a nondirected edges o-o to the graph.
    • addPartiallyOrientedEdge

      boolean addPartiallyOrientedEdge(Node node1, Node node2)
      Adds a partially oriented edge o-> to the graph.
    • addEdge

      boolean addEdge(Edge edge)
      Adds the specified edge to the graph, provided it is not already in the graph.
      Returns:
      true if the edge was added, false if not.
    • addNode

      boolean addNode(Node node)
      Adds a node to the graph. Precondition: The proposed name of the node cannot already be used by any other node in the same graph.
      Returns:
      true if nodes were added, false if not.
    • addPropertyChangeListener

      void addPropertyChangeListener(PropertyChangeListener e)
      Adds a PropertyChangeListener to the graph.
    • clear

      void clear()
      Removes all nodes (and therefore all edges) from the graph.
    • containsEdge

      boolean containsEdge(Edge edge)
      Determines whether this graph contains the given edge.
      Returns:
      true iff the graph contain 'edge'.
    • containsNode

      boolean containsNode(Node node)
      Determines whether this graph contains the given node.
      Returns:
      true iff the graph contains 'node'.
    • equals

      boolean equals(Object o)
      Determines whether this graph is equal to some other graph, in the sense that they contain the same nodes and the sets of edges defined over these nodes in the two graphs are isomorphic typewise. That is, if node A and B exist in both graphs, and if there are, e.g., three edges between A and B in the first graph, two of which are directed edges and one of which is an undirected edge, then in the second graph there must also be two directed edges and one undirected edge between nodes A and B.
      Overrides:
      equals in class Object
    • fullyConnect

      void fullyConnect(Endpoint endpoint)
      Removes all edges from the graph and fully connects it using #-# edges, where # is the given endpoint.
    • reorientAllWith

      void reorientAllWith(Endpoint endpoint)
      Reorients all edges in the graph with the given endpoint.
    • getAdjacentNodes

      List<Node> getAdjacentNodes(Node node)
      Returns:
      a mutable list of nodes adjacent to the given node.
    • getChildren

      List<Node> getChildren(Node node)
      Returns:
      a mutable list of children for a node.
    • getDegree

      int getDegree()
      Returns:
      the connectivity of the graph.
    • getEdge

      Edge getEdge(Node node1, Node node2)
      Returns:
      the edge connecting node1 and node2, provided a unique such edge exists.
      Throws:
      UnsupportedOperationException - if the graph allows multiple edges between node pairs.
    • getDirectedEdge

      Edge getDirectedEdge(Node node1, Node node2)
      Returns:
      the directed edge from node1 to node2, if there is one.
      Throws:
      UnsupportedOperationException - if the graph allows multiple edges between node pairs.
    • getEdges

      List<Edge> getEdges(Node node)
      Returns:
      the list of edges connected to a particular node. No particular ordering of the edges in the list is guaranteed.
    • getEdges

      List<Edge> getEdges(Node node1, Node node2)
      Returns:
      the edges connecting node1 and node2.
    • getEdges

      Set<Edge> getEdges()
      Returns:
      the set of edges in the graph. No particular ordering of the edges in the list is guaranteed.
    • getEndpoint

      Endpoint getEndpoint(Node node1, Node node2)
      Returns:
      the endpoint along the edge from node to node2 at the node2 end.
    • getIndegree

      int getIndegree(Node node)
      Returns:
      the number of arrow endpoints adjacent to a node.
    • getDegree

      int getDegree(Node node)
      Returns:
      the number of arrow endpoints adjacent to a node.
    • getNode

      Node getNode(String name)
      Returns:
      the node with the given string name. In case of accidental duplicates, the first node encountered with the given name is returned. In case no node exists with the given name, null is returned.
    • getNodes

      List<Node> getNodes()
      Returns:
      the list of nodes for the graph.
    • setNodes

      void setNodes(List<Node> nodes)
    • getNodeNames

      List<String> getNodeNames()
      Returns:
      the names of the nodes, in the order of getNodes.
    • getNumEdges

      int getNumEdges()
      Returns:
      the number of edges in the (entire) graph.
    • getNumEdges

      int getNumEdges(Node node)
      Returns:
      the number of edges in the graph which are connected to a particular node.
    • getNumNodes

      int getNumNodes()
      Returns:
      the number of nodes in the graph.
    • getOutdegree

      int getOutdegree(Node node)
      Returns:
      the number of null endpoints adjacent to an edge.
    • getParents

      List<Node> getParents(Node node)
      Returns:
      the list of parents for a node.
    • isAdjacentTo

      boolean isAdjacentTo(Node node1, Node node2)
      Returns:
      true iff node1 is adjacent to node2 in the graph.
    • isChildOf

      boolean isChildOf(Node node1, Node node2)
      Returns:
      true iff node1 is a child of node2 in the graph.
    • isParentOf

      boolean isParentOf(Node node1, Node node2)
      Determines whether node1 is a parent of node2.
    • isDefNoncollider

      boolean isDefNoncollider(Node node1, Node node2, Node node3)
      Added by ekorber, 2004/6/9.
      Returns:
      true if node 2 is a definite noncollider between 1 and 3
    • isDefCollider

      boolean isDefCollider(Node node1, Node node2, Node node3)
      Added by ekorber, 2004/6/9.
      Returns:
      true if node 2 is a definite collider between 1 and 3
    • isExogenous

      boolean isExogenous(Node node)
      Returns:
      true iff the given node is exogenous in the graph.
    • getNodesInTo

      List<Node> getNodesInTo(Node node, Endpoint n)
      Nodes adjacent to the given node with the given proximal endpoint.
    • getNodesOutTo

      List<Node> getNodesOutTo(Node node, Endpoint n)
      Nodes adjacent to the given node with the given distal endpoint.
    • removeEdge

      boolean removeEdge(Edge edge)
      Removes the given edge from the graph.
      Returns:
      true if the edge was removed, false if not.
    • removeEdge

      boolean removeEdge(Node node1, Node node2)
      Removes the edge connecting the two given nodes, provided there is exactly one such edge.
      Throws:
      UnsupportedOperationException - if multiple edges between node pairs are not supported.
    • removeEdges

      boolean removeEdges(Node node1, Node node2)
      Removes all edges connecting node A to node B. In most cases, this will remove at most one edge, but since multiple edges are permitted in some graph implementations, the number will in some cases be greater than one.
      Returns:
      true if edges were removed, false if not.
    • removeEdges

      boolean removeEdges(Collection<Edge> edges)
      Iterates through the list and removes any permissible edges found. The order in which edges are added is the order in which they are presented in the iterator.
      Returns:
      true if edges were added, false if not.
    • removeNode

      boolean removeNode(Node node)
      Removes a node from the graph.
      Returns:
      true if the node was removed, false if not.
    • removeNodes

      boolean removeNodes(List<Node> nodes)
      Iterates through the list and removes any permissible nodes found. The order in which nodes are removed is the order in which they are presented in the iterator.
      Returns:
      true if nodes were added, false if not.
    • setEndpoint

      boolean setEndpoint(Node from, Node to, Endpoint endPoint)
      Sets the endpoint type at the 'to' end of the edge from 'from' to 'to' to the given endpoint. Note: NOT CONSTRAINT SAFE
    • subgraph

      Graph subgraph(List<Node> nodes)
      Constructs and returns a subgraph consisting of a given subset of the nodes of this graph together with the edges between them.
    • toString

      String toString()
      Overrides:
      toString in class Object
      Returns:
      a string representation of the graph.
    • transferNodesAndEdges

      void transferNodesAndEdges(Graph graph) throws IllegalArgumentException
      Transfers nodes and edges from one graph to another. One way this is used is to change graph types. One constructs a new graph based on the old graph, and this method is called to transfer the nodes and edges of the old graph to the new graph.
      Parameters:
      graph - the graph from which nodes and edges are to be pilfered.
      Throws:
      IllegalArgumentException - This exception is thrown if adding some node.
    • transferAttributes

      void transferAttributes(Graph graph) throws IllegalArgumentException
      Throws:
      IllegalArgumentException
    • paths

      Paths paths()
    • isParameterizable

      boolean isParameterizable(Node node)
      Returns:
      true if the given node is parameterizable.
    • isTimeLagModel

      boolean isTimeLagModel()
      Returns:
      true if this is a time lag model, in which case getTimeLagGraph() returns the graph.
    • getTimeLagGraph

      TimeLagGraph getTimeLagGraph()
      Returns:
      the underlying time lag model, if there is one; otherwise, returns null.
    • getSepset

      Set<Node> getSepset(Node n1, Node n2)
    • getAllAttributes

      Map<String,Object> getAllAttributes()
    • getAttribute

      Object getAttribute(String key)
    • removeAttribute

      void removeAttribute(String key)
    • addAttribute

      void addAttribute(String key, Object value)
    • getUnderLines

      Set<Triple> getUnderLines()
    • getDottedUnderlines

      Set<Triple> getDottedUnderlines()
    • getAmbiguousTriples

      Set<Triple> getAmbiguousTriples()
    • setAmbiguousTriples

      void setAmbiguousTriples(Set<Triple> triples)
    • isAmbiguousTriple

      boolean isAmbiguousTriple(Node x, Node y, Node z)
      States whether r-s-r is an underline triple or not.
    • isUnderlineTriple

      boolean isUnderlineTriple(Node x, Node y, Node z)
      States whether r-s-r is an underline triple or not.
    • addAmbiguousTriple

      void addAmbiguousTriple(Node x, Node y, Node z)
    • addUnderlineTriple

      void addUnderlineTriple(Node x, Node y, Node z)
    • addDottedUnderlineTriple

      void addDottedUnderlineTriple(Node x, Node y, Node z)
    • removeAmbiguousTriple

      void removeAmbiguousTriple(Node x, Node y, Node z)
    • removeUnderlineTriple

      void removeUnderlineTriple(Node x, Node y, Node z)
    • removeDottedUnderlineTriple

      void removeDottedUnderlineTriple(Node x, Node y, Node z)
    • setUnderLineTriples

      void setUnderLineTriples(Set<Triple> triples)
    • setDottedUnderLineTriples

      void setDottedUnderLineTriples(Set<Triple> triples)
    • removeTriplesNotInGraph

      void removeTriplesNotInGraph()