|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectprefuse.data.tuple.AbstractTupleSet
prefuse.data.tuple.CompositeTupleSet
prefuse.data.Graph
public class Graph
A Graph models a network of nodes connected by a collection of edges. Both nodes and edges can have any number of associated data fields. Additionally, edges are either directed or undirected, indicating a possible directionality of the connection. Each edge has both a source node and a target node, for a directed edge this indicates the directionality, for an undirected edge this is just an artifact of the order in which the nodes were specified when added to the graph.
Both nodes and edges are represented by backing data Table
instances storing the data attributes. For edges, this table must
also contain a source node field and a target node field. The default
column name for these fields are DEFAULT_SOURCE_KEY
and
DEFAULT_TARGET_KEY
, but these can be configured by the graph
constructor. These columns should be integer valued, and contain
either the row number for a corresponding node in the node table,
or another unique identifier for a node. In this second case, the
unique identifier must be included as a data field in the node
table. This name of this column can be configured using the appropriate
graph constructor. The default column name for this field is
DEFAULT_NODE_KEY
, which by default evaluates to null,
indicating that no special node key should be used, just the direct
node table row numbers. Though the source, target, and node key
values completely specify the graph linkage structure, to make
graph operations more efficient an additional table is maintained
internally by the Graph class, storing node indegree and outdegree
counts and adjacency lists for the inlinks and outlinks for all nodes.
Graph nodes and edges can be accessed by application code by either
using the row numbers of the node and edge tables, which provide unique ids
for each, or using the Node
and
Edge
classes --
Tuple
instances that provide
object-oriented access to both node or edge data values and the
backing graph structure. Node and Edge tuples are maintained by
special TupleManager instances contained within this Graph. By default, they
are not accessible from the backing node or edge tables directly. The reason
for this is that these tables might be used in multiple graphs
simultaneously. For example, a node data table could be used in a number of
different graphs, exploring different possible linkages between those node.
In short, use this Graph instance to request iterators over Node or
Edge tuples, not the backing data tables.
All Graph instances also support an internally generated
spanning tree, provided by the getSpanningTree()
or
getSpanningTree(Node)
methods. This is particularly
useful in visualization contexts that use an underlying tree structure
to compute a graph layout.
Nested Class Summary | |
---|---|
protected class |
Graph.Listener
Listener class for tracking updates from node and edge tables, and their columns that determine the graph linkage structure. |
Field Summary | |
---|---|
static java.lang.String |
DEFAULT_NODE_KEY
Default data field used to uniquely identify a node |
static java.lang.String |
DEFAULT_SOURCE_KEY
Default data field used to denote the source node in an edge table |
static java.lang.String |
DEFAULT_TARGET_KEY
Default data field used to denote the target node in an edge table |
static java.lang.String |
EDGES
Data group name to identify the edges of this graph |
protected static java.lang.String |
INDEGREE
In-degree data field for the links table |
static int |
INEDGES
Indicates incoming edges (inlinks) |
protected static java.lang.String |
INLINKS
In-links adjacency list data field for the links table |
protected static Schema |
LINKS_SCHEMA
Schema used for the internal graph linkage table |
protected boolean |
m_directed
Indicates if this graph is directed or undirected |
protected TupleManager |
m_edgeTuples
TupleManager for managing Edge tuple instances |
protected Table |
m_links
Table containing the adjacency lists for the graph |
protected boolean |
m_longKey
Indicates if the key values are of type long |
protected Index |
m_nidx
Reference to an index over the node key field |
protected java.lang.String |
m_nkey
The node key field (for the Node table) |
protected TupleManager |
m_nodeTuples
TupleManager for managing Node tuple instances |
protected java.lang.String |
m_skey
The source node key field (for the Edge table) |
protected SpanningTree |
m_spanning
The spanning tree over this graph |
protected java.lang.String |
m_tkey
The target node key field (for the Edge table) |
static java.lang.String |
NODES
Data group name to identify the nodes of this graph |
protected static java.lang.String |
OUTDEGREE
Out-degree data field for the links table |
static int |
OUTEDGES
Indicates outgoing edges (outlinks) |
protected static java.lang.String |
OUTLINKS
Out-links adjacency list data field for the links table |
static int |
UNDIRECTED
Indicates all edges, regardless of direction |
Fields inherited from interface prefuse.data.tuple.TupleSet |
---|
EMPTY_ARRAY |
Constructor Summary | |
---|---|
Graph()
Creates a new, empty undirected Graph. |
|
Graph(boolean directed)
Creates a new, empty Graph. |
|
Graph(Table nodes,
boolean directed)
Create a new Graph using the provided table of node data and an empty set of edges. |
|
Graph(Table nodes,
boolean directed,
java.lang.String nodeKey,
java.lang.String sourceKey,
java.lang.String targetKey)
Create a new Graph using the provided table of node data and an empty set of edges. |
|
Graph(Table nodes,
Table edges,
boolean directed)
Create a new Graph, using node table row numbers to uniquely identify nodes in the edge table's source and target fields. |
|
Graph(Table nodes,
Table edges,
boolean directed,
java.lang.String sourceKey,
java.lang.String targetKey)
Create a new Graph, using node table row numbers to uniquely identify nodes in the edge table's source and target fields. |
|
Graph(Table nodes,
Table edges,
boolean directed,
java.lang.String nodeKey,
java.lang.String sourceKey,
java.lang.String targetKey)
Create a new Graph. |
Method Summary | |
---|---|
int |
addEdge(int s,
int t)
Add an edge to the graph. |
Edge |
addEdge(Node s,
Node t)
Add an edge to the graph. |
void |
addGraphModelListener(GraphListener listnr)
Add a listener to be notified of changes to the graph. |
protected void |
addLink(java.lang.String field,
int len,
int n,
int e)
Internal method for adding a link to an adjacency list |
Node |
addNode()
Add a new node to the graph. |
int |
addNodeRow()
Add row to the node table, thereby adding a node to the graph. |
void |
clear()
Clear this graph, removing all nodes and edges. |
protected void |
clearEdges()
Internal method for clearing the edge table, removing all edges. |
void |
clearSpanningTree()
Clear the internally stored spanning tree. |
protected Table |
createLinkTable()
Instantiate and return the link table. |
void |
dispose()
Dispose of this graph. |
protected boolean |
edgeCheck(Edge e,
boolean throwException)
Internal method for checking the validity of an edge. |
IntIterator |
edgeRows()
Get an iterator over all edge ids (edge table row numbers). |
IntIterator |
edgeRows(int node)
Get an iterator over all edge ids for edges incident on the given node. |
IntIterator |
edgeRows(int node,
int direction)
Get an iterator edge ids for edges incident on the given node. |
java.util.Iterator |
edges()
Get an iterator over all edges in the graph. |
java.util.Iterator |
edges(Node node)
Get an iterator over all Edges connected to the given Node in the graph. |
protected void |
fireGraphEvent(Table t,
int first,
int last,
int col,
int type)
Fire a graph change event |
Node |
getAdjacentNode(Edge e,
Node n)
Given an Edge and an incident Node, return the other Node connected to the edge. |
int |
getAdjacentNode(int edge,
int node)
Given an edge id and an incident node id, return the node id for the other node connected to the edge. |
int |
getDegree(int node)
Get the degree of a node, the number of edges for which a node is either the source or the target. |
int |
getDegree(Node n)
Get the degree of a node, the number of edges for which a node is either the source or the target. |
Edge |
getEdge(int e)
Get the Edge tuple instance corresponding to an edge id. |
int |
getEdge(int source,
int target)
Returns an edge from the source node to the target node. |
Edge |
getEdge(Node source,
Node target)
Get an Edge with given source and target Nodes. |
int |
getEdgeCount()
Get the number of edges in this graph. |
TupleSet |
getEdges()
Get the collection of edges as a TupleSet. |
java.lang.String |
getEdgeSourceField()
Get the data field used to denote the source node in an edge table. |
Table |
getEdgeTable()
Get the backing edge table. |
java.lang.String |
getEdgeTargetField()
Get the data field used to denote the target node in an edge table. |
int |
getInDegree(int node)
Get the in-degree of a node, the number of edges for which the node is the target. |
int |
getInDegree(Node n)
Get the in-degree of a node, the number of edges for which the node is the target. |
long |
getKey(int node)
Given a node id (a row number in the node table), get the value of the node key field. |
Node |
getNode(int n)
Get the Node tuple instance corresponding to a node id. |
int |
getNodeCount()
Get the number of nodes in this graph. |
Node |
getNodeFromKey(long key)
Get the Node tuple corresponding to the input node key field value. |
int |
getNodeIndex(long key)
Given a value of the node key field, get the node id (the row number in the node table). |
java.lang.String |
getNodeKeyField()
Get the data field used to uniquely identify a node |
TupleSet |
getNodes()
Get the collection of nodes as a TupleSet. |
Table |
getNodeTable()
Get the backing node table. |
int |
getOutDegree(int node)
Get the out-degree of a node, the number of edges for which the node is the source. |
int |
getOutDegree(Node n)
Get the out-degree of a node, the number of edges for which the node is the source. |
Node |
getSourceNode(Edge e)
Get the source Node for the given Edge instance. |
int |
getSourceNode(int edge)
Get the source node id (node table row number) for the given edge id (edge table row number). |
Tree |
getSpanningTree()
Return the current spanning tree over this graph. |
Tree |
getSpanningTree(Node root)
Returns a spanning tree rooted at the specified node. |
Node |
getTargetNode(Edge e)
Get the target Node for the given Edge instance. |
int |
getTargetNode(int edge)
Get the target node id (node table row number) for the given edge id (edge table row number). |
IntIterator |
inEdgeRows(int node)
Get an iterator over all edges that have the given node as a target. |
java.util.Iterator |
inEdges(Node node)
Get an iterator over all in-linking edges to the given Node. |
protected void |
init(Table nodes,
Table edges,
boolean directed,
java.lang.String nodeKey,
java.lang.String sourceKey,
java.lang.String targetKey)
Initialize this Graph instance. |
protected void |
initLinkTable()
Initialize the link table, which holds adjacency lists for this graph. |
java.util.Iterator |
inNeighbors(Node n)
Get an iterator over all in-linking neighbor nodes for the given Node. |
boolean |
isDirected()
Indicates if the edges of this graph are directed or undirected. |
java.util.Iterator |
neighbors(Node n)
Get an iterator over all neighbor nodes for the given Node in the graph. |
protected boolean |
nodeCheck(Node n,
boolean throwException)
Internal method for checking the validity of a node. |
IntIterator |
nodeRows()
Get an iterator over all node ids (node table row numbers). |
java.util.Iterator |
nodes()
Get an iterator over all nodes in the graph. |
IntIterator |
outEdgeRows(int node)
Get an iterator over all edges that have the given node as a source. |
java.util.Iterator |
outEdges(Node node)
Get an iterator over all out-linking edges from the given Node. |
java.util.Iterator |
outNeighbors(Node n)
Get an iterator over all out-linking neighbor nodes for the given Node. |
protected boolean |
remLink(java.lang.String field,
int len,
int n,
int e)
Internal method for removing a link from an adjacency list |
void |
removeAllGraphModelListeners()
Removes all listeners on this graph |
boolean |
removeEdge(Edge e)
Remove an edge from the graph. |
boolean |
removeEdge(int edge)
Remove an edge from the graph. |
void |
removeGraphModelListener(GraphListener listnr)
Remove a listener from this graph. |
boolean |
removeNode(int node)
Remove a node from the graph, also removing all incident edges. |
boolean |
removeNode(Node n)
Remove a node from the graph, also removing all incident edges. |
boolean |
removeTuple(Tuple t)
If the given tuple is a Node or Edge in this graph, remove it. |
void |
setEdgeTable(Table edges)
Updates this graph to use a different edge structure for the same nodes. |
void |
setTupleManagers(TupleManager ntm,
TupleManager etm)
Set the tuple managers used to manage the Node and Edge tuples of this Graph. |
java.util.Iterator |
tuples()
Get an iterator over all the edges and nodes of this graph. |
java.util.Iterator |
tuples(Predicate filter)
Get a filtered iterator over the edges and nodes of this graph. |
protected void |
updateDegrees(int e,
int incr)
Internal method for updating the linkage of this graph. |
protected void |
updateDegrees(int e,
int s,
int t,
int incr)
Internal method for updating the linkage of this graph. |
protected void |
updateNodeData(int r,
boolean added)
Update the link table to accomodate an inserted or deleted node |
Methods inherited from class prefuse.data.tuple.CompositeTupleSet |
---|
addColumn, addColumn, addColumn, addColumn, addSet, addTuple, containsSet, containsTuple, getSet, getTupleCount, hasSet, isAddColumnSupported, removeAllSets, removeSet, setNames, sets, setTuple |
Methods inherited from class prefuse.data.tuple.AbstractTupleSet |
---|
addColumns, addPropertyChangeListener, addPropertyChangeListener, addTupleSetListener, fireTupleEvent, fireTupleEvent, fireTupleEvent, getClientProperty, putClientProperty, removePropertyChangeListener, removePropertyChangeListener, removeTupleSetListener, tuples |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final int INEDGES
public static final int OUTEDGES
public static final int UNDIRECTED
public static final java.lang.String DEFAULT_NODE_KEY
public static final java.lang.String DEFAULT_SOURCE_KEY
public static final java.lang.String DEFAULT_TARGET_KEY
public static final java.lang.String NODES
public static final java.lang.String EDGES
protected Table m_links
protected TupleManager m_nodeTuples
protected TupleManager m_edgeTuples
protected boolean m_directed
protected SpanningTree m_spanning
protected java.lang.String m_nkey
protected java.lang.String m_skey
protected java.lang.String m_tkey
protected Index m_nidx
protected boolean m_longKey
protected static final java.lang.String INDEGREE
protected static final java.lang.String OUTDEGREE
protected static final java.lang.String INLINKS
protected static final java.lang.String OUTLINKS
protected static final Schema LINKS_SCHEMA
Constructor Detail |
---|
public Graph()
public Graph(boolean directed)
directed
- true for directed edges, false for undirectedpublic Graph(Table nodes, boolean directed)
nodes
- the backing table to use for node data.
Node instances of this graph will get their data from this table.directed
- true for directed edges, false for undirectedpublic Graph(Table nodes, boolean directed, java.lang.String nodeKey, java.lang.String sourceKey, java.lang.String targetKey)
nodes
- the backing table to use for node data.
Node instances of this graph will get their data from this table.directed
- true for directed edges, false for undirectednodeKey
- data field used to uniquely identify a node. If this
field is null, the node table row numbers will be usedsourceKey
- data field used to denote the source node in an edge
tabletargetKey
- data field used to denote the target node in an edge
tablepublic Graph(Table nodes, Table edges, boolean directed)
nodes
- the backing table to use for node data.
Node instances of this graph will get their data from this table.edges
- the backing table to use for edge data.
Edge instances of this graph will get their data from this table.directed
- true for directed edges, false for undirectedpublic Graph(Table nodes, Table edges, boolean directed, java.lang.String sourceKey, java.lang.String targetKey)
nodes
- the backing table to use for node data.
Node instances of this graph will get their data from this table.edges
- the backing table to use for edge data.
Edge instances of this graph will get their data from this table.directed
- true for directed edges, false for undirectedsourceKey
- data field used to denote the source node in an edge
tabletargetKey
- data field used to denote the target node in an edge
tablepublic Graph(Table nodes, Table edges, boolean directed, java.lang.String nodeKey, java.lang.String sourceKey, java.lang.String targetKey)
nodes
- the backing table to use for node data.
Node instances of this graph will get their data from this table.edges
- the backing table to use for edge data.
Edge instances of this graph will get their data from this table.directed
- true for directed edges, false for undirectednodeKey
- data field used to uniquely identify a node. If this
field is null, the node table row numbers will be usedsourceKey
- data field used to denote the source node in an edge
tabletargetKey
- data field used to denote the target node in an edge
tableMethod Detail |
---|
protected void init(Table nodes, Table edges, boolean directed, java.lang.String nodeKey, java.lang.String sourceKey, java.lang.String targetKey)
nodes
- the node tableedges
- the edge tabledirected
- the edge directionalitynodeKey
- data field used to uniquely identify a nodesourceKey
- data field used to denote the source node in an edge
tabletargetKey
- data field used to denote the target node in an edge
tablepublic void setTupleManagers(TupleManager ntm, TupleManager etm)
ntm
- the TupleManager to use for nodesetm
- the TupleManager to use for edgespublic void dispose()
public void setEdgeTable(Table edges)
edges
- the new edge table.protected void initLinkTable()
protected Table createLinkTable()
protected void updateDegrees(int e, int incr)
e
- the edge id for the updated linkincr
- the increment value, 1 for an added link,
-1 for a removed linkprotected void updateDegrees(int e, int s, int t, int incr)
e
- the edge id for the updated links
- the source node id for the updated linkt
- the target node id for the updated linkincr
- the increment value, 1 for an added link,
-1 for a removed linkprotected void addLink(java.lang.String field, int len, int n, int e)
field
- which adjacency list (inlinks or outlinks) to uselen
- the length of the adjacency listn
- the node id of the adjacency list to usee
- the edge to add to the listprotected boolean remLink(java.lang.String field, int len, int n, int e)
field
- which adjacency list (inlinks or outlinks) to uselen
- the length of the adjacency listn
- the node id of the adjacency list to usee
- the edge to remove from the list
protected void updateNodeData(int r, boolean added)
r
- the node id, also the row number into the link tableadded
- indicates if a node was added or removedpublic java.lang.String getNodeKeyField()
public java.lang.String getEdgeSourceField()
public java.lang.String getEdgeTargetField()
public long getKey(int node)
node
- the node id
public int getNodeIndex(long key)
key
- a node key field value
public int addNodeRow()
public Node addNode()
public int addEdge(int s, int t)
s
- the source node idt
- the target node id
public Edge addEdge(Node s, Node t)
s
- the source Nodet
- the target Node
public boolean removeNode(int node)
node
- the node id (node table row number) of the node to remove
public boolean removeNode(Node n)
n
- the Node to remove from the graph
public boolean removeEdge(int edge)
edge
- the edge id (edge table row number) of the edge to remove
public boolean removeEdge(Edge e)
e
- the Edge to remove from the graph
protected void clearEdges()
protected boolean nodeCheck(Node n, boolean throwException)
n
- the Node to check for validitythrowException
- true if this method should throw an Exception
when an invalid node is encountered
public TupleSet getNodes()
CompositeTupleSet.getSet(String)
using
NODES
as the parameter.
public Table getNodeTable()
public int getNodeCount()
public Node getNode(int n)
n
- a node id (node table row number)
public Node getNodeFromKey(long key)
key
- a node key field value
public int getInDegree(int node)
node
- the node id (node table row number)
public int getInDegree(Node n)
n
- the Node instance
public int getOutDegree(int node)
node
- the node id (node table row number)
public int getOutDegree(Node n)
n
- the Node instance
public int getDegree(int node)
node
- the node id (node table row number)
public int getDegree(Node n)
n
- the Node instance
public boolean isDirected()
protected boolean edgeCheck(Edge e, boolean throwException)
e
- the Edge to check for validitythrowException
- true if this method should throw an Exception
when an invalid node is encountered
public TupleSet getEdges()
CompositeTupleSet.getSet(String)
using
EDGES
as the parameter.
public Table getEdgeTable()
public int getEdgeCount()
public Edge getEdge(int e)
e
- an edge id (edge table row number)
public int getEdge(int source, int target)
public Edge getEdge(Node source, Node target)
source
- the source Nodetarget
- the target Node
public int getSourceNode(int edge)
edge
- an edge id (edge table row number)
public Node getSourceNode(Edge e)
e
- an Edge instance
public int getTargetNode(int edge)
edge
- an edge id (edge table row number)
public Node getTargetNode(Edge e)
e
- an Edge instance
public int getAdjacentNode(int edge, int node)
edge
- an edge id (edge table row number)node
- a node id (node table row number). This node id must
be connected to the edge
public Node getAdjacentNode(Edge e, Node n)
e
- an Edge instancen
- a Node instance. This node must
be connected to the edge
public IntIterator nodeRows()
public IntIterator edgeRows()
public IntIterator edgeRows(int node)
node
- a node id (node table row number)
public IntIterator edgeRows(int node, int direction)
node
- a node id (node table row number)direction
- the directionality of the edges to include. One of
INEDGES
(for in-linking edges),
OUTEDGES
(for out-linking edges), or
UNDIRECTED
(for all edges).
public IntIterator inEdgeRows(int node)
node
- a node id (node table row number)
public IntIterator outEdgeRows(int node)
node
- a node id (node table row number)
public java.util.Iterator nodes()
public java.util.Iterator neighbors(Node n)
n
- a Node in the graph
public java.util.Iterator inNeighbors(Node n)
n
- a Node in the graph
public java.util.Iterator outNeighbors(Node n)
n
- a Node in the graph
public java.util.Iterator edges()
public java.util.Iterator edges(Node node)
node
- a Node in the graph
public java.util.Iterator inEdges(Node node)
node
- a Node in the graph
public java.util.Iterator outEdges(Node node)
node
- a Node in the graph
public void clear()
clear
in interface TupleSet
clear
in class CompositeTupleSet
TupleSet.clear()
public boolean removeTuple(Tuple t)
removeTuple
in interface TupleSet
removeTuple
in class CompositeTupleSet
t
- the Tuple to remove
TupleSet.removeTuple(prefuse.data.Tuple)
public java.util.Iterator tuples(Predicate filter)
tuples
in interface TupleSet
tuples
in class CompositeTupleSet
filter
- predicate to apply to tuples in this set, only tuples
for which the predicate evaluates to true are included in the iteration
TupleSet.tuples(prefuse.data.expression.Predicate)
public java.util.Iterator tuples()
tuples
in interface TupleSet
tuples
in class CompositeTupleSet
TupleSet.tuples()
public Tree getSpanningTree()
getSpanningTree(Node)
,
clearSpanningTree()
public Tree getSpanningTree(Node root)
root
- the node at which to root the spanning tree.
getSpanningTree()
,
clearSpanningTree()
public void clearSpanningTree()
getSpanningTree()
,
getSpanningTree(Node)
,
Tree.getSpanningTree(Node)
public void addGraphModelListener(GraphListener listnr)
listnr
- the listener to addpublic void removeGraphModelListener(GraphListener listnr)
listnr
- the listener to removepublic void removeAllGraphModelListeners()
protected void fireGraphEvent(Table t, int first, int last, int col, int type)
t
- the backing table where the change occurred (either a
node table or an edge table)first
- the first modified table rowlast
- the last (inclusive) modified table rowcol
- the number of the column modified, or
EventConstants.ALL_COLUMNS
for operations
affecting all columnstype
- the type of modification, one of
EventConstants.INSERT
,
EventConstants.DELETE
, or
EventConstants.UPDATE
.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |