Package edu.cmu.tetrad.graph
Class Dag
java.lang.Object
edu.cmu.tetrad.graph.Dag
- All Implemented Interfaces:
- Graph,- TetradSerializable,- Serializable
Represents a directed acyclic graph--that is, a graph containing only directed edges, with no cycles. Variables are
 permitted to be either measured or latent, with at most one edge per node pair, and no edges to self.
- Version:
- $Id: $Id
- Author:
- josephramsey
- See Also:
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidaddAmbiguousTriple(Node x, Node y, Node z) Adds an ambiguous triple to the list of ambiguous triples.voidaddAttribute(String key, Object value) Adds an attribute to the graph.booleanaddBidirectedEdge(Node node1, Node node2) Adds a bidirectional edge between two nodes.booleanaddDirectedEdge(Node node1, Node node2) Adds a directed edge between two nodes.voidaddDottedUnderlineTriple(Node x, Node y, Node z) Adds a dotted underline triple to the graph.booleanAdds a directed edge to the Directed Acyclic Graph (DAG).booleanAdds a Node to the graph.booleanaddNondirectedEdge(Node node1, Node node2) Adds a nondirected edge between two nodes in the graph.booleanaddPartiallyOrientedEdge(Node node1, Node node2) Adds a partially oriented edge between two nodes.voidAdds a PropertyChangeListener to the underlying graph object.voidaddUnderlineTriple(Node x, Node y, Node z) Adds an underline triple to the current object.booleanaddUndirectedEdge(Node node1, Node node2) Adds an undirected edge between two nodes.voidclear()clear.booleancontainsEdge(Edge edge) Checks if the given edge is present in the graph.booleancontainsNode(Node node) Checks if the given Node object is contained in the graph.booleanCompares thisGraphobject with the specified object for equality.voidfullyConnect(Endpoint endpoint) Fully connects the given endpoint.getAdjacentNodes(Node node) Retrieves the adjacent nodes of a given node in the graph.getAllAttributes.Returns a set of ambiguous triples.getAttribute(String key) Retrieves the value associated with the given key in the attribute map.getChildren(Node node) Retrieves the children of a specified Node in the graph.intgetDegree.intReturns the degree of a given node in the graph.getDirectedEdge(Node node1, Node node2) Returns the directed edge between the given nodes, if one exists in the graph.getDottedUnderlines.Retrieves the edge between two nodes in the graph.getEdges()getEdges.Returns a list of edges connected to the given node.Returns a list of edges between the specified nodes in the graph.getEndpoint(Node node1, Node node2) Returns the endpoint between two nodes in the graph.intgetIndegree(Node node) Returns the indegree of the specified node in the graph.Retrieves the node in the graph with the specified name.getNodeNames.getNodes()getNodes.getNodesInTo(Node node, Endpoint n) Retrieves a list of nodes in the given graph that have edges pointing into the specified node and endpoint.getNodesOutTo(Node node, Endpoint n) Retrieves a list of nodes that have outgoing edges to a specified node and endpoint.intgetNumEdges.intgetNumEdges(Node node) Returns the number of edges connected to the specified node.intgetNumNodes.intgetOutdegree(Node node) Returns the outdegree of the given node.getParents(Node node) Retrieves the list of parent nodes for a given node in the graph.getSepset(Node n1, Node n2, IndependenceTest test) Returns the sepset between two given nodes in the graph.getTimeLagGraph.Retrieves the set of underlined triples.booleanisAdjacentTo(Node node1, Node node2) Determines whether two nodes are adjacent in the graph.booleanisAmbiguousTriple(Node x, Node y, Node z) Determines if a triple of nodes is ambiguous.booleanChecks if the given node1 is a child of node2 in the graph.booleanisDefCollider(Node node1, Node node2, Node node3) Checks if there is a definite collider between three nodes in the graph.booleanisDefNoncollider(Node node1, Node node2, Node node3) Checks if three given nodes form a definite non-collider in a graph.booleanisExogenous(Node node) Checks whether a given node is exogenous.booleanisParameterizable(Node node) Checks if the given node is parameterizable.booleanisParentOf(Node node1, Node node2) Determines if a given node is a parent of another node in the graph.booleanisTimeLagModel.booleanisUnderlineTriple(Node x, Node y, Node z) Determines if a triple of nodes is underlined.paths()paths.voidremoveAmbiguousTriple(Node x, Node y, Node z) Removes an ambiguous triple from the list of ambiguous triples.voidremoveAttribute(String key) Removes an attribute from the graph.voidremoveDottedUnderlineTriple(Node x, Node y, Node z) Removes a dotted underline triple from the set of triples.booleanremoveEdge(Edge edge) Removes a given edge from the graph.booleanremoveEdge(Node node1, Node node2) Removes the edge between two nodes in the graph.booleanremoveEdges(Node node1, Node node2) Removes an edge between two nodes.booleanremoveEdges(Collection<Edge> edges) Removes the given edges from the graph.booleanremoveNode(Node node) Removes the specified node from the graph.booleanremoveNodes(List<Node> nodes) Removes the specified nodes from the graph.voidRemoves triples from the graph that contain nodes not present in the graph or are not adjacent to each other.voidremoveUnderlineTriple(Node x, Node y, Node z) Removes an underline triple from the list of underline triples.voidreorientAllWith(Endpoint endpoint) Reorients all edges in a Directed Acyclic Graph (DAG) with a single endpoint type.static DagGenerates a simple exemplar of this class to test serialization.voidsetAmbiguousTriples(Set<Triple> triples) Sets the ambiguous triples for the object.voidsetDottedUnderLineTriples(Set<Triple> triples) Sets the dotted underline triples for the given set of Triples.booleansetEndpoint(Node from, Node to, Endpoint endPoint) Sets the endpoint of a directed edge between two nodes in a graph.voidSet the nodes of the graph.voidsetUnderLineTriples(Set<Triple> triples) Sets the underlined triples.Returns a subgraph of the current graph consisting only of the specified nodes.toString()toString.voidtransferAttributes(Graph graph) Transfers attributes from the given graph to the current graph.voidtransferNodesAndEdges(Graph graph) Transfers nodes and edges from the given graph to the current graph.Methods inherited from class java.lang.ObjectgetClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface edu.cmu.tetrad.graph.GraphexistsSemidirectedPath, isAncestorOf
- 
Constructor Details- 
Dagpublic Dag()Constructs a new directed acyclic graph (DAG).
- 
DagConstructor for Dag. - Parameters:
- nodes- a- Listobject
 
- 
DagConstructs a new directed acyclic graph from the given graph object.- Parameters:
- graph- the graph to base the new DAG on.
- Throws:
- IllegalArgumentException- if the given graph cannot for some reason be converted into a DAG.
 
 
- 
- 
Method Details- 
serializableInstanceGenerates a simple exemplar of this class to test serialization.- Returns:
- a Dagobject
 
- 
addBidirectedEdgeAdds a bidirectional edge between two nodes.- Specified by:
- addBidirectedEdgein interface- Graph
- Parameters:
- node1- the first node to connect (a- Nodeobject)
- node2- the second node to connect (a- Nodeobject)
- Returns:
- true if the bidirectional edge was successfully added, false otherwise
 
- 
addDirectedEdgeAdds a directed edge between two nodes.- Specified by:
- addDirectedEdgein interface- Graph
- Parameters:
- node1- the first node to connect (source node)
- node2- the second node to connect (target node)
- Returns:
- true if the directed edge is successfully added, false otherwise
 
- 
addUndirectedEdgeAdds an undirected edge between two nodes.- Specified by:
- addUndirectedEdgein interface- Graph
- Parameters:
- node1- the first node to connect (a- Nodeobject)
- node2- the second node to connect (a- Nodeobject)
- Returns:
- true if the undirected edge is successfully added, false otherwise
 
- 
addNondirectedEdgeAdds a nondirected edge between two nodes in the graph.- Specified by:
- addNondirectedEdgein interface- Graph
- Parameters:
- node1- the first node to connect (a- Nodeobject)
- node2- the second node to connect (a- Nodeobject)
- Returns:
- true if the edge was successfully added, false otherwise
 
- 
addPartiallyOrientedEdgeAdds a partially oriented edge between two nodes.- Specified by:
- addPartiallyOrientedEdgein interface- Graph
- Parameters:
- node1- the first node to be connected
- node2- the second node to be connected
- Returns:
- true if the partially oriented edge is added successfully, false otherwise
- Throws:
- UnsupportedOperationException- if the graph is a directed acyclic graph (DAG)
 
- 
addEdgeAdds a directed edge to the Directed Acyclic Graph (DAG).- Specified by:
- addEdgein interface- Graph
- Parameters:
- edge- the directed- Edgeobject to be added
- Returns:
- true if the edge is successfully added, false otherwise
- Throws:
- IllegalArgumentException- if the provided edge is not a directed edge or adding the edge would result in a cycle
 
- 
addNodeAdds a Node to the graph.
- 
addPropertyChangeListenerAdds a PropertyChangeListener to the underlying graph object.- Specified by:
- addPropertyChangeListenerin interface- Graph
- Parameters:
- e- the PropertyChangeListener to be added
 
- 
clearpublic void clear()clear. 
- 
containsEdgeChecks if the given edge is present in the graph.- Specified by:
- containsEdgein interface- Graph
- Parameters:
- edge- the edge to check if present in the graph
- Returns:
- true if the edge is present in the graph, false otherwise
 
- 
containsNodeChecks if the given Node object is contained in the graph.- Specified by:
- containsNodein interface- Graph
- Parameters:
- node- The Node object to check for containment. Must not be null.
- Returns:
- true if the Node object is contained in the graph, false otherwise.
 
- 
equalsCompares thisGraphobject with the specified object for equality.
- 
fullyConnectFully connects the given endpoint.- Specified by:
- fullyConnectin interface- Graph
- Parameters:
- endpoint- The endpoint to fully connect.
- Throws:
- UnsupportedOperationException- If the endpoint is a single endpoint type and cannot be fully connected.
 
- 
reorientAllWithReorients all edges in a Directed Acyclic Graph (DAG) with a single endpoint type.- Specified by:
- reorientAllWithin interface- Graph
- Parameters:
- endpoint- The type of endpoint to reorient all edges with. Must be an instance of `edu.cmu.tetrad.graph.Endpoint`.
- Throws:
- UnsupportedOperationException- if attempting to reorient all edges in a DAG with a single endpoint type.
 
- 
getAdjacentNodesRetrieves the adjacent nodes of a given node in the graph.- Specified by:
- getAdjacentNodesin interface- Graph
- Parameters:
- node- the node for which to retrieve adjacent nodes
- Returns:
- a List of nodes that are adjacent to the given node
 
- 
getChildrenRetrieves the children of a specified Node in the graph.- Specified by:
- getChildrenin interface- Graph
- Parameters:
- node- The Node object whose children are to be retrieved.
- Returns:
- A List of Node objects representing the children of the specified node.
 
- 
getDegreepublic int getDegree()getDegree. 
- 
getEdgeRetrieves the edge between two nodes in the graph.
- 
getDirectedEdgeReturns the directed edge between the given nodes, if one exists in the graph.- Specified by:
- getDirectedEdgein interface- Graph
- Parameters:
- node1- the first Node object
- node2- the second Node object
- Returns:
- the directed edge between the given nodes, or null if no edge exists
 
- 
getEdgesReturns a list of edges connected to the given node.
- 
getEdgesReturns a list of edges between the specified nodes in the graph.
- 
getEdgesgetEdges. 
- 
getEndpointReturns the endpoint between two nodes in the graph.- Specified by:
- getEndpointin interface- Graph
- Parameters:
- node1- a Node object representing the first node
- node2- a Node object representing the second node
- Returns:
- the Endpoint object representing the endpoint between the two nodes
 
- 
getIndegreeReturns the indegree of the specified node in the graph.- Specified by:
- getIndegreein interface- Graph
- Parameters:
- node- the node for which to find the indegree
- Returns:
- the indegree of the specified node
 
- 
getDegreeReturns the degree of a given node in the graph.
- 
getNodeRetrieves the node in the graph with the specified name.
- 
getNodesgetNodes. 
- 
setNodesSet the nodes of the graph.
- 
getNodeNamesgetNodeNames. - Specified by:
- getNodeNamesin interface- Graph
- Returns:
- a Listobject
 
- 
getNumEdgespublic int getNumEdges()getNumEdges. - Specified by:
- getNumEdgesin interface- Graph
- Returns:
- a int
 
- 
getNumEdgesReturns the number of edges connected to the specified node.- Specified by:
- getNumEdgesin interface- Graph
- Parameters:
- node- the node for which to retrieve the number of edges
- Returns:
- the number of edges connected to the specified node
 
- 
getNumNodespublic int getNumNodes()getNumNodes. - Specified by:
- getNumNodesin interface- Graph
- Returns:
- a int
 
- 
getOutdegreeReturns the outdegree of the given node.- Specified by:
- getOutdegreein interface- Graph
- Parameters:
- node- a- Nodeobject
- Returns:
- the outdegree of the node
 
- 
getParentsRetrieves the list of parent nodes for a given node in the graph.- Specified by:
- getParentsin interface- Graph
- Parameters:
- node- the node for which to retrieve the parent nodes
- Returns:
- the list of parent nodes for the given node
 
- 
isAdjacentToDetermines whether two nodes are adjacent in the graph.- Specified by:
- isAdjacentToin interface- Graph
- Parameters:
- node1- The first node to check adjacency.
- node2- The second node to check adjacency.
- Returns:
- true if the nodes are adjacent, false otherwise.
 
- 
isChildOfChecks if the given node1 is a child of node2 in the graph.
- 
isParentOfDetermines if a given node is a parent of another node in the graph.- Specified by:
- isParentOfin interface- Graph
- Parameters:
- node1- the first node to be compared.
- node2- the second node to be compared.
- Returns:
- true if node1 is a parent of node2, false otherwise.
 
- 
isDefNoncolliderChecks if three given nodes form a definite non-collider in a graph.- Specified by:
- isDefNoncolliderin interface- Graph
- Parameters:
- node1- the first node
- node2- the second node
- node3- the third node
- Returns:
- true if the three nodes form a definite non-collider, false otherwise
 
- 
isDefColliderChecks if there is a definite collider between three nodes in the graph.- Specified by:
- isDefColliderin interface- Graph
- Parameters:
- node1- the first node to check
- node2- the second node to check
- node3- the third node to check
- Returns:
- true if there is a definite collider, false otherwise
 
- 
isExogenousChecks whether a given node is exogenous.- Specified by:
- isExogenousin interface- Graph
- Parameters:
- node- A- Nodeobject representing the node to be checked.
- Returns:
- True if the given node is exogenous, false otherwise.
 
- 
getNodesInToRetrieves a list of nodes in the given graph that have edges pointing into the specified node and endpoint.- Specified by:
- getNodesInToin interface- Graph
- Parameters:
- node- the node to check for incoming edges
- n- the endpoint to check for incoming edges
- Returns:
- a list of nodes with edges pointing into the specified node and endpoint
 
- 
getNodesOutToRetrieves a list of nodes that have outgoing edges to a specified node and endpoint.- Specified by:
- getNodesOutToin interface- Graph
- Parameters:
- node- The node to which the outgoing edges lead.
- n- The endpoint to which the outgoing edges connect to the specified node.
- Returns:
- A list of nodes that have outgoing edges to the specified node and endpoint.
 
- 
removeEdgeRemoves a given edge from the graph.- Specified by:
- removeEdgein interface- Graph
- Parameters:
- edge- the edge to be removed
- Returns:
- true if the edge was successfully removed, false otherwise
 
- 
removeEdgeRemoves the edge between two nodes in the graph.- Specified by:
- removeEdgein interface- Graph
- Parameters:
- node1- the first node to remove the edge from
- node2- the second node to remove the edge to
- Returns:
- true if the edge was successfully removed, false otherwise
 
- 
removeEdgesRemoves an edge between two nodes.- Specified by:
- removeEdgesin interface- Graph
- Parameters:
- node1- the first node
- node2- the second node
- Returns:
- true if the edge was successfully removed, false otherwise
 
- 
removeEdgesRemoves the given edges from the graph.- Specified by:
- removeEdgesin interface- Graph
- Parameters:
- edges- a collection of edges to be removed from the graph
- Returns:
- true if all the edges were successfully removed, false otherwise
 
- 
removeNodeRemoves the specified node from the graph.- Specified by:
- removeNodein interface- Graph
- Parameters:
- node- the node to be removed from the graph
- Returns:
- true if the node was successfully removed, false otherwise
 
- 
removeNodesRemoves the specified nodes from the graph.- Specified by:
- removeNodesin interface- Graph
- Parameters:
- nodes- a- Listof nodes to remove
- Returns:
- trueif the nodes were successfully removed,- falseotherwise
 
- 
setEndpointSets the endpoint of a directed edge between two nodes in a graph.- Specified by:
- setEndpointin interface- Graph
- Parameters:
- from- the starting node of the edge
- to- the ending node of the edge
- endPoint- the endpoint of the directed edge
- Returns:
- trueif the endpoint was successfully set,- falseotherwise
 
- 
subgraphReturns a subgraph of the current graph consisting only of the specified nodes.
- 
toStringtoString. 
- 
transferNodesAndEdgesTransfers nodes and edges from the given graph to the current graph.- Specified by:
- transferNodesAndEdgesin interface- Graph
- Parameters:
- graph- the graph from which nodes and edges are to be pilfered
- Throws:
- IllegalArgumentException- if the graph is null, or if adding a node/edge fails
- NullPointerException- if no graph is provided
 
- 
transferAttributesTransfers attributes from the given graph to the current graph.- Specified by:
- transferAttributesin interface- Graph
- Parameters:
- graph- a- Graphobject representing the graph from which attributes will be transferred
- Throws:
- IllegalArgumentException- if the graph is null
 
- 
pathspaths. 
- 
isParameterizableChecks if the given node is parameterizable.- Specified by:
- isParameterizablein interface- Graph
- Parameters:
- node- the node to be checked for parameterizability
- Returns:
- trueif the node is parameterizable,- falseotherwise
 
- 
isTimeLagModelpublic boolean isTimeLagModel()isTimeLagModel. - Specified by:
- isTimeLagModelin interface- Graph
- Returns:
- a boolean
 
- 
getTimeLagGraphgetTimeLagGraph. - Specified by:
- getTimeLagGraphin interface- Graph
- Returns:
- a TimeLagGraphobject
 
- 
getSepsetReturns the sepset between two given nodes in the graph.
- 
getAllAttributesgetAllAttributes. - Specified by:
- getAllAttributesin interface- Graph
- Returns:
- a Mapobject
 
- 
getAttributeRetrieves the value associated with the given key in the attribute map.- Specified by:
- getAttributein interface- Graph
- Parameters:
- key- the key of the attribute to be retrieved
- Returns:
- the value associated with the given key
 
- 
removeAttributeRemoves an attribute from the graph.- Specified by:
- removeAttributein interface- Graph
- Parameters:
- key- the key of the attribute to remove
 
- 
addAttributeAdds an attribute to the graph.- Specified by:
- addAttributein interface- Graph
- Parameters:
- key- the key of the attribute
- value- the value of the attribute
 
- 
getAmbiguousTriplesReturns a set of ambiguous triples.- Specified by:
- getAmbiguousTriplesin interface- Graph
- Returns:
- a set of ambiguous triples
 
- 
setAmbiguousTriplesSets the ambiguous triples for the object.- Specified by:
- setAmbiguousTriplesin interface- Graph
- Parameters:
- triples- a set of Triple objects representing ambiguous triples
 
- 
getUnderLinesRetrieves the set of underlined triples.- Specified by:
- getUnderLinesin interface- Graph
- Returns:
- The set of underlined triples as a SetofTripleobjects.
 
- 
getDottedUnderlinesgetDottedUnderlines. - Specified by:
- getDottedUnderlinesin interface- Graph
- Returns:
- a Setobject
 
- 
isAmbiguousTripleDetermines if a triple of nodes is ambiguous.- Specified by:
- isAmbiguousTriplein interface- Graph
- Parameters:
- x- the first node in the triple.
- y- the second node in the triple.
- z- the third node in the triple.
- Returns:
- true if the triple is ambiguous, false otherwise.
 
- 
isUnderlineTripleDetermines if a triple of nodes is underlined.- Specified by:
- isUnderlineTriplein interface- Graph
- Parameters:
- x- the first Node in the triple
- y- the second Node in the triple
- z- the third Node in the triple
- Returns:
- true if the triple is underlined, false otherwise
 
- 
addAmbiguousTripleAdds an ambiguous triple to the list of ambiguous triples. An ambiguous triple consists of three nodes: x, y, and z.- Specified by:
- addAmbiguousTriplein interface- Graph
- Parameters:
- x- the first node in the ambiguous triple
- y- the second node in the ambiguous triple
- z- the third node in the ambiguous triple
 
- 
addUnderlineTripleAdds an underline triple to the current object.- Specified by:
- addUnderlineTriplein interface- Graph
- Parameters:
- x- The first- Nodeobject in the triple.
- y- The second- Nodeobject in the triple.
- z- The third- Nodeobject in the triple.
 
- 
addDottedUnderlineTripleAdds a dotted underline triple to the graph.- Specified by:
- addDottedUnderlineTriplein interface- Graph
- Parameters:
- x- The first node of the triple.
- y- The second node of the triple.
- z- The third node of the triple.
 
- 
removeAmbiguousTripleRemoves an ambiguous triple from the list of ambiguous triples.- Specified by:
- removeAmbiguousTriplein interface- Graph
- Parameters:
- x- The first node of the triple.
- y- The second node of the triple.
- z- The third node of the triple.
 
- 
removeUnderlineTripleRemoves an underline triple from the list of underline triples.- Specified by:
- removeUnderlineTriplein interface- Graph
- Parameters:
- x- The first- Nodeobject in the underline triple.
- y- The second- Nodeobject in the underline triple.
- z- The third- Nodeobject in the underline triple.
 
- 
removeDottedUnderlineTripleRemoves a dotted underline triple from the set of triples.- Specified by:
- removeDottedUnderlineTriplein interface- Graph
- Parameters:
- x- the first node of the triple to be removed
- y- the second node of the triple to be removed
- z- the third node of the triple to be removed
 
- 
setUnderLineTriplesSets the underlined triples.- Specified by:
- setUnderLineTriplesin interface- Graph
- Parameters:
- triples- a set of triples to be set as underlined
 
- 
setDottedUnderLineTriplesSets the dotted underline triples for the given set of Triples. Clears the existing dotted underline triples and adds the new ones from the set.- Specified by:
- setDottedUnderLineTriplesin interface- Graph
- Parameters:
- triples- a Set of Triples to set as dotted underline triples
 
- 
removeTriplesNotInGraphpublic void removeTriplesNotInGraph()Removes triples from the graph that contain nodes not present in the graph or are not adjacent to each other.- Specified by:
- removeTriplesNotInGraphin interface- Graph
 
 
-