Package net.sf.tweety.graphs
Interface Graph<T extends Node>
-
- Type Parameters:
T- The type of the node.
- All Superinterfaces:
Iterable<T>
- All Known Implementing Classes:
DefaultGraph
public interface Graph<T extends Node> extends Iterable<T>
Common interface for graphs with nodes of type T- Author:
- Matthias Thimm
-
-
Field Summary
Fields Modifier and Type Field Description static intIGNORE_SELFLOOPSWhen inverting a graph, ignore self loops (don't add and don't remove)static intINVERT_SELFLOOPSWhen inverting a graph, deal with self loops like ordinary edges (add if not present and remove if present)static intREMOVE_SELFLOOPSWhen inverting a graph, simple remove self loops, but don't add new ones.
-
Method Summary
Modifier and Type Method Description booleanadd(Edge<T> edge)Adds the given edge to this graph.booleanadd(T node)Adds the given node to this graph.booleanareAdjacent(T a, T b)Returns "true" iff the two nodes are connected by a directed edge from a to b or an undirected edge.booleancontains(Object obj)Returns "true" when this graph contains the given node or edge.booleanexistsDirectedPath(T node1, T node2)Checks whether there is a (directed) path from node1 to node2.net.sf.tweety.math.matrix.MatrixgetAdjacencyMatrix()Returns the adjacency matrix of this graph (the order of the nodes is the same as returned by "iterator()").Collection<T>getChildren(Node node)Returns the set of children (node connected via an undirected edge or a directed edge where the given node is the parent) of the given node.Graph<T>getComplementGraph(int selfloops)Returns the complement graph of this graph, i.e.Edge<T>getEdge(T a, T b)Returns the corresponding edge (a,b) if a and b are adjacent.Collection<? extends Edge<? extends T>>getEdges()Returns the edges of this graph.Collection<T>getNeighbors(T node)Returns the set of neighbors of the given node.Collection<T>getNodes()Returns the nodes of this graph.intgetNumberOfNodes()Returns the number of nodes in this graph.Collection<T>getParents(Node node)Returns the set of parents (node connected via an undirected edge or a directed edge where the given node is the child) of the given node.Graph<T>getRestriction(Collection<T> nodes)Returns copy of this graph consisting only of the given nodes and all corresponding edges.Collection<Collection<T>>getStronglyConnectedComponents()Returns the strongly connected components of this graph.Collection<Graph<T>>getSubgraphs()Returns the set of sub graphs of this graph.booleanhasSelfLoops()Returns "true" iff the graph has a self loop (an edge from a node to itself).booleanisWeightedGraph()Checks whether this graph only contains weighted edges.Iterator<T>iterator()StringtoString()-
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
-
-
-
Field Detail
-
IGNORE_SELFLOOPS
static final int IGNORE_SELFLOOPS
When inverting a graph, ignore self loops (don't add and don't remove)- See Also:
- Constant Field Values
-
INVERT_SELFLOOPS
static final int INVERT_SELFLOOPS
When inverting a graph, deal with self loops like ordinary edges (add if not present and remove if present)- See Also:
- Constant Field Values
-
REMOVE_SELFLOOPS
static final int REMOVE_SELFLOOPS
When inverting a graph, simple remove self loops, but don't add new ones.- See Also:
- Constant Field Values
-
-
Method Detail
-
add
boolean add(T node)
Adds the given node to this graph.- Parameters:
node- some node.- Returns:
- "true" iff the edge has been added successfully.
-
add
boolean add(Edge<T> edge)
Adds the given edge to this graph. If at least one of the nodes the given edge connects is not in the graph, an illegal argument exception is thrown.- Parameters:
edge- some edge.- Returns:
- "true" iff the edge has been added successfully.
-
getNodes
Collection<T> getNodes()
Returns the nodes of this graph.- Returns:
- the nodes of this graph.
-
getNumberOfNodes
int getNumberOfNodes()
Returns the number of nodes in this graph.- Returns:
- the number of nodes in this graph.
-
areAdjacent
boolean areAdjacent(T a, T b)
Returns "true" iff the two nodes are connected by a directed edge from a to b or an undirected edge.- Parameters:
a- some nodeb- some node- Returns:
- "true" iff the two nodes are connected by a directed edge from a to b or an undirected edge.
-
getEdge
Edge<T> getEdge(T a, T b)
Returns the corresponding edge (a,b) if a and b are adjacent. Otherwise it returns null.- Parameters:
a- some nodeb- some node- Returns:
- the edge (a,b) or null.
-
getEdges
Collection<? extends Edge<? extends T>> getEdges()
Returns the edges of this graph.- Returns:
- the edges of this graph.
-
contains
boolean contains(Object obj)
Returns "true" when this graph contains the given node or edge.- Parameters:
obj- an object- Returns:
- "true" if this graph contains the given node or edge.
-
getChildren
Collection<T> getChildren(Node node)
Returns the set of children (node connected via an undirected edge or a directed edge where the given node is the parent) of the given node.- Parameters:
node- some node (must be in the graph).- Returns:
- the set of children of the given node.
-
getParents
Collection<T> getParents(Node node)
Returns the set of parents (node connected via an undirected edge or a directed edge where the given node is the child) of the given node.- Parameters:
node- some node (must be in the graph).- Returns:
- the set of parents of the given node.
-
existsDirectedPath
boolean existsDirectedPath(T node1, T node2)
Checks whether there is a (directed) path from node1 to node2.- Parameters:
node1- some node.node2- some node.- Returns:
- "true" if there is a directed path from node1 to node2.
-
getNeighbors
Collection<T> getNeighbors(T node)
Returns the set of neighbors of the given node.- Parameters:
node- some node (must be in the graph).- Returns:
- the set of neighbors of the given node.
-
getAdjacencyMatrix
net.sf.tweety.math.matrix.Matrix getAdjacencyMatrix()
Returns the adjacency matrix of this graph (the order of the nodes is the same as returned by "iterator()").- Returns:
- the adjacency matrix of this graph
-
getComplementGraph
Graph<T> getComplementGraph(int selfloops)
Returns the complement graph of this graph, i.e. the graph on the same set of vertices as this graph that connects two vertices v and w with an edge if and only if v and w are not connected in this graph.- Parameters:
selfloops- Indicates how to deal with selfloops:
IGNORE_SELFLOOPS - ignore self loops (don't add and don't remove)
INVERT_SELFLOOPS - deal with self loops like ordinary edges (add if not present and remove if present)
REMOVE_SELFLOOPS - simple remove self loops, but don't add new ones.- Returns:
- the complement graph of this graph.
-
getStronglyConnectedComponents
Collection<Collection<T>> getStronglyConnectedComponents()
Returns the strongly connected components of this graph. A set of nodes is strongly connected, if there is a path from each node to each other. A set of nodes is called strongly connected component if it is strongly connected and maximal with respect to set inclusion.- Returns:
- the strongly connected components of this graph.
-
getSubgraphs
Collection<Graph<T>> getSubgraphs()
Returns the set of sub graphs of this graph.- Returns:
- the set of sub graphs of this graph.
-
getRestriction
Graph<T> getRestriction(Collection<T> nodes)
Returns copy of this graph consisting only of the given nodes and all corresponding edges.- Parameters:
nodes- a set of nodes- Returns:
- a graph.
-
hasSelfLoops
boolean hasSelfLoops()
Returns "true" iff the graph has a self loop (an edge from a node to itself).- Returns:
- "true" iff the graph has a self loop (an edge from a node to itself).
-
isWeightedGraph
boolean isWeightedGraph()
Checks whether this graph only contains weighted edges.- Returns:
- "true" if all edges are weighted in this graph.
-
-