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 TypeMethodDescriptionvoidaddAmbiguousTriple(Node x, Node y, Node z) addAmbiguousTriple.voidaddAttribute(String key, Object value) addAttribute.booleanaddBidirectedEdge(Node node1, Node node2) Adds a bidirected edges <-> to the graph.booleanaddDirectedEdge(Node node1, Node node2) Adds a directed edge --> to the graph.voidaddDottedUnderlineTriple(Node x, Node y, Node z) addDottedUnderlineTriple.booleanAdds the specified edge to the graph, provided it is not already in the graph.booleanAdds a node to the graph.booleanaddNondirectedEdge(Node node1, Node node2) Adds a nondirected edges o-o to the graph.booleanaddPartiallyOrientedEdge(Node node1, Node node2) Adds a partially oriented edge o-> to the graph.voidAdds a PropertyChangeListener to the graph.voidaddUnderlineTriple(Node x, Node y, Node z) addUnderlineTriple.booleanaddUndirectedEdge(Node node1, Node node2) Adds an undirected edge --- to the graph.voidchangeName(String name, String newName) changeName.voidclear()Removes all nodes (and therefore all edges) from the graph.booleancontainsEdge(Edge edge) Determines whether this graph contains the given edge.booleancontainsNode(Node node) Determines whether this graph contains the given 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.booleanexistsSemidirectedPath(Node node1, Node node2) Determines whether one node is an ancestor of another.voidfullyConnect(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.intgetDegree.intgetDegree.getDirectedEdge(Node node1, Node node2) getDirectedEdge.getDottedUnderlines.getEdge.getEdges()getEdges.getEdges.getEdges.getEndpoint(Node node1, Node node2) getEndpoint.intgetIndegree(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.intgetNumEdges.intgetNumEdges(Node node) getNumEdges.intgetNumNodes.intgetOutdegree(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.inthashCode()booleanisAdjacentTo(Node node1, Node node2) isAdjacentTo.booleanisAmbiguousTriple(Node x, Node y, Node z) States whether r-s-r is an underline triple or not.booleanisAncestorOf(Node node1, Node node2) Determines whether one node is an ancestor of another.booleanisChildOf.booleanisDefCollider(Node node1, Node node2, Node node3) Added by ekorber, 2004/6/9.booleanisDefNoncollider(Node node1, Node node2, Node node3) Added by ekorber, 2004/6/9.booleanisExogenous(Node node) isExogenous.booleanisMSeparatedFrom(Node x, Node y, Set<Node> z) Determines whether x and y are d-separated given z.booleanisParameterizable(Node node) isParameterizable.booleanisParentOf(Node node1, Node node2) Determines whether node1 is a parent of node2.booleanisTimeLagModel.booleanisUnderlineTriple(Node x, Node y, Node z) States whether r-s-r is an underline triple or not.paths()paths.voidremoveAmbiguousTriple(Node x, Node y, Node z) removeAmbiguousTriple.voidremoveAttribute(String key) removeAttribute.voidremoveDottedUnderlineTriple(Node x, Node y, Node z) removeDottedUnderlineTriple.booleanremoveEdge(Edge edge) Removes the given edge from the graph.booleanremoveEdge(Node node1, Node node2) Removes an edge between two given nodes.booleanremoveEdges(Node node1, Node node2) Removes all edges connecting node A to node B.booleanremoveEdges(Collection<Edge> edges) Iterates through the list and removes any permissible edges found.booleanremoveNode(Node node) Removes a node from the graph.booleanremoveNodes(List<Node> newNodes) Iterates through the list and removes any permissible nodes found.voidremoveTriplesNotInGraph.voidremoveUnderlineTriple(Node x, Node y, Node z) removeUnderlineTriple.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) setAmbiguousTriples.voidsetDottedUnderLineTriples(Set<Triple> triples) setDottedUnderLineTriples.booleansetEndpoint(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.voidsetNodes.voidsetUnderLineTriples(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.voidtransferAttributes(Graph graph) transferAttributes.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
Constructor for EdgeListGraph.
- Parameters:
graph- aEdgeListGraphobject- Throws:
IllegalArgumentException- if any.
-
EdgeListGraph
-
-
Method Details
-
serializableInstance
Generates a simple exemplar of this class to test serialization.- Returns:
- a
EdgeListGraphobject
-
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:
addPartiallyOrientedEdgein interfaceGraph- Parameters:
node1- aNodeobjectnode2- aNodeobject- 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:
isDefNoncolliderin interfaceGraph- Parameters:
node1- aNodeobjectnode2- aNodeobjectnode3- aNodeobject- 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:
isAncestorOfin 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:
existsSemidirectedPathin 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:
getIndegreein interfaceGraph- Parameters:
node- aNodeobject- Returns:
- the number of arrow endpoints adjacent to a node.
-
getDegree
-
getOutdegree
getOutdegree.
- Specified by:
getOutdegreein interfaceGraph- Parameters:
node- aNodeobject- 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:
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.
-
transferAttributes
transferAttributes.
- Specified by:
transferAttributesin interfaceGraph- Parameters:
graph- aGraphobject- Throws:
IllegalArgumentException- if any.
-
paths
-
isExogenous
isExogenous.
Determines whether a node in a graph is exogenous.
- Specified by:
isExogenousin interfaceGraph- Parameters:
node- aNodeobject- 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:
removeEdgein 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:
setEndpointin interfaceGraph- Parameters:
from- aNodeobjectto- aNodeobjectendPoint- aEndpointobject- 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:
getNodesInToin interfaceGraph- Parameters:
node- aNodeobjectendpoint- aEndpointobject- Returns:
- a
Listobject
-
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:
getNodesOutToin interfaceGraph- Parameters:
node- aNodeobjectendpoint- aEndpointobject- Returns:
- a
Listobject
-
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:
containsEdgein interfaceGraph- Parameters:
edge- aEdgeobject- 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:
containsNodein interfaceGraph- Parameters:
node- aNodeobject- 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:
fullyConnectin interfaceGraph- Parameters:
endpoint- aEndpointobject
-
reorientAllWith
Reorients all edges in the graph with the given endpoint.- Specified by:
reorientAllWithin interfaceGraph- Parameters:
endpoint- aEndpointobject
-
getNode
getNode.
-
getNumNodes
public int getNumNodes()getNumNodes.
- Specified by:
getNumNodesin interfaceGraph- Returns:
- the number of nodes in the graph.
-
getNumEdges
public int getNumEdges()getNumEdges.
- Specified by:
getNumEdgesin interfaceGraph- Returns:
- the number of edges in the (entire) graph.
-
getNumEdges
getNumEdges.
- Specified by:
getNumEdgesin interfaceGraph- Parameters:
node- aNodeobject- 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:
removeEdgein interfaceGraph- Parameters:
edge- aEdgeobject- 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:
removeEdgesin interfaceGraph- Parameters:
edges- aCollectionobject- 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:
removeEdgesin interfaceGraph- Parameters:
node1- aNodeobjectnode2- aNodeobject- Returns:
- true if edges were removed, false if not.
-
removeNode
Removes a node from the graph.Removes a node from the graph.
- Specified by:
removeNodein interfaceGraph- Parameters:
node- aNodeobject- 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:
removeNodesin interfaceGraph- Parameters:
newNodes- aListobject- Returns:
- true if nodes were added, false if not.
-
toString
-
subgraph
-
getEdges
-
getNodeNames
getNodeNames.
- Specified by:
getNodeNamesin interfaceGraph- Returns:
- the names of the nodes, in the order of
getNodes.
-
isParameterizable
isParameterizable.
- Specified by:
isParameterizablein interfaceGraph- Parameters:
node- aNodeobject- Returns:
- true if the given node is parameterizable.
-
isTimeLagModel
public boolean isTimeLagModel()isTimeLagModel.
- Specified by:
isTimeLagModelin interfaceGraph- Returns:
- true if this is a time lag model, in which case getTimeLagGraph() returns the graph.
-
getTimeLagGraph
getTimeLagGraph.
- Specified by:
getTimeLagGraphin interfaceGraph- Returns:
- the underlying time lag model, if there is one; otherwise, returns null.
-
changeName
-
getAllAttributes
-
getAttribute
-
removeAttribute
removeAttribute.
- Specified by:
removeAttributein interfaceGraph- Parameters:
key- aStringobject
-
addAttribute
-
addPropertyChangeListener
Adds a PropertyChangeListener to the graph.- Specified by:
addPropertyChangeListenerin interfaceGraph- Parameters:
l- aPropertyChangeListenerobject
-
getAmbiguousTriples
Getter for the field
ambiguousTriples.- Specified by:
getAmbiguousTriplesin interfaceGraph- Returns:
- a
Setobject
-
setAmbiguousTriples
setAmbiguousTriples.
- Specified by:
setAmbiguousTriplesin interfaceGraph- Parameters:
triples- aSetobject
-
getUnderLines
getUnderLines.
- Specified by:
getUnderLinesin interfaceGraph- Returns:
- a
Setobject
-
getDottedUnderlines
getDottedUnderlines.
- Specified by:
getDottedUnderlinesin interfaceGraph- Returns:
- a
Setobject
-
isAmbiguousTriple
-
isUnderlineTriple
-
addAmbiguousTriple
-
addUnderlineTriple
-
addDottedUnderlineTriple
-
removeAmbiguousTriple
-
removeUnderlineTriple
-
removeDottedUnderlineTriple
-
setUnderLineTriples
setUnderLineTriples.
- Specified by:
setUnderLineTriplesin interfaceGraph- Parameters:
triples- aSetobject
-
setDottedUnderLineTriples
setDottedUnderLineTriples.
- Specified by:
setDottedUnderLineTriplesin interfaceGraph- Parameters:
triples- aSetobject
-
removeTriplesNotInGraph
public void removeTriplesNotInGraph()removeTriplesNotInGraph.
- Specified by:
removeTriplesNotInGraphin interfaceGraph
-
getTriplesClassificationTypes
getTriplesClassificationTypes.
- Specified by:
getTriplesClassificationTypesin interfaceTripleClassifier- Returns:
- the names of the triple classifications. Coordinates with
getTriplesList
-
getTriplesLists
getTriplesLists.
- Specified by:
getTriplesListsin interfaceTripleClassifier- Parameters:
node- aNodeobject- Returns:
- a
Listobject
-