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 Summary
Constructors -
Method Summary
Modifier 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.Object
getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface edu.cmu.tetrad.graph.Graph
copy, existsSemidirectedPath, isAncestorOf
-
Constructor Details
-
Dag
public Dag()Constructs a new directed acyclic graph (DAG). -
Dag
Constructor for Dag.
- Parameters:
nodes- aListobject
-
Dag
Constructs 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
-
serializableInstance
Generates a simple exemplar of this class to test serialization.- Returns:
- a
Dagobject
-
addBidirectedEdge
Adds a bidirectional edge between two nodes.- Specified by:
addBidirectedEdgein interfaceGraph- Parameters:
node1- the first node to connect (aNodeobject)node2- the second node to connect (aNodeobject)- Returns:
- true if the bidirectional edge was successfully added, false otherwise
-
addDirectedEdge
Adds a directed edge between two nodes.- Specified by:
addDirectedEdgein interfaceGraph- 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
-
addUndirectedEdge
Adds an undirected edge between two nodes.- Specified by:
addUndirectedEdgein interfaceGraph- Parameters:
node1- the first node to connect (aNodeobject)node2- the second node to connect (aNodeobject)- Returns:
- true if the undirected edge is successfully added, false otherwise
-
addNondirectedEdge
Adds a nondirected edge between two nodes in the graph.- Specified by:
addNondirectedEdgein interfaceGraph- Parameters:
node1- the first node to connect (aNodeobject)node2- the second node to connect (aNodeobject)- Returns:
- true if the edge was successfully added, false otherwise
-
addPartiallyOrientedEdge
Adds a partially oriented edge between two nodes.- Specified by:
addPartiallyOrientedEdgein interfaceGraph- Parameters:
node1- the first node to be connectednode2- 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)
-
addEdge
Adds a directed edge to the Directed Acyclic Graph (DAG).- Specified by:
addEdgein interfaceGraph- Parameters:
edge- the directedEdgeobject 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
-
addNode
Adds a Node to the graph. -
addPropertyChangeListener
Adds a PropertyChangeListener to the underlying graph object.- Specified by:
addPropertyChangeListenerin interfaceGraph- Parameters:
e- the PropertyChangeListener to be added
-
clear
public void clear()clear.
-
containsEdge
Checks if the given edge is present in the graph.- Specified by:
containsEdgein interfaceGraph- Parameters:
edge- the edge to check if present in the graph- Returns:
- true if the edge is present in the graph, false otherwise
-
containsNode
Checks if the given Node object is contained in the graph.- Specified by:
containsNodein interfaceGraph- 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.
-
equals
Compares thisGraphobject with the specified object for equality. -
fullyConnect
Fully connects the given endpoint.- Specified by:
fullyConnectin interfaceGraph- Parameters:
endpoint- The endpoint to fully connect.- Throws:
UnsupportedOperationException- If the endpoint is a single endpoint type and cannot be fully connected.
-
reorientAllWith
Reorients all edges in a Directed Acyclic Graph (DAG) with a single endpoint type.- Specified by:
reorientAllWithin interfaceGraph- 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.
-
getAdjacentNodes
Retrieves the adjacent nodes of a given node in the graph.- Specified by:
getAdjacentNodesin interfaceGraph- Parameters:
node- the node for which to retrieve adjacent nodes- Returns:
- a List of nodes that are adjacent to the given node
-
getChildren
Retrieves the children of a specified Node in the graph.- Specified by:
getChildrenin interfaceGraph- Parameters:
node- The Node object whose children are to be retrieved.- Returns:
- A List of Node objects representing the children of the specified node.
-
getDegree
public int getDegree()getDegree.
-
getEdge
Retrieves the edge between two nodes in the graph. -
getDirectedEdge
Returns the directed edge between the given nodes, if one exists in the graph.- Specified by:
getDirectedEdgein interfaceGraph- Parameters:
node1- the first Node objectnode2- the second Node object- Returns:
- the directed edge between the given nodes, or null if no edge exists
-
getEdges
Returns a list of edges connected to the given node. -
getEdges
Returns a list of edges between the specified nodes in the graph. -
getEdges
getEdges.
-
getEndpoint
Returns the endpoint between two nodes in the graph.- Specified by:
getEndpointin interfaceGraph- Parameters:
node1- a Node object representing the first nodenode2- a Node object representing the second node- Returns:
- the Endpoint object representing the endpoint between the two nodes
-
getIndegree
Returns the indegree of the specified node in the graph.- Specified by:
getIndegreein interfaceGraph- Parameters:
node- the node for which to find the indegree- Returns:
- the indegree of the specified node
-
getDegree
Returns the degree of a given node in the graph. -
getNode
Retrieves the node in the graph with the specified name. -
getNodes
getNodes.
-
setNodes
Set the nodes of the graph. -
getNodeNames
getNodeNames.
- Specified by:
getNodeNamesin interfaceGraph- Returns:
- a
Listobject
-
getNumEdges
public int getNumEdges()getNumEdges.
- Specified by:
getNumEdgesin interfaceGraph- Returns:
- a int
-
getNumEdges
Returns the number of edges connected to the specified node.- Specified by:
getNumEdgesin interfaceGraph- Parameters:
node- the node for which to retrieve the number of edges- Returns:
- the number of edges connected to the specified node
-
getNumNodes
public int getNumNodes()getNumNodes.
- Specified by:
getNumNodesin interfaceGraph- Returns:
- a int
-
getOutdegree
Returns the outdegree of the given node.- Specified by:
getOutdegreein interfaceGraph- Parameters:
node- aNodeobject- Returns:
- the outdegree of the node
-
getParents
Retrieves the list of parent nodes for a given node in the graph.- Specified by:
getParentsin interfaceGraph- Parameters:
node- the node for which to retrieve the parent nodes- Returns:
- the list of parent nodes for the given node
-
isAdjacentTo
Determines whether two nodes are adjacent in the graph.- Specified by:
isAdjacentToin interfaceGraph- Parameters:
node1- The first node to check adjacency.node2- The second node to check adjacency.- Returns:
- true if the nodes are adjacent, false otherwise.
-
isChildOf
Checks if the given node1 is a child of node2 in the graph. -
isParentOf
Determines if a given node is a parent of another node in the graph.- Specified by:
isParentOfin interfaceGraph- 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.
-
isDefNoncollider
Checks if three given nodes form a definite non-collider in a graph.- Specified by:
isDefNoncolliderin interfaceGraph- Parameters:
node1- the first nodenode2- the second nodenode3- the third node- Returns:
- true if the three nodes form a definite non-collider, false otherwise
-
isDefCollider
Checks if there is a definite collider between three nodes in the graph.- Specified by:
isDefColliderin interfaceGraph- Parameters:
node1- the first node to checknode2- the second node to checknode3- the third node to check- Returns:
- true if there is a definite collider, false otherwise
-
isExogenous
Checks whether a given node is exogenous.- Specified by:
isExogenousin interfaceGraph- Parameters:
node- ANodeobject representing the node to be checked.- Returns:
- True if the given node is exogenous, false otherwise.
-
getNodesInTo
Retrieves a list of nodes in the given graph that have edges pointing into the specified node and endpoint.- Specified by:
getNodesInToin interfaceGraph- Parameters:
node- the node to check for incoming edgesn- the endpoint to check for incoming edges- Returns:
- a list of nodes with edges pointing into the specified node and endpoint
-
getNodesOutTo
Retrieves a list of nodes that have outgoing edges to a specified node and endpoint.- Specified by:
getNodesOutToin interfaceGraph- 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.
-
removeEdge
Removes a given edge from the graph.- Specified by:
removeEdgein interfaceGraph- Parameters:
edge- the edge to be removed- Returns:
- true if the edge was successfully removed, false otherwise
-
removeEdge
Removes the edge between two nodes in the graph.- Specified by:
removeEdgein interfaceGraph- Parameters:
node1- the first node to remove the edge fromnode2- the second node to remove the edge to- Returns:
- true if the edge was successfully removed, false otherwise
-
removeEdges
Removes an edge between two nodes.- Specified by:
removeEdgesin interfaceGraph- Parameters:
node1- the first nodenode2- the second node- Returns:
- true if the edge was successfully removed, false otherwise
-
removeEdges
Removes the given edges from the graph.- Specified by:
removeEdgesin interfaceGraph- Parameters:
edges- a collection of edges to be removed from the graph- Returns:
- true if all the edges were successfully removed, false otherwise
-
removeNode
Removes the specified node from the graph.- Specified by:
removeNodein interfaceGraph- Parameters:
node- the node to be removed from the graph- Returns:
- true if the node was successfully removed, false otherwise
-
removeNodes
Removes the specified nodes from the graph.- Specified by:
removeNodesin interfaceGraph- Parameters:
nodes- aListof nodes to remove- Returns:
trueif the nodes were successfully removed,falseotherwise
-
setEndpoint
Sets the endpoint of a directed edge between two nodes in a graph.- Specified by:
setEndpointin interfaceGraph- Parameters:
from- the starting node of the edgeto- the ending node of the edgeendPoint- the endpoint of the directed edge- Returns:
trueif the endpoint was successfully set,falseotherwise
-
subgraph
Returns a subgraph of the current graph consisting only of the specified nodes. -
toString
toString.
-
transferNodesAndEdges
Transfers nodes and edges from the given graph to the current graph.- Specified by:
transferNodesAndEdgesin interfaceGraph- 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 failsNullPointerException- if no graph is provided
-
transferAttributes
Transfers attributes from the given graph to the current graph.- Specified by:
transferAttributesin interfaceGraph- Parameters:
graph- aGraphobject representing the graph from which attributes will be transferred- Throws:
IllegalArgumentException- if the graph is null
-
paths
paths.
-
isParameterizable
Checks if the given node is parameterizable.- Specified by:
isParameterizablein interfaceGraph- Parameters:
node- the node to be checked for parameterizability- Returns:
trueif the node is parameterizable,falseotherwise
-
isTimeLagModel
public boolean isTimeLagModel()isTimeLagModel.
- Specified by:
isTimeLagModelin interfaceGraph- Returns:
- a boolean
-
getTimeLagGraph
getTimeLagGraph.
- Specified by:
getTimeLagGraphin interfaceGraph- Returns:
- a
TimeLagGraphobject
-
getSepset
Returns the sepset between two given nodes in the graph. -
getAllAttributes
getAllAttributes.
- Specified by:
getAllAttributesin interfaceGraph- Returns:
- a
Mapobject
-
getAttribute
Retrieves the value associated with the given key in the attribute map.- Specified by:
getAttributein interfaceGraph- Parameters:
key- the key of the attribute to be retrieved- Returns:
- the value associated with the given key
-
removeAttribute
Removes an attribute from the graph.- Specified by:
removeAttributein interfaceGraph- Parameters:
key- the key of the attribute to remove
-
addAttribute
Adds an attribute to the graph.- Specified by:
addAttributein interfaceGraph- Parameters:
key- the key of the attributevalue- the value of the attribute
-
getAmbiguousTriples
Returns a set of ambiguous triples.- Specified by:
getAmbiguousTriplesin interfaceGraph- Returns:
- a set of ambiguous triples
-
setAmbiguousTriples
Sets the ambiguous triples for the object.- Specified by:
setAmbiguousTriplesin interfaceGraph- Parameters:
triples- a set of Triple objects representing ambiguous triples
-
getUnderLines
Retrieves the set of underlined triples.- Specified by:
getUnderLinesin interfaceGraph- Returns:
- The set of underlined triples as a
SetofTripleobjects.
-
getDottedUnderlines
getDottedUnderlines.
- Specified by:
getDottedUnderlinesin interfaceGraph- Returns:
- a
Setobject
-
isAmbiguousTriple
Determines if a triple of nodes is ambiguous.- Specified by:
isAmbiguousTriplein interfaceGraph- 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.
-
isUnderlineTriple
Determines if a triple of nodes is underlined.- Specified by:
isUnderlineTriplein interfaceGraph- Parameters:
x- the first Node in the tripley- the second Node in the triplez- the third Node in the triple- Returns:
- true if the triple is underlined, false otherwise
-
addAmbiguousTriple
Adds an ambiguous triple to the list of ambiguous triples. An ambiguous triple consists of three nodes: x, y, and z.- Specified by:
addAmbiguousTriplein interfaceGraph- Parameters:
x- the first node in the ambiguous tripley- the second node in the ambiguous triplez- the third node in the ambiguous triple
-
addUnderlineTriple
Adds an underline triple to the current object.- Specified by:
addUnderlineTriplein interfaceGraph- Parameters:
x- The firstNodeobject in the triple.y- The secondNodeobject in the triple.z- The thirdNodeobject in the triple.
-
addDottedUnderlineTriple
Adds a dotted underline triple to the graph.- Specified by:
addDottedUnderlineTriplein interfaceGraph- Parameters:
x- The first node of the triple.y- The second node of the triple.z- The third node of the triple.
-
removeAmbiguousTriple
Removes an ambiguous triple from the list of ambiguous triples.- Specified by:
removeAmbiguousTriplein interfaceGraph- Parameters:
x- The first node of the triple.y- The second node of the triple.z- The third node of the triple.
-
removeUnderlineTriple
Removes an underline triple from the list of underline triples.- Specified by:
removeUnderlineTriplein interfaceGraph- Parameters:
x- The firstNodeobject in the underline triple.y- The secondNodeobject in the underline triple.z- The thirdNodeobject in the underline triple.
-
removeDottedUnderlineTriple
Removes a dotted underline triple from the set of triples.- Specified by:
removeDottedUnderlineTriplein interfaceGraph- Parameters:
x- the first node of the triple to be removedy- the second node of the triple to be removedz- the third node of the triple to be removed
-
setUnderLineTriples
Sets the underlined triples.- Specified by:
setUnderLineTriplesin interfaceGraph- Parameters:
triples- a set of triples to be set as underlined
-
setDottedUnderLineTriples
Sets 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 interfaceGraph- Parameters:
triples- a Set of Triples to set as dotted underline triples
-
removeTriplesNotInGraph
public 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 interfaceGraph
-