Class 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
- Version:
- $Id: $Id
- Author:
- josephramsey, Erin Korber additions summer 2004
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionConstructs a new (empty) EdgeListGraph.EdgeListGraph
(EdgeListGraph graph) Constructor for EdgeListGraph.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 TypeMethodDescriptionvoid
addAmbiguousTriple
(Node x, Node y, Node z) addAmbiguousTriple.void
addAttribute
(String key, Object value) addAttribute.boolean
addBidirectedEdge
(Node node1, Node node2) Adds a bidirected edges <-> to the graph.boolean
addDirectedEdge
(Node node1, Node node2) Adds a directed edge --> to the graph.void
addDottedUnderlineTriple
(Node x, Node y, Node z) addDottedUnderlineTriple.boolean
Adds the specified edge to the graph, provided it is not already in the graph.boolean
Adds a node to the graph.boolean
addNondirectedEdge
(Node node1, Node node2) Adds a nondirected edges o-o to the graph.boolean
addPartiallyOrientedEdge
(Node node1, Node node2) Adds a partially oriented edge o-> to the graph.void
Adds a PropertyChangeListener to the graph.void
addUnderlineTriple
(Node x, Node y, Node z) addUnderlineTriple.boolean
addUndirectedEdge
(Node node1, Node node2) Adds an undirected edge --- to the graph.void
changeName
(String name, String newName) changeName.void
clear()
Removes all nodes (and therefore all edges) from the graph.boolean
containsEdge
(Edge edge) Determines whether this graph contains the given edge.boolean
containsNode
(Node node) Determines whether this graph contains the given node.boolean
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.boolean
existsSemidirectedPath
(Node node1, Node node2) Determines whether one node is an ancestor of another.void
fullyConnect
(Endpoint endpoint) Removes all edges from the graph and fully connects it using #-# edges, where # is the given endpoint.getAdjacentNodes
(Node node) getAdjacentNodes.getAllAttributes.Getter for the fieldambiguousTriples
.getAttribute
(String key) getAttribute.getChildren
(Node node) getChildren.int
getDegree.int
getDegree.getDirectedEdge
(Node node1, Node node2) getDirectedEdge.getDottedUnderlines.getEdge.getEdges()
getEdges.getEdges.getEdges.getEndpoint
(Node node1, Node node2) getEndpoint.int
getIndegree
(Node node) getIndegree.getNode.getNodeNames.getNodes()
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.int
getNumEdges.int
getNumEdges
(Node node) getNumEdges.int
getNumNodes.int
getOutdegree
(Node node) getOutdegree.getParents
(Node node) getParents.Retrieves the set of nodes that form the sepset between two given nodes.getSepset
(Node x, Node y, IndependenceTest test) Returns the set of nodes that form the separating set between two given nodes.getSepsetContaining
(Node x, Node y, Set<Node> containing, int maxLength) Retrieves the set of nodes that form the sepset between two given nodes.getTimeLagGraph.getTriplesClassificationTypes.getTriplesLists
(Node node) getTriplesLists.getUnderLines.int
hashCode()
boolean
isAdjacentTo
(Node node1, Node node2) isAdjacentTo.boolean
isAmbiguousTriple
(Node x, Node y, Node z) States whether r-s-r is an underline triple or not.boolean
isAncestorOf
(Node node1, Node node2) Determines whether one node is an ancestor of another.boolean
isChildOf.boolean
isDefCollider
(Node node1, Node node2, Node node3) Added by ekorber, 2004/6/9.boolean
isDefNoncollider
(Node node1, Node node2, Node node3) Added by ekorber, 2004/6/9.boolean
isExogenous
(Node node) isExogenous.boolean
isMSeparatedFrom
(Node x, Node y, Set<Node> z) Determines whether x and y are d-separated given z.boolean
isParameterizable
(Node node) isParameterizable.boolean
isParentOf
(Node node1, Node node2) Determines whether node1 is a parent of node2.boolean
isTimeLagModel.boolean
isUnderlineTriple
(Node x, Node y, Node z) States whether r-s-r is an underline triple or not.paths()
paths.void
removeAmbiguousTriple
(Node x, Node y, Node z) removeAmbiguousTriple.void
removeAttribute
(String key) removeAttribute.void
removeDottedUnderlineTriple
(Node x, Node y, Node z) removeDottedUnderlineTriple.boolean
removeEdge
(Edge edge) Removes the given edge from the graph.boolean
removeEdge
(Node node1, Node node2) Removes an edge between two given nodes.boolean
removeEdges
(Node node1, Node node2) Removes all edges connecting node A to node B.boolean
removeEdges
(Collection<Edge> edges) Iterates through the list and removes any permissible edges found.boolean
removeNode
(Node node) Removes a node from the graph.boolean
removeNodes
(List<Node> newNodes) Iterates through the list and removes any permissible nodes found.void
removeTriplesNotInGraph.void
removeUnderlineTriple
(Node x, Node y, Node z) removeUnderlineTriple.void
reorientAllWith
(Endpoint endpoint) Reorients all edges in the graph with the given endpoint.static EdgeListGraph
Generates a simple exemplar of this class to test serialization.void
setAmbiguousTriples
(Set<Triple> triples) setAmbiguousTriples.void
setDottedUnderLineTriples
(Set<Triple> triples) setDottedUnderLineTriples.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.void
setNodes.void
setUnderLineTriples
(Set<Triple> triples) setUnderLineTriples.Constructs and returns a subgraph consisting of a given subset of the nodes of this graph together with the edges between them.toString()
toString.void
transferAttributes
(Graph graph) transferAttributes.void
transferNodesAndEdges
(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
Constructor for EdgeListGraph.
- Parameters:
graph
- aEdgeListGraph
object- Throws:
IllegalArgumentException
- if any.
-
EdgeListGraph
-
-
Method Details
-
serializableInstance
Generates a simple exemplar of this class to test serialization.- Returns:
- a
EdgeListGraph
object
-
addDirectedEdge
-
addUndirectedEdge
-
addNondirectedEdge
-
addPartiallyOrientedEdge
Adds a partially oriented edge o-> to the graph.Adds a partially oriented edge to the graph from node A to node B.
- Specified by:
addPartiallyOrientedEdge
in interfaceGraph
- Parameters:
node1
- aNode
objectnode2
- aNode
object- Returns:
- a boolean
-
addBidirectedEdge
-
isDefNoncollider
Added by ekorber, 2004/6/9.IllegalArgument exception raised (by isDirectedFromTo(getEndpoint) or by getEdge) if there are multiple edges between any of the node pairs.
- Specified by:
isDefNoncollider
in interfaceGraph
- Parameters:
node1
- aNode
objectnode2
- aNode
objectnode3
- aNode
object- Returns:
- true if node 2 is a definite noncollider between 1 and 3
-
isDefCollider
-
getChildren
-
getDegree
-
getEdge
-
getDirectedEdge
-
getParents
-
isAncestorOf
Determines whether one node is an ancestor of another. Including this here for caching purposes.- Specified by:
isAncestorOf
in interfaceGraph
- Parameters:
node1
- The first node.node2
- The second node.- Returns:
- True if the first node is an ancestor of the second, false if not.
-
existsSemidirectedPath
Determines whether one node is an ancestor of another. Including this here for caching purposes.- Specified by:
existsSemidirectedPath
in interfaceGraph
- Parameters:
node1
- The first node.node2
- The second node.- Returns:
- True if the first node is an ancestor of the second, false if not.
-
getIndegree
getIndegree.
- Specified by:
getIndegree
in interfaceGraph
- Parameters:
node
- aNode
object- Returns:
- the number of arrow endpoints adjacent to a node.
-
getDegree
-
getOutdegree
getOutdegree.
- Specified by:
getOutdegree
in interfaceGraph
- Parameters:
node
- aNode
object- Returns:
- the number of null endpoints adjacent to an edge.
-
isAdjacentTo
-
isChildOf
-
getSepset
Returns the set of nodes that form the separating set between two given nodes. A separating set is a set of nodes that, when conditioned on, renders the given nodes d-separated. -
getSepset
Retrieves the set of nodes that form the sepset between two given nodes. This method needs specifically to be called on the EdgeListGraph class, as it is not implemented in the Graph interface.- Parameters:
x
- The first node.y
- The second node.maxLength
- The maximum length of the paths to consider.- Returns:
- The set of nodes that form the sepset between the two given nodes.
-
getSepsetContaining
Retrieves the set of nodes that form the sepset between two given nodes. This method needs specifically- Parameters:
x
- The first node.y
- The second node.containing
- The set of nodes that must be contained in the sepset.maxLength
- The maximum length of the paths to consider.- Returns:
- The set of nodes that form the sepset between the two given nodes.
-
isMSeparatedFrom
-
isParentOf
-
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.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:
transferNodesAndEdges
in interfaceGraph
- Parameters:
graph
- the graph from which nodes and edges are to be pilfered.- Throws:
IllegalArgumentException
- This exception is thrown if adding some node.
-
transferAttributes
transferAttributes.
- Specified by:
transferAttributes
in interfaceGraph
- Parameters:
graph
- aGraph
object- Throws:
IllegalArgumentException
- if any.
-
paths
-
isExogenous
isExogenous.
Determines whether a node in a graph is exogenous.
- Specified by:
isExogenous
in interfaceGraph
- Parameters:
node
- aNode
object- Returns:
- true iff the given node is exogenous in the graph.
-
getAdjacentNodes
-
removeEdge
Removes an edge between two given nodes.Removes the edge connecting the two given nodes.
- Specified by:
removeEdge
in interfaceGraph
- Parameters:
node1
- The first node.node2
- The second node.- Returns:
- true if the edge between node1 and node2 was successfully removed, false otherwise.
-
getEndpoint
-
setEndpoint
Sets the endpoint type at the 'to' end of the edge from 'from' to 'to' to the given endpoint. Note: NOT CONSTRAINT SAFEIf 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:
setEndpoint
in interfaceGraph
- Parameters:
from
- aNode
objectto
- aNode
objectendPoint
- aEndpoint
object- Returns:
- a boolean
- Throws:
IllegalArgumentException
-
getNodesInTo
Nodes adjacent to the given node with the given proximal endpoint.Nodes adjacent to the given node with the given proximal endpoint.
- Specified by:
getNodesInTo
in interfaceGraph
- Parameters:
node
- aNode
objectendpoint
- aEndpoint
object- Returns:
- a
List
object
-
getNodesOutTo
Nodes adjacent to the given node with the given distal endpoint.( Nodes adjacent to the given node with the given distal endpoint.
- Specified by:
getNodesOutTo
in interfaceGraph
- Parameters:
node
- aNode
objectendpoint
- aEndpoint
object- Returns:
- a
List
object
-
addEdge
-
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.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 whether this graph contains the given edge.Determines if the graph contains a particular edge.
- Specified by:
containsEdge
in interfaceGraph
- Parameters:
edge
- aEdge
object- Returns:
- true iff the graph contain 'edge'.
-
containsNode
Determines whether this graph contains the given node.Determines whether the graph contains a particular node.
- Specified by:
containsNode
in interfaceGraph
- Parameters:
node
- aNode
object- Returns:
- true iff the graph contains 'node'.
-
getEdges
-
hashCode
-
equals
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. -
fullyConnect
Removes all edges from the graph and fully connects it using #-# edges, where # is the given endpoint.Resets the graph so that it is fully connects it using #-# edges, where # is the given endpoint.
- Specified by:
fullyConnect
in interfaceGraph
- Parameters:
endpoint
- aEndpoint
object
-
reorientAllWith
Reorients all edges in the graph with the given endpoint.- Specified by:
reorientAllWith
in interfaceGraph
- Parameters:
endpoint
- aEndpoint
object
-
getNode
getNode.
-
getNumNodes
public int getNumNodes()getNumNodes.
- Specified by:
getNumNodes
in interfaceGraph
- Returns:
- the number of nodes in the graph.
-
getNumEdges
public int getNumEdges()getNumEdges.
- Specified by:
getNumEdges
in interfaceGraph
- Returns:
- the number of edges in the (entire) graph.
-
getNumEdges
getNumEdges.
- Specified by:
getNumEdges
in interfaceGraph
- Parameters:
node
- aNode
object- Returns:
- the number of edges in the graph which are connected to a particular node.
-
getNodes
-
setNodes
-
clear
-
removeEdge
Removes the given edge from the graph.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:
removeEdge
in interfaceGraph
- Parameters:
edge
- aEdge
object- Returns:
- true if the edge was removed, false if not.
-
removeEdges
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.Removes any relevant edge objects found in this collection. G
- Specified by:
removeEdges
in interfaceGraph
- Parameters:
edges
- aCollection
object- Returns:
- true if edges were added, false if not.
-
removeEdges
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.Removes all edges connecting node A to node B.
- Specified by:
removeEdges
in interfaceGraph
- Parameters:
node1
- aNode
objectnode2
- aNode
object- Returns:
- true if edges were removed, false if not.
-
removeNode
Removes a node from the graph.Removes a node from the graph.
- Specified by:
removeNode
in interfaceGraph
- Parameters:
node
- aNode
object- Returns:
- true if the node was removed, false if not.
-
removeNodes
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.Removes any relevant node objects found in this collection.
- Specified by:
removeNodes
in interfaceGraph
- Parameters:
newNodes
- aList
object- Returns:
- true if nodes were added, false if not.
-
toString
-
subgraph
-
getEdges
-
getNodeNames
getNodeNames.
- Specified by:
getNodeNames
in interfaceGraph
- Returns:
- the names of the nodes, in the order of
getNodes
.
-
isParameterizable
isParameterizable.
- Specified by:
isParameterizable
in interfaceGraph
- Parameters:
node
- aNode
object- Returns:
- true if the given node is parameterizable.
-
isTimeLagModel
public boolean isTimeLagModel()isTimeLagModel.
- Specified by:
isTimeLagModel
in interfaceGraph
- Returns:
- true if this is a time lag model, in which case getTimeLagGraph() returns the graph.
-
getTimeLagGraph
getTimeLagGraph.
- Specified by:
getTimeLagGraph
in interfaceGraph
- Returns:
- the underlying time lag model, if there is one; otherwise, returns null.
-
changeName
-
getAllAttributes
-
getAttribute
-
removeAttribute
removeAttribute.
- Specified by:
removeAttribute
in interfaceGraph
- Parameters:
key
- aString
object
-
addAttribute
-
addPropertyChangeListener
Adds a PropertyChangeListener to the graph.- Specified by:
addPropertyChangeListener
in interfaceGraph
- Parameters:
l
- aPropertyChangeListener
object
-
getAmbiguousTriples
Getter for the field
ambiguousTriples
.- Specified by:
getAmbiguousTriples
in interfaceGraph
- Returns:
- a
Set
object
-
setAmbiguousTriples
setAmbiguousTriples.
- Specified by:
setAmbiguousTriples
in interfaceGraph
- Parameters:
triples
- aSet
object
-
getUnderLines
getUnderLines.
- Specified by:
getUnderLines
in interfaceGraph
- Returns:
- a
Set
object
-
getDottedUnderlines
getDottedUnderlines.
- Specified by:
getDottedUnderlines
in interfaceGraph
- Returns:
- a
Set
object
-
isAmbiguousTriple
-
isUnderlineTriple
-
addAmbiguousTriple
-
addUnderlineTriple
-
addDottedUnderlineTriple
-
removeAmbiguousTriple
-
removeUnderlineTriple
-
removeDottedUnderlineTriple
-
setUnderLineTriples
setUnderLineTriples.
- Specified by:
setUnderLineTriples
in interfaceGraph
- Parameters:
triples
- aSet
object
-
setDottedUnderLineTriples
setDottedUnderLineTriples.
- Specified by:
setDottedUnderLineTriples
in interfaceGraph
- Parameters:
triples
- aSet
object
-
removeTriplesNotInGraph
public void removeTriplesNotInGraph()removeTriplesNotInGraph.
- Specified by:
removeTriplesNotInGraph
in interfaceGraph
-
getTriplesClassificationTypes
getTriplesClassificationTypes.
- Specified by:
getTriplesClassificationTypes
in interfaceTripleClassifier
- Returns:
- the names of the triple classifications. Coordinates with
getTriplesList
-
getTriplesLists
getTriplesLists.
- Specified by:
getTriplesLists
in interfaceTripleClassifier
- Parameters:
node
- aNode
object- Returns:
- a
List
object
-