Graph.Edge| Constructor and Description |
|---|
AdjacencyMatrix(int n)
Constructor.
|
AdjacencyMatrix(int n,
boolean digraph)
Constructor.
|
| Modifier and Type | Method and Description |
|---|---|
void |
addEdge(int source,
int target)
Creates a new edge in this graph, going from the source vertex to the
target vertex, and returns the created edge.
|
void |
addEdge(int source,
int target,
double weight)
Creates a new edge in this graph, going from the source vertex to the
target vertex, and returns the created edge.
|
int[][] |
bfs()
Breadth-first search connected components of graph.
|
void |
bfs(Visitor visitor)
BFS search on graph and performs some operation defined in visitor
on each vertex during traveling.
|
int[][] |
dfs()
Depth-first search connected components of graph.
|
void |
dfs(Visitor visitor)
DFS search on graph and performs some operation defined in visitor
on each vertex during traveling.
|
double[] |
dijkstra(int s)
Calculate the shortest path from a source to all other vertices in the
graph by Dijkstra algorithm.
|
double[] |
dijkstra(int s,
boolean weighted)
Calculates the shortest path by Dijkstra algorithm.
|
int |
getDegree(int vertex)
Returns the degree of the specified vertex.
|
Graph.Edge |
getEdge(int source,
int target)
Returns an edge connecting source vertex to target vertex if such edge
exist in this graph.
|
java.util.Collection<Graph.Edge> |
getEdges()
Returns a set of the edges contained in this graph.
|
java.util.Collection<Graph.Edge> |
getEdges(int vertex)
Returns a set of all edges from the specified vertex.
|
java.util.Collection<Graph.Edge> |
getEdges(int source,
int target)
Returns a set of all edges connecting source vertex to target vertex if
such vertices exist in this graph.
|
int |
getIndegree(int vertex)
Returns the in-degree of the specified vertex.
|
int |
getNumVertices()
Returns the number vertices.
|
int |
getOutdegree(int vertex)
Returns the out-degree of the specified vertex.
|
double |
getWeight(int source,
int target)
Returns the weight assigned to a given edge.
|
boolean |
hasEdge(int source,
int target)
Returns true if and only if this graph contains an edge going
from the source vertex to the target vertex.
|
double |
pushRelabel(double[][] flow,
int source,
int sink)
Push-relabel algorithm for maximum flow
|
void |
removeEdge(Graph.Edge edge)
Removes the specified edge from the graph.* Returns true if the
graph contained the specified edge.
|
void |
removeEdge(int source,
int target)
In a simple graph, removes and returns the edge going from the specified source
vertex to the specified target vertex.
|
void |
removeEdges(java.util.Collection<Graph.Edge> edges)
Removes a set of edges from the graph.
|
AdjacencyMatrix |
setWeight(int source,
int target,
double weight)
Sets the weight assigned to a given edge.
|
int[] |
sortbfs()
Topological sort digraph by breadth-first search of graph.
|
int[] |
sortdfs()
Reverse topological sort digraph by depth-first search of graph.
|
AdjacencyMatrix |
subgraph(int[] vertices)
Returns a subgraph containing all given vertices.
|
double[][] |
toArray()
Returns the adjacency matrix.
|
smile.math.matrix.Matrix |
toMatrix()
Returns the (dense or sparse) matrix representation of the graph.
|
public AdjacencyMatrix(int n)
n - the number of vertices.public AdjacencyMatrix(int n,
boolean digraph)
n - the number of vertices.digraph - true if this is a directed graph.public int getNumVertices()
GraphgetNumVertices in interface Graphpublic boolean hasEdge(int source,
int target)
Graphpublic double getWeight(int source,
int target)
Graphpublic AdjacencyMatrix setWeight(int source, int target, double weight)
Graphpublic java.util.Collection<Graph.Edge> getEdges()
Graphpublic java.util.Collection<Graph.Edge> getEdges(int vertex)
Graphpublic java.util.Collection<Graph.Edge> getEdges(int source, int target)
GraphIn undirected graphs, some of the returned edges may have their source and target vertices in the opposite order.
public Graph.Edge getEdge(int source, int target)
Graph null.
In undirected graphs, the returned edge may have its source and target vertices in the opposite order.
For multi-graph, the return value is ill-defined.
public void addEdge(int source,
int target)
Graphpublic void addEdge(int source,
int target,
double weight)
Graphpublic void removeEdges(java.util.Collection<Graph.Edge> edges)
GraphremoveEdges in interface Graphedges - edges to be removed from this graph.public void removeEdge(int source,
int target)
GraphremoveEdge in interface Graphsource - the id of source vertex of the edge.target - the id of target vertex of the edge.public void removeEdge(Graph.Edge edge)
GraphremoveEdge in interface Graphedge - edge to be removed from this graph, if present.public int getDegree(int vertex)
Graphpublic int getIndegree(int vertex)
GraphgetIndegree in interface Graphvertex - the id of vertex.public int getOutdegree(int vertex)
GraphgetOutdegree in interface Graphvertex - the id of vertex.public int[] sortdfs()
Graphpublic int[][] dfs()
Graphpublic void dfs(Visitor visitor)
Graphpublic int[] sortbfs()
Graphpublic int[][] bfs()
Graphpublic void bfs(Visitor visitor)
Graphpublic double[] dijkstra(int s)
Graphpublic double[] dijkstra(int s,
boolean weighted)
s - The source vertex.weighted - True to calculate weighted path. Otherwise, the edge weights will be ignored.public AdjacencyMatrix subgraph(int[] vertices)
Graphpublic double[][] toArray()
public double pushRelabel(double[][] flow,
int source,
int sink)