T
- The class of the node, used when getting a nodepublic class Graph<T> extends Object implements Serializable
Modifier and Type | Field and Description |
---|---|
static int |
DEFAULT_K
Number of edges per node.
|
Constructor and Description |
---|
Graph()
Initialize an empty graph with k = 10.
|
Graph(Graph<T> origin)
Copy constructor.
|
Graph(int k)
Initialize an empty graph, and set k (number of edges per node).
|
Modifier and Type | Method and Description |
---|---|
int |
add(T new_node)
Add a node to the online graph using exhaustive search approach.
|
int |
compare(Graph<T> other)
Count the number of edges/neighbors that are the same (based on
similarity) in both graphs.
|
ArrayList<Graph<T>> |
connectedComponents()
Split the graph in connected components (usually you will first prune the
graph to remove "weak" edges).
|
boolean |
containsKey(T node) |
Iterable<Map.Entry<T,NeighborList>> |
entrySet() |
boolean |
equals(Object obj) |
void |
fastAdd(T node)
Add a node to the online graph, using approximate online graph building
algorithm presented in "Fast Online k-nn Graph Building" by Debatty
et al.
|
void |
fastAdd(T new_node,
OnlineConfig conf)
Add a node to the online graph, using approximate online graph building
algorithm presented in "Fast Online k-nn Graph Building" by Debatty
et al.
|
void |
fastRemove(T node_to_remove)
Remove a node from the graph (and update the graph) using fast
approximate algorithm.
|
void |
fastRemove(T node_to_remove,
OnlineConfig conf)
Remove a node from the graph (and update the graph) using fast
approximate algorithm.
|
FastSearchResult |
fastSearch(T query)
Approximate fast graph based search, as published in "Fast Online k-nn
Graph Building" by Debatty et al.
|
FastSearchResult |
fastSearch(T query,
FastSearchConfig conf)
Approximate fast graph based search, as published in "Fast Online k-nn
Graph Building" by Debatty et al.
|
FastSearchResult |
fastSearch(T query,
FastSearchConfig conf,
T start)
Approximate fast graph based search, as published in "Fast Online k-nn
Graph Building" by Debatty et al.
|
LinkedList<T> |
findNeighbors(LinkedList<T> starting_points,
int depth)
Recursively search neighbors of neighbors, up to a given depth.
|
T |
first()
Get the first node in the graph.
|
HashMap<T,NeighborList> |
getHashMap()
Get the underlying hash map that stores the nodes and associated
neighborlists.
|
int |
getK()
Get k (the number of edges per node).
|
NeighborList |
getNeighbors(T node)
Get the neighborlist of this node.
|
ArrayList<T> |
getNodes() |
T |
getRandomNode()
Return a random node from the graph.
|
SimilarityInterface<T> |
getSimilarity()
Get the similarity measure.
|
int |
hashCode() |
void |
prune(double threshold)
Remove from the graph all edges with a similarity lower than threshold.
|
NeighborList |
put(T node,
NeighborList neighborlist) |
NeighborList |
search(T query,
int k)
Multi-thread exhaustive search.
|
void |
setK(int k)
Set k (the number of edges per node).
|
void |
setSimilarity(SimilarityInterface<T> similarity)
Set the similarity measure used to build or search the graph.
|
int |
size() |
ArrayList<Graph<T>> |
stronglyConnectedComponents()
Computes the strongly connected sub-graphs (where every node is reachable
from every other node) using Tarjan's algorithm, which has computation
cost O(n).
|
String |
toString() |
void |
writeGEXF(String filename)
Writes the graph as a GEXF file (to be used in Gephi, for example).
|
public static final int DEFAULT_K
public Graph(int k)
k
- public Graph()
public final SimilarityInterface<T> getSimilarity()
public final void setSimilarity(SimilarityInterface<T> similarity)
similarity
- public final int getK()
public final void setK(int k)
k
- public final NeighborList getNeighbors(T node)
node
- public final T first() throws NoSuchElementException
NoSuchElementException
- if the graph is empty...public final T getRandomNode()
public final void prune(double threshold)
threshold
- public final ArrayList<Graph<T>> connectedComponents()
public final ArrayList<Graph<T>> stronglyConnectedComponents()
public final NeighborList put(T node, NeighborList neighborlist)
node
- neighborlist
- public final boolean containsKey(T node)
node
- public final int size()
public final Iterable<Map.Entry<T,NeighborList>> entrySet()
public final LinkedList<T> findNeighbors(LinkedList<T> starting_points, int depth)
starting_points
- depth
- public final HashMap<T,NeighborList> getHashMap()
public final NeighborList search(T query, int k) throws InterruptedException, ExecutionException
query
- k
- InterruptedException
- if thread is interruptedExecutionException
- if thread cannot completepublic final FastSearchResult fastSearch(T query)
query
- public final FastSearchResult fastSearch(T query, FastSearchConfig conf)
query
- conf
- public final FastSearchResult fastSearch(T query, FastSearchConfig conf, T start)
conf
- start
- starting pointquery
- query pointpublic final void writeGEXF(String filename) throws FileNotFoundException, IOException
filename
- FileNotFoundException
- if filename is invalidIOException
- if cannot write to filepublic final int add(T new_node)
new_node
- public final void fastAdd(T node)
node
- public final void fastAdd(T new_node, OnlineConfig conf)
new_node
- conf
- public final void fastRemove(T node_to_remove)
node_to_remove
- public final void fastRemove(T node_to_remove, OnlineConfig conf)
node_to_remove
- conf
- public final int compare(Graph<T> other)
other
- Copyright © 2017. All rights reserved.