public interface IntGraph
| Modifier and Type | Method and Description |
|---|---|
boolean |
abortableBreadthFirstSearch(int startingNode,
boolean up,
IntPredicate cons)
Do a breadth-first search which takes a predicate that will abort the
search the first time the predicate returns false.
|
boolean |
abortableDepthFirstSearch(int startingNode,
boolean up,
IntPredicate cons)
Do a depth-first search which takes a predicate that will abort the
search the first time the predicate returns false.
|
PairSet |
allEdges()
Get all edges in the graph.
|
Bits |
bottomLevelNodes()
Get the set of nodes which have no outbound edges.
|
void |
breadthFirstSearch(int startingNode,
boolean up,
IntConsumer cons)
Do a breadth-first search from the starting node, visiting all nodes in
its closure or reverse-closure depending on the value of
up,
visiting each node in some order at least once. |
static IntGraphBuilder |
builder() |
static IntGraphBuilder |
builder(int expectedSize) |
int[] |
byClosureSize()
Return an array of all nodes in the graph, sorted by the size of their
closure (the number of distinct descendant nodes they have).
|
int[] |
byReverseClosureSize()
Return an array of all nodes in the graph, sorted by the size of their
reverse closure (the number of distinct ancestor nodes they have).
|
Bits |
children(int node)
Get the set of nodes which have inbound edges from the passed node.
|
Bits |
closureDisjunction(Bits nodes)
Get the set of those nodes which exist in the closure of only one of the
passed list of nodes.
|
Bits |
closureDisjunction(int... nodes)
Get the set of those nodes which exist in the closure of only one of the
passed list of nodes.
|
Bits |
closureDisjunction(int a,
int b)
Get the disjunction of the closure of two nodes.
|
Bits |
closureOf(int node)
Get the closure of this node - the set of all nodes which have this node
as an ancestor.
|
int |
closureSize(int node)
Get the count of nodes which have the passed node as an ancestor.
|
Bits |
closureUnion(int a,
int b)
Get the union of the closure of two nodes.
|
Bits |
connectors()
Return the set of nodes in the graph which have both inbound and outbound
references.
|
boolean |
containsEdge(int a,
int b)
Determine if an edge from a to b exists.
|
static IntGraph |
create(Bits[] references) |
static IntGraph |
create(Bits[] reverseReferences,
Bits[] references) |
static IntGraph |
create(BitSet[] references) |
static IntGraph |
create(BitSet[] reverseReferences,
BitSet[] references) |
void |
depthFirstSearch(int startingNode,
boolean up,
IntConsumer cons)
Perform a depth-first search, traversing the closure or reverse-closure
of the starting node depth-first.
|
void |
diff(IntGraph other,
BiConsumer<IntGraph,IntGraph> c)
Compare this graph and another; it is assumed that they
have the same size.
|
Bits |
disjointNodes()
Get the set of nodes in the graph whose closure is not shared by any
other nodes.
|
int |
distance(int a,
int b)
Get the minimum distance between two nodes.
|
void |
edges(IntBiConsumer bi)
Visit all edges in the graph.
|
double[] |
eigenvectorCentrality(int maxIterations,
double minDiff,
boolean inEdges,
boolean ignoreSelfEdges,
boolean l2norm)
Compute the eigenvector centrality of each node in the graph - an
importance measure that could loosely be phrased as most likely to be
connected through - meaning, unlike page rank, this emphasizes
"connector" nodes rather than most-linked nodes - those nodes
which, if removed, would break the most paths in the graph.
|
boolean |
hasInboundEdge(int from,
int to)
Determine if a direct inbound edge exits from one node to another.
|
boolean |
hasOutboundEdge(int from,
int to)
Determine if a direct outbound edge exits from one node to another.
|
int |
inboundReferenceCount(int node)
Returns the number of inbound edges a node has.
|
boolean |
isIndirectlyRecursive(int node)
Determine if a node is indirectly recursive - if the closure of it
contains a cycle back to it, not counting cycles to itself.
|
boolean |
isReachableFrom(int a,
int b)
Determine if node b is contained in the closure of node a.
|
boolean |
isRecursive(int node)
Determine if the passed node or a descendant of it has a cycle back to
itself.
|
boolean |
isReverseReachableFrom(int a,
int b)
Determine if the closure of a includes b.
|
boolean |
isUnreferenced(int node)
Determine if a node has no inbound edges - no ancestors.
|
static IntGraph |
load(ObjectInputStream objectInputStream) |
Bits |
neighbors(int startingNode)
Get the set of parent and child nodes for a node.
|
IntGraph |
omitting(int... items)
Create a new graph, sans the passed array of items - the resulting graph
will be smaller and if mapped to objects, have different indices than the
original.
|
Bits |
orphans()
Return the set of nodes which have no edges in or out.
|
int |
outboundReferenceCount(int node)
Returns the number of outbound edges a node has.
|
double[] |
pageRank(double minDifference,
double dampingFactor,
int maximumIterations,
boolean normalize)
Rank the nodes in this graph according to the page rank algorithm, which
detects most-linked-to nodes in the graph.
|
Bits |
parents(int node)
Get the set of nodes which reference the passed node.
|
List<IntPath> |
pathsBetween(int src,
int target)
Get a list of all paths between the source and target node, sorted low to
high by length.
|
Bits |
reverseClosureOf(int node)
Collect the reverse closure of a node - the set of all nodes which have
an outbound edge to this one or an ancestor of those nodes.
|
int |
reverseClosureSize(int node)
Get the count of nodes which have the passed node as a descendant.
|
void |
save(ObjectOutput out)
Serialize this graph.
|
Optional<IntPath> |
shortestPathBetween(int src,
int target)
Get the shortest path between two nodes in the graph.
|
Optional<IntPath> |
shortestUndirectedPathBetween(int src,
int target)
Get the shortest undirected path between two nodes.
|
int |
size()
Get the maximum node id + 1 of this graph, or the number of logical
nodes.
|
default <T> ObjectGraph<T> |
toObjectGraph(List<T> items) |
PairSet |
toPairSet()
Convert this graph to a PairSet, which internally uses a single Bits of
size * size bits to represent the matrix of all edges.
|
Bits |
topLevelOrOrphanNodes()
Get the set of nodes which have no inbound edges - no ancestors.
|
default StringGraph |
toStringGraph(String[] sortedNodeNames) |
int |
totalCardinality()
Get the combined cardinality of all nodes in this graph - the total
number of edges.
|
List<IntPath> |
undirectedPathsBetween(int src,
int target)
Get a list of all inbound and outbound paths between two nodes.
|
void |
walk(IntGraphVisitor v)
Walk the closure of the graph from top level nodes.
|
void |
walk(int startingWith,
IntGraphVisitor v)
Walk the closure of a node.
|
void |
walkUpwards(IntGraphVisitor v)
Walk the inverse closure of the bottom-most nodes in the graph.
|
void |
walkUpwards(int startingWith,
IntGraphVisitor v)
Walk the inverse closure of one node, visiting each ancestor exactly
once.
|
static IntGraph load(ObjectInputStream objectInputStream) throws IOException, ClassNotFoundException
IOExceptionClassNotFoundExceptionstatic IntGraphBuilder builder()
static IntGraphBuilder builder(int expectedSize)
default <T> ObjectGraph<T> toObjectGraph(List<T> items)
boolean abortableBreadthFirstSearch(int startingNode,
boolean up,
IntPredicate cons)
startingNode - The starting nodeup - Wheather to search antecedent nodes or successor nodescons - A predicateboolean abortableDepthFirstSearch(int startingNode,
boolean up,
IntPredicate cons)
startingNode - The starting nodeup - Wheather to search antecedent nodes or successor nodescons - A predicatePairSet allEdges()
Bits bottomLevelNodes()
void breadthFirstSearch(int startingNode,
boolean up,
IntConsumer cons)
up,
visiting each node in some order at least once.startingNode - The starting nodeup - If true, traverse antecedents of the starting node, not
descendantscons - A consumer which will visit nodesint[] byClosureSize()
int[] byReverseClosureSize()
Bits children(int node)
node - A nodeBits closureDisjunction(int a, int b)
a - The first nodeb - The second nodeBits closureDisjunction(int... nodes)
nodes - An array of nodesBits closureDisjunction(Bits nodes)
nodes - A set of nodesBits closureOf(int node)
node - A nodeint closureSize(int node)
node - A nodeBits closureUnion(int a, int b)
a - The first nodeb - The second nodeBits connectors()
boolean containsEdge(int a,
int b)
a - The first edgeb - The second edgevoid depthFirstSearch(int startingNode,
boolean up,
IntConsumer cons)
startingNode - The starting nodeup - If true, traverse the reverse-closurecons - A consumer which will visit nodesBits disjointNodes()
int distance(int a,
int b)
a - One nodeb - Another nodevoid edges(IntBiConsumer bi)
bi - A consumerdouble[] eigenvectorCentrality(int maxIterations,
double minDiff,
boolean inEdges,
boolean ignoreSelfEdges,
boolean l2norm)
maxIterations - The maxmum number of iterations to use refining the
answer before assuming an optimal answer has been determinedminDiff - The minimum difference in values between iterations which,
when reached, indicates that an optimal answer has been determined even
if the algorithm has refined the answer for less than
maxIterationsinEdges - If true, use inbound rather than outbound edges for the
calculationignoreSelfEdges - If true, do not count a node's direct cycles to
themselves in the scorel2norm - If set, attempt to normalize the result so scores will be
comparable across different graphsboolean hasInboundEdge(int from,
int to)
from - The source nodeto - The destination nodeboolean hasOutboundEdge(int from,
int to)
from - The source nodeto - The destination nodeint inboundReferenceCount(int node)
node - A nodeboolean isIndirectlyRecursive(int node)
node - A nodeboolean isReachableFrom(int a,
int b)
a - A nodeb - Another nodeboolean isRecursive(int node)
node - A nodeboolean isReverseReachableFrom(int a,
int b)
a - A nodeb - Another nodeboolean isUnreferenced(int node)
node - The nodeBits neighbors(int startingNode)
startingNode - A nodeBits orphans()
int outboundReferenceCount(int node)
node - A nodedouble[] pageRank(double minDifference,
double dampingFactor,
int maximumIterations,
boolean normalize)
minDifference - The minimum difference after an iteration, at which
point the algorithm should bail out and return the answerdampingFactor - The damping factormaximumIterations - The maximum number of iterations before the
algorithm should assume it has computed an optimal answer and bail outnormalize - If true, normalize the results so they are comparable
across calls to this method on different graphsBits parents(int node)
node - A nodeList<IntPath> pathsBetween(int src, int target)
src - The source nodetarget - The target nodeBits reverseClosureOf(int node)
node - An element in the graphint reverseClosureSize(int node)
node - A nodeOptional<IntPath> shortestPathBetween(int src, int target)
src - The source nodetarget - The target nodePairSet toPairSet()
Bits topLevelOrOrphanNodes()
int totalCardinality()
void walk(IntGraphVisitor v)
v - A visitorvoid walk(int startingWith,
IntGraphVisitor v)
startingWith - The starting nodev - A visitorvoid walkUpwards(IntGraphVisitor v)
v - A visitorvoid walkUpwards(int startingWith,
IntGraphVisitor v)
startingWith - The starting nodev - A visitorint size()
void save(ObjectOutput out) throws IOException
out - OutputIOException - If something goes wrongOptional<IntPath> shortestUndirectedPathBetween(int src, int target)
src - The first nodetarget - The second nodeList<IntPath> undirectedPathsBetween(int src, int target)
src - The first nodetarget - The second nodedefault StringGraph toStringGraph(String[] sortedNodeNames)
IntGraph omitting(int... items)
items - Items which should not be present - indices previously
present will be shifted downwards.void diff(IntGraph other, BiConsumer<IntGraph,IntGraph> c)
other - Another graphc - A consumer which will be passed two arguments: A
graph containing only added edges, and a graph containing only
removed edgesCopyright © 2010–2020 Mastfrog Technologies. All rights reserved.