Interface GraphModel
-
public interface GraphModel
Graph API's entry point.GraphModel
is the entry point for this API and provide methods to create, access and modify graphs. It supports the most common graph paradigms and a complete support for graphs over time as well.- Directed: Edges can have a direction. Graphs can be directed, undirected or mixed.
- Weighted: Edges can have a weight.
- Self-loops: Nodes can have self-loops.
- Labelled edges: Edges can have a label.
- Properties: Each element in the graph can have properties associated to it.
New instances can be obtained via the embedded factory:
GraphModel model = GraphModel.Factory.newInstance();
This API revolves around a set of simple concepts. AGraphModel
encapsulate all elements and metadata associated with a graph structure. In other words its a single graph but it also contains configuration, indices, views and other less important services such as observers.Then,
GraphModel
gives access to theGraph
interface, which focuses only on the graph structure and provide methods to add, remove, get and iterate nodes and edges.The
Graph
contains nodes and edges, which both implement theElement
interface. ThisElement
interface gives access to methods that manipulate the attributes associated to nodes and edges.Any number of attributes can be associated to elements but are managed through the
Table
andColumn
interfaces. AGraphModel
gives access by default to a node and edge table. ATable
is simply a list of columns, which each has a unique identifier and a type (e.g. integer). Attribute values can only be associated with elements for existing columns.Attributes are automatically indexed and information such as the number of elements with a particular value can be obtained from the
Index
interface.Finally, this API supports the concept of graph views. A view is a mask on the graph structure and represents a subgraph. The user controls the set of nodes and edges in the view by obtaining a
Subgraph
for a specificGraphView
. Views can directly be created and destroyed from this model.Elements should be created through the
factory()
method.For performance reasons, edge labels are internally represented as integers and the mapping between arbitrary labels is managed through the
addEdgeType(java.lang.Object)
andgetEdgeType(java.lang.Object)
methods. By default, edges have anull
label, which is internally represented as zero.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
GraphModel.DefaultColumns
Default columns utility.static class
GraphModel.Factory
Utility to create new graph model instances.static class
GraphModel.Serialization
Serialization utility to read/write graph models from/to input/output.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description int
addEdgeType(Object label)
Adds a new edge type and returns the integer identifier.GraphBridge
bridge()
Returns the graph bridge.GraphView
copyView(GraphView view)
Creates a new graph view based on an existing view.GraphView
copyView(GraphView view, boolean node, boolean edge)
Creates a new graph based on an existing view.GraphObserver
createGraphObserver(Graph graph, boolean withGraphDiff)
Creates and returns a new graph observer.GraphView
createView()
Creates a new graph view.GraphView
createView(boolean node, boolean edge)
Creates a new graph view.GraphModel.DefaultColumns
defaultColumns()
Returns the default columns.void
destroyView(GraphView view)
Destroys the given view.GraphFactory
factory()
Returns the graph factory.Configuration
getConfiguration()
Returns the current configuration.DirectedGraph
getDirectedGraph()
Gets the full graph with the directed interface.DirectedSubgraph
getDirectedGraph(GraphView view)
Gets the directed graph for the given graph view.DirectedGraph
getDirectedGraphVisible()
Gets the visible graph with the directed interface.Index<Edge>
getEdgeIndex()
Gets the edge index.Index<Edge>
getEdgeIndex(GraphView view)
Gets the edge index for the given graph view.Table
getEdgeTable()
Returns the edge table.TimeIndex<Edge>
getEdgeTimeIndex()
Gets the edge time index.TimeIndex<Edge>
getEdgeTimeIndex(GraphView view)
Gets the edge time index for the given view.int
getEdgeType(Object label)
Gets the edge type for the given label.int
getEdgeTypeCount()
Returns the number of different edge types.Object
getEdgeTypeLabel(int id)
Gets the edge label associated with the given type.Object[]
getEdgeTypeLabels()
Returns the edge type labels.Object[]
getEdgeTypeLabels(boolean includeEmpty)
Returns the edge type labels.int[]
getEdgeTypes()
Returns the edge types.Index<Element>
getElementIndex(Table table)
Gets the node or edge index depending on the column provided.Index<Element>
getElementIndex(Table table, GraphView view)
Gets the node or edge index for the given graph view.Graph
getGraph()
Gets the full graph.Subgraph
getGraph(GraphView view)
Gets the graph for the given graph view.Graph
getGraphVisible()
Get the visible graph.int
getMaxEdgeStoreId()
Returns the maximum store id number edges have in this model.int
getMaxNodeStoreId()
Returns the maximum store id number nodes have in this model.Index<Node>
getNodeIndex()
Gets the node index.Index<Node>
getNodeIndex(GraphView view)
Gets the node index for the given graph view.Table
getNodeTable()
Returns the node table.TimeIndex<Node>
getNodeTimeIndex()
Gets the node time index.TimeIndex<Node>
getNodeTimeIndex(GraphView view)
Gets the node time index for the given view.SpatialIndex
getSpatialIndex()
Returns the spatial index.Interval
getTimeBounds()
Gets the time bounds.Interval
getTimeBounds(GraphView view)
Gets the time bounds for the given graph view.Interval
getTimeBoundsVisible()
Gets the time bounds for the visible graph.TimeFormat
getTimeFormat()
Returns the time format used to display time.org.joda.time.DateTimeZone
getTimeZone()
Returns the time zone used to display time.UndirectedGraph
getUndirectedGraph()
Gets the full graph with the undirected interface.UndirectedSubgraph
getUndirectedGraph(GraphView view)
Gets the undirected graph for the given graph view.UndirectedGraph
getUndirectedGraphVisible()
Gets the visible graph with the undirected interface.GraphView
getVisibleView()
Gets the visible view.boolean
isDirected()
Returns true if the graph is directed.boolean
isDynamic()
Returns true if the graph is dynamic.boolean
isMixed()
Returns true if the graph is mixed (both directed and undirected edges).boolean
isMultiGraph()
Returns true if the graph is multi-graph (multiple types of edges).boolean
isUndirected()
Returns true if the graph is undirected.void
setConfiguration(Configuration configuration)
Sets a new configuration for this graph model.void
setTimeFormat(TimeFormat timeFormat)
Sets the time format used to display time.void
setTimeInterval(GraphView view, Interval interval)
Sets the given time interval to the view.void
setTimeZone(org.joda.time.DateTimeZone timeZone)
Sets the time zone used to display time.void
setVisibleView(GraphView view)
Sets the visible view.
-
-
-
Method Detail
-
factory
GraphFactory factory()
Returns the graph factory.- Returns:
- graph factory
-
bridge
GraphBridge bridge()
Returns the graph bridge.- Returns:
- graph bridge
-
getGraph
Graph getGraph()
Gets the full graph.- Returns:
- graph
-
getGraphVisible
Graph getGraphVisible()
Get the visible graph.The visible graph may be the full graph (default) or a graph view.
- Returns:
- visible graph
-
getGraph
Subgraph getGraph(GraphView view)
Gets the graph for the given graph view.- Parameters:
view
- graph view- Returns:
- graph for this view
-
getDirectedGraph
DirectedGraph getDirectedGraph()
Gets the full graph with the directed interface.- Returns:
- directed graph
-
getDirectedGraphVisible
DirectedGraph getDirectedGraphVisible()
Gets the visible graph with the directed interface.- Returns:
- visible graph
-
getUndirectedGraph
UndirectedGraph getUndirectedGraph()
Gets the full graph with the undirected interface.- Returns:
- undirected graph
-
getUndirectedGraphVisible
UndirectedGraph getUndirectedGraphVisible()
Gets the visible graph with the undirected interface.- Returns:
- visible graph
-
getDirectedGraph
DirectedSubgraph getDirectedGraph(GraphView view)
Gets the directed graph for the given graph view.- Parameters:
view
- graph view- Returns:
- directed graph for this view
-
getUndirectedGraph
UndirectedSubgraph getUndirectedGraph(GraphView view)
Gets the undirected graph for the given graph view.- Parameters:
view
- graph view- Returns:
- undirected graph for this view
-
getVisibleView
GraphView getVisibleView()
Gets the visible view.- Returns:
- visible view
-
setVisibleView
void setVisibleView(GraphView view)
Sets the visible view.If view is null, it restores the main view.
- Parameters:
view
- view
-
defaultColumns
GraphModel.DefaultColumns defaultColumns()
Returns the default columns.Default columns are always available for each element.
- Returns:
- default columns
-
addEdgeType
int addEdgeType(Object label)
Adds a new edge type and returns the integer identifier.If the type already exists, it returns the existing identifier.
- Parameters:
label
- edge type label- Returns:
- newly created edge type identifier.
-
getEdgeType
int getEdgeType(Object label)
Gets the edge type for the given label.- Parameters:
label
- edge label- Returns:
- edge type identifier, or -1 if not found
-
getEdgeTypeLabel
Object getEdgeTypeLabel(int id)
Gets the edge label associated with the given type.- Parameters:
id
- edge type- Returns:
- edge label
-
getEdgeTypeCount
int getEdgeTypeCount()
Returns the number of different edge types.- Returns:
- edge type count
-
getEdgeTypes
int[] getEdgeTypes()
Returns the edge types.- Returns:
- edge types
-
getEdgeTypeLabels
Object[] getEdgeTypeLabels()
Returns the edge type labels.- Returns:
- edge type labels
-
getEdgeTypeLabels
Object[] getEdgeTypeLabels(boolean includeEmpty)
Returns the edge type labels.- Parameters:
includeEmpty
- true to include labels without edges- Returns:
- edge type labels
-
isDirected
boolean isDirected()
Returns true if the graph is directed.- Returns:
- true if directed, false otherwise
-
isUndirected
boolean isUndirected()
Returns true if the graph is undirected.- Returns:
- true if undirected, false otherwise
-
isMixed
boolean isMixed()
Returns true if the graph is mixed (both directed and undirected edges).- Returns:
- true if mixed, false otherwise
-
isDynamic
boolean isDynamic()
Returns true if the graph is dynamic.- Returns:
- true if dynamic, false otherwise
-
isMultiGraph
boolean isMultiGraph()
Returns true if the graph is multi-graph (multiple types of edges).- Returns:
- true if multi-graph, false otherwise
-
createView
GraphView createView()
Creates a new graph view.- Returns:
- newly created graph view
-
createView
GraphView createView(boolean node, boolean edge)
Creates a new graph view.The node and edge parameters allows to restrict the view filtering to only nodes or only edges. By default, the view applies to both nodes and edges.
- Parameters:
node
- true to enable node view, false otherwiseedge
- true to enable edge view, false otherwise- Returns:
- newly created graph view
-
copyView
GraphView copyView(GraphView view)
Creates a new graph view based on an existing view.- Parameters:
view
- view to copy- Returns:
- newly created graph view
-
copyView
GraphView copyView(GraphView view, boolean node, boolean edge)
Creates a new graph based on an existing view.The node and edge parameters allows to restrict the view filtering to only nodes or only edges. By default, the view applies to both nodes and edges.
- Parameters:
view
- view to copynode
- true to enable node view, false otherwiseedge
- true to enable edge view, false otherwise- Returns:
- newly created graph view
-
destroyView
void destroyView(GraphView view)
Destroys the given view.- Parameters:
view
- view to destroy
-
setTimeInterval
void setTimeInterval(GraphView view, Interval interval)
Sets the given time interval to the view.Each view can be configured with a time interval to filter a graph over time.
- Parameters:
view
- the view to configureinterval
- the time interval
-
getNodeTable
Table getNodeTable()
Returns the node table. Contains all the columns associated to node elements.A
GraphModel
always has node and edge tables by default.- Returns:
- node table, contains node columns
-
getEdgeTable
Table getEdgeTable()
Returns the edge table. Contains all the columns associated to edge elements.A
GraphModel
always has node and edge tables by default.- Returns:
- edge table, contains edge columns
-
getNodeIndex
Index<Node> getNodeIndex(GraphView view)
Gets the node index for the given graph view.- Parameters:
view
- the view to get the index from- Returns:
- node index
-
getEdgeIndex
Index<Edge> getEdgeIndex(GraphView view)
Gets the edge index for the given graph view.- Parameters:
view
- the view to get the index from- Returns:
- edge index
-
getElementIndex
Index<Element> getElementIndex(Table table)
Gets the node or edge index depending on the column provided.- Parameters:
table
- the table to get the index for- Returns:
- element index, either node or edge
-
getElementIndex
Index<Element> getElementIndex(Table table, GraphView view)
Gets the node or edge index for the given graph view.- Parameters:
table
- the table to get the index forview
- the view to get the index from- Returns:
- edge index
-
getNodeTimeIndex
TimeIndex<Node> getNodeTimeIndex()
Gets the node time index.- Returns:
- node time index
-
getNodeTimeIndex
TimeIndex<Node> getNodeTimeIndex(GraphView view)
Gets the node time index for the given view.- Parameters:
view
- the view to get the index from- Returns:
- node time index
-
getEdgeTimeIndex
TimeIndex<Edge> getEdgeTimeIndex()
Gets the edge time index.- Returns:
- edge timestamp index
-
getEdgeTimeIndex
TimeIndex<Edge> getEdgeTimeIndex(GraphView view)
Gets the edge time index for the given view.- Parameters:
view
- view to get the index from- Returns:
- edge timestamp index
-
getTimeBounds
Interval getTimeBounds()
Gets the time bounds.The time bounds is an interval made of the minimum and maximum time observed in the entire graph.
- Returns:
- time bounds
-
getTimeBoundsVisible
Interval getTimeBoundsVisible()
Gets the time bounds for the visible graph.The time bounds is an interval made of the minimum and maximum time observed in the entire graph.
- Returns:
- time bounds
-
getTimeBounds
Interval getTimeBounds(GraphView view)
Gets the time bounds for the given graph view.The time bounds is an interval made of the minimum and maximum time observed in the entire graph.
- Parameters:
view
- the graph view- Returns:
- time bounds
-
createGraphObserver
GraphObserver createGraphObserver(Graph graph, boolean withGraphDiff)
Creates and returns a new graph observer.- Parameters:
graph
- the graph to observewithGraphDiff
- true to include graph difference feature, false otherwise- Returns:
- newly created graph observer
-
getSpatialIndex
SpatialIndex getSpatialIndex()
Returns the spatial index.- Returns:
- spatial index
-
getTimeFormat
TimeFormat getTimeFormat()
Returns the time format used to display time.- Returns:
- time format
-
setTimeFormat
void setTimeFormat(TimeFormat timeFormat)
Sets the time format used to display time.- Parameters:
timeFormat
- time format
-
getTimeZone
org.joda.time.DateTimeZone getTimeZone()
Returns the time zone used to display time.- Returns:
- time zone
-
setTimeZone
void setTimeZone(org.joda.time.DateTimeZone timeZone)
Sets the time zone used to display time.- Parameters:
timeZone
- time zone
-
getConfiguration
Configuration getConfiguration()
Returns the current configuration.- Returns:
- configuration
-
setConfiguration
void setConfiguration(Configuration configuration)
Sets a new configuration for this graph model.Note that this method only works if the graph model is empty.
- Parameters:
configuration
- new configuration- Throws:
IllegalStateException
- if the graph model isn't empty
-
getMaxNodeStoreId
int getMaxNodeStoreId()
Returns the maximum store id number nodes have in this model.Each node has a unique store identifier which can be retrieved from
Element.getStoreId()
. This maximum number can help design algorithms thar rely on storing nodes in a array. Note that not all consecutive ids may be assigned.- Returns:
- maximum node store id
-
getMaxEdgeStoreId
int getMaxEdgeStoreId()
Returns the maximum store id number edges have in this model.Each edge has a unique store identifier which can be retrieved from
Element.getStoreId()
. This maximum number can help design algorithms thar rely on storing edges in a array. Note that not all consecutive ids may be assigned.- Returns:
- maximum edge store id
-
-