Package edu.cmu.tetrad.graph
Class EdgeListGraph
java.lang.Object
edu.cmu.tetrad.graph.EdgeListGraph
- All Implemented Interfaces:
Graph,TripleClassifier,TetradSerializable,Serializable
Stores a graph a list of lists of edges adjacent to each node in the graph, with an additional list storing all of the edges in the graph. The edges are of the form N1 *-# N2. Multiple edges may be added per node pair to this graph, with the caveat that all edges of the form N1 *-# N2 will be considered equal. For example, if the edge X --> Y is added to the graph, another edge X --> Y may not be added, although an edge Y --> X may be added. Edges from nodes to themselves may also be added.> 0
- Author:
- josephramsey, Erin Korber additions summer 2004
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new (empty) EdgeListGraph.EdgeListGraph(EdgeListGraph graph) EdgeListGraph(Graph graph) Constructs a EdgeListGraph using the nodes and edges of the given graph.EdgeListGraph(List<Node> nodes) Constructs a new graph, with no edges, using the given variable names. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddAmbiguousTriple(Node x, Node y, Node z) voidaddAttribute(String key, Object value) booleanaddBidirectedEdge(Node node1, Node node2) Adds a bidirected edge to the graph from node A to node B.booleanaddDirectedEdge(Node node1, Node node2) Adds a directed edge to the graph from node A to node B.voidaddDottedUnderlineTriple(Node x, Node y, Node z) booleanAdds an edge to the graph.booleanAdds a node to the graph.booleanaddNondirectedEdge(Node node1, Node node2) Adds a nondirected edge to the graph from node A to node B.booleanaddPartiallyOrientedEdge(Node node1, Node node2) Adds a partially oriented edge to the graph from node A to node B.voidAdds a PropertyChangeListener to the graph.voidaddUnderlineTriple(Node x, Node y, Node z) booleanaddUndirectedEdge(Node node1, Node node2) Adds an undirected edge to the graph from node A to node B.voidchangeName(String name, String newName) voidclear()Removes all nodes (and therefore all edges) from the graph.booleancontainsEdge(Edge edge) Determines if the graph contains a particular edge.booleancontainsNode(Node node) Determines whether the graph contains a particular node.booleanDetermines 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.voidfullyConnect(Endpoint endpoint) Resets the graph so that it is fully connects it using #-# edges, where # is the given endpoint.getAdjacentNodes(Node node) getAttribute(String key) getChildren(Node node) intintgetDirectedEdge(Node node1, Node node2) getEdges()getEndpoint(Node node1, Node node2) intgetIndegree(Node node) getNodes()getNodesInTo(Node node, Endpoint endpoint) Nodes adjacent to the given node with the given proximal endpoint.getNodesOutTo(Node node, Endpoint endpoint) Nodes adjacent to the given node with the given distal endpoint.intintgetNumEdges(Node node) intintgetOutdegree(Node node) getParents(Node node) protected PropertyChangeSupportgetPcs()getTriplesLists(Node node) inthashCode()booleanisAdjacentTo(Node node1, Node node2) Determines whether some edge or other exists between two nodes.booleanisAmbiguousTriple(Node x, Node y, Node z) States whether r-s-r is an underline triple or not.booleanDetermines whether one node is a child of another.booleanisDefCollider(Node node1, Node node2, Node node3) Added by ekorber, 2004/6/9.booleanisDefNoncollider(Node node1, Node node2, Node node3) IllegalArgument exception raised (by isDirectedFromTo(getEndpoint) or by getEdge) if there are multiple edges between any of the node pairs.booleanisDSeparatedFrom(Node x, Node y, List<Node> z) booleanbooleanisExogenous(Node node) Determines whether a node in a graph is exogenous.booleanisParameterizable(Node node) booleanisParentOf(Node node1, Node node2) Determines whether one node is a parent of another.booleanbooleanisUnderlineTriple(Node x, Node y, Node z) States whether r-s-r is an underline triple or not.paths()voidremoveAmbiguousTriple(Node x, Node y, Node z) voidremoveAttribute(String key) voidremoveDottedUnderlineTriple(Node x, Node y, Node z) booleanremoveEdge(Edge edge) Removes an edge from the graph.booleanremoveEdge(Node node1, Node node2) Removes the edge connecting the two given nodes.booleanremoveEdges(Node node1, Node node2) Removes all edges connecting node A to node B.booleanremoveEdges(Collection<Edge> edges) Removes any relevant edge objects found in this collection.booleanremoveNode(Node node) Removes a node from the graph.booleanremoveNodes(List<Node> newNodes) Removes any relevant node objects found in this collection.voidvoidremoveUnderlineTriple(Node x, Node y, Node z) voidreorientAllWith(Endpoint endpoint) Reorients all edges in the graph with the given endpoint.static EdgeListGraphGenerates a simple exemplar of this class to test serialization.voidsetAmbiguousTriples(Set<Triple> triples) voidsetDottedUnderLineTriples(Set<Triple> triples) booleansetEndpoint(Node from, Node to, Endpoint endPoint) If there is currently an edge from node1 to node2, sets the endpoint at node2 to the given endpoint; if there is no such edge, adds an edge --# where # is the given endpoint.voidvoidsetUnderLineTriples(Set<Triple> triples) Constructs and returns a subgraph consisting of a given subset of the nodes of this graph together with the edges between them.toString()voidtransferAttributes(Graph graph) voidtransferNodesAndEdges(Graph graph) Transfers nodes and edges from one graph to another.
-
Constructor Details
-
EdgeListGraph
public EdgeListGraph()Constructs a new (empty) EdgeListGraph. -
EdgeListGraph
Constructs a EdgeListGraph using the nodes and edges of the given graph. If this cannot be accomplished successfully, an exception is thrown. Note that any graph constraints from the given graph are forgotten in the new graph.- Parameters:
graph- the graph from which nodes and edges are is to be extracted.- Throws:
IllegalArgumentException- if a duplicate edge is added.
-
EdgeListGraph
- Throws:
IllegalArgumentException
-
EdgeListGraph
Constructs a new graph, with no edges, using the given variable names.
-
-
Method Details
-
serializableInstance
Generates a simple exemplar of this class to test serialization. -
addDirectedEdge
Adds a directed edge to the graph from node A to node B.- Specified by:
addDirectedEdgein interfaceGraph- Parameters:
node1- the "from" node.node2- the "to" node.
-
addUndirectedEdge
Adds an undirected edge to the graph from node A to node B.- Specified by:
addUndirectedEdgein interfaceGraph- Parameters:
node1- the "from" node.node2- the "to" node.
-
addNondirectedEdge
Adds a nondirected edge to the graph from node A to node B.- Specified by:
addNondirectedEdgein interfaceGraph- Parameters:
node1- the "from" node.node2- the "to" node.
-
addPartiallyOrientedEdge
Adds a partially oriented edge to the graph from node A to node B.- Specified by:
addPartiallyOrientedEdgein interfaceGraph- Parameters:
node1- the "from" node.node2- the "to" node.
-
addBidirectedEdge
Adds a bidirected edge to the graph from node A to node B.- Specified by:
addBidirectedEdgein interfaceGraph- Parameters:
node1- the "from" node.node2- the "to" node.
-
isDefNoncollider
IllegalArgument exception raised (by isDirectedFromTo(getEndpoint) or by getEdge) if there are multiple edges between any of the node pairs.- Specified by:
isDefNoncolliderin interfaceGraph- Returns:
- true if node 2 is a definite noncollider between 1 and 3
-
isDefCollider
Description copied from interface:GraphAdded by ekorber, 2004/6/9.- Specified by:
isDefColliderin interfaceGraph- Returns:
- true if node 2 is a definite collider between 1 and 3
-
getChildren
- Specified by:
getChildrenin interfaceGraph- Returns:
- the list of children for a node.
-
getDegree
public int getDegree() -
getEdge
-
getDirectedEdge
- Specified by:
getDirectedEdgein interfaceGraph- Returns:
- the directed edge from node1 to node2, if there is one.
-
getParents
- Specified by:
getParentsin interfaceGraph- Returns:
- the list of parents for a node.
-
getIndegree
- Specified by:
getIndegreein interfaceGraph- Returns:
- the number of edges into the given node.
-
getDegree
-
getOutdegree
- Specified by:
getOutdegreein interfaceGraph- Returns:
- the number of edges out of the given node.
-
isAdjacentTo
Determines whether some edge or other exists between two nodes.- Specified by:
isAdjacentToin interfaceGraph- Returns:
- true iff node1 is adjacent to node2 in the graph.
-
isChildOf
Determines whether one node is a child of another. -
getSepset
-
isDSeparatedFrom
-
isDSeparatedFrom
-
isParentOf
Determines whether one node is a parent of another.- Specified by:
isParentOfin interfaceGraph- Parameters:
node1- the first node.node2- the second node.- Returns:
- true if node1 is a parent of node2, false if not.
- See Also:
-
transferNodesAndEdges
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.- Specified by:
transferNodesAndEdgesin interfaceGraph- Parameters:
graph- the graph from which nodes and edges are to be pilfered.- Throws:
IllegalArgumentException- This exception is thrown if adding some node or edge violates one of the basicConstraints of this graph.
-
transferAttributes
- Specified by:
transferAttributesin interfaceGraph- Throws:
IllegalArgumentException
-
paths
-
isExogenous
Determines whether a node in a graph is exogenous.- Specified by:
isExogenousin interfaceGraph- Returns:
- true iff the given node is exogenous in the graph.
-
getAdjacentNodes
- Specified by:
getAdjacentNodesin interfaceGraph- Returns:
- the list of nodes adjacent to the given node. If there are multiple edges between X and Y, Y will show up twice in the list of adjacencies for X, for optimality; simply create a list an and array from these to eliminate the duplication.
-
removeEdge
Removes the edge connecting the two given nodes.- Specified by:
removeEdgein interfaceGraph
-
getEndpoint
- Specified by:
getEndpointin interfaceGraph- Returns:
- the endpoint along the edge from node to node2 at the node2 end.
-
setEndpoint
If there is currently an edge from node1 to node2, sets the endpoint at node2 to the given endpoint; if there is no such edge, adds an edge --# where # is the given endpoint. Setting an endpoint to null, provided there is exactly one edge connecting the given nodes, removes the edge. (If there is more than one edge, an exception is thrown.)- Specified by:
setEndpointin interfaceGraph- Throws:
IllegalArgumentException- if the edge with the revised endpoint cannot be added to the graph.
-
getNodesInTo
Nodes adjacent to the given node with the given proximal endpoint.- Specified by:
getNodesInToin interfaceGraph
-
getNodesOutTo
Nodes adjacent to the given node with the given distal endpoint.- Specified by:
getNodesOutToin interfaceGraph
-
addEdge
Adds an edge to the graph. -
addNode
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. -
getEdges
-
containsEdge
Determines if the graph contains a particular edge.- Specified by:
containsEdgein interfaceGraph- Returns:
- true iff the graph contain 'edge'.
-
containsNode
Determines whether the graph contains a particular node.- Specified by:
containsNodein interfaceGraph- Returns:
- true iff the graph contains 'node'.
-
getEdges
-
hashCode
public int hashCode() -
equals
Description copied from interface:GraphDetermines 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. -
fullyConnect
Resets the graph so that it is fully connects it using #-# edges, where # is the given endpoint.- Specified by:
fullyConnectin interfaceGraph
-
reorientAllWith
Description copied from interface:GraphReorients all edges in the graph with the given endpoint.- Specified by:
reorientAllWithin interfaceGraph
-
getNode
-
getNumNodes
public int getNumNodes()- Specified by:
getNumNodesin interfaceGraph- Returns:
- the number of nodes in the graph.
-
getNumEdges
public int getNumEdges()- Specified by:
getNumEdgesin interfaceGraph- Returns:
- the number of edges in the (entire) graph.
-
getNumEdges
- Specified by:
getNumEdgesin interfaceGraph- Returns:
- the number of edges connected to a particular node in the graph.
-
getNodes
-
setNodes
-
clear
public void clear()Removes all nodes (and therefore all edges) from the graph. -
removeEdge
Removes an edge from the graph. (Note: It is dangerous to make a recursive call to this method (as it stands) from a method containing certain types of iterators. The problem is that if one uses an iterator that iterates over the edges of node A or node B, and tries in the process to remove those edges using this method, a concurrent modification exception will be thrown.)- Specified by:
removeEdgein interfaceGraph- Parameters:
edge- the edge to remove.- Returns:
- true if the edge was removed, false if not.
-
removeEdges
Removes any relevant edge objects found in this collection. G- Specified by:
removeEdgesin interfaceGraph- Parameters:
edges- the collection of edges to remove.- Returns:
- true if any edges in the collection were removed, false if not.
-
removeEdges
Removes all edges connecting node A to node B.- Specified by:
removeEdgesin interfaceGraph- Parameters:
node1- the first node.,node2- the second node.- Returns:
- true if edges were removed between A and B, false if not.
-
removeNode
Removes a node from the graph.- Specified by:
removeNodein interfaceGraph- Returns:
- true if the node was removed, false if not.
-
removeNodes
Removes any relevant node objects found in this collection.- Specified by:
removeNodesin interfaceGraph- Parameters:
newNodes- the collection of nodes to remove.- Returns:
- true if nodes from the collection were removed, false if not.
-
toString
-
subgraph
Description copied from interface:GraphConstructs and returns a subgraph consisting of a given subset of the nodes of this graph together with the edges between them. -
getEdges
-
getNodeNames
- Specified by:
getNodeNamesin interfaceGraph- Returns:
- the names of the nodes, in the order of
getNodes.
-
getPcs
- Returns:
- this object.
-
isParameterizable
- Specified by:
isParameterizablein interfaceGraph- Returns:
- true if the given node is parameterizable.
-
isTimeLagModel
public boolean isTimeLagModel()- Specified by:
isTimeLagModelin interfaceGraph- Returns:
- true if this is a time lag model, in which case getTimeLagGraph() returns the graph.
-
getTimeLagGraph
- Specified by:
getTimeLagGraphin interfaceGraph- Returns:
- the underlying time lag model, if there is one; otherwise, returns null.
-
changeName
-
getAllAttributes
- Specified by:
getAllAttributesin interfaceGraph
-
getAttribute
- Specified by:
getAttributein interfaceGraph
-
removeAttribute
- Specified by:
removeAttributein interfaceGraph
-
addAttribute
- Specified by:
addAttributein interfaceGraph
-
addPropertyChangeListener
Description copied from interface:GraphAdds a PropertyChangeListener to the graph.- Specified by:
addPropertyChangeListenerin interfaceGraph
-
getAmbiguousTriples
- Specified by:
getAmbiguousTriplesin interfaceGraph
-
setAmbiguousTriples
- Specified by:
setAmbiguousTriplesin interfaceGraph
-
getUnderLines
- Specified by:
getUnderLinesin interfaceGraph
-
getDottedUnderlines
- Specified by:
getDottedUnderlinesin interfaceGraph
-
isAmbiguousTriple
States whether r-s-r is an underline triple or not.- Specified by:
isAmbiguousTriplein interfaceGraph
-
isUnderlineTriple
States whether r-s-r is an underline triple or not.- Specified by:
isUnderlineTriplein interfaceGraph
-
addAmbiguousTriple
- Specified by:
addAmbiguousTriplein interfaceGraph
-
addUnderlineTriple
- Specified by:
addUnderlineTriplein interfaceGraph
-
addDottedUnderlineTriple
- Specified by:
addDottedUnderlineTriplein interfaceGraph
-
removeAmbiguousTriple
- Specified by:
removeAmbiguousTriplein interfaceGraph
-
removeUnderlineTriple
- Specified by:
removeUnderlineTriplein interfaceGraph
-
removeDottedUnderlineTriple
- Specified by:
removeDottedUnderlineTriplein interfaceGraph
-
setUnderLineTriples
- Specified by:
setUnderLineTriplesin interfaceGraph
-
setDottedUnderLineTriples
- Specified by:
setDottedUnderLineTriplesin interfaceGraph
-
removeTriplesNotInGraph
public void removeTriplesNotInGraph()- Specified by:
removeTriplesNotInGraphin interfaceGraph
-
getTriplesClassificationTypes
- Specified by:
getTriplesClassificationTypesin interfaceTripleClassifier- Returns:
- the names of the triple classifications. Coordinates with
getTriplesList
-
getTriplesLists
- Specified by:
getTriplesListsin interfaceTripleClassifier- Returns:
- the list of triples corresponding to
getTripleClassificationNamesfor the given node.
-