public static final class Grafo.Dirigido<T>
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.util.List<Grafo.Edge<T>> |
edges
Vector of edges in the graph
|
private Grafo.Vertex<T> |
rootVertex
The vertex identified as the root of the graph
|
private java.util.List<Grafo.Vertex<T>> |
verticies
Vector of graph verticies
|
static int |
VISIT_COLOR_BLACK
Color used to mark nodes after descendants are completely visited
|
static int |
VISIT_COLOR_GREY
Color used to mark nodes as they are first visited in DFS order
|
static int |
VISIT_COLOR_WHITE
Color used to mark unvisited nodes
|
Constructor and Description |
---|
Dirigido()
Construct a new graph without any vertices or edges
|
Modifier and Type | Method and Description |
---|---|
boolean |
addEdge(Grafo.Vertex<T> from,
Grafo.Vertex<T> to,
int cost)
Insert a directed, weighted Edge into the graph.
|
boolean |
addVertex(Grafo.Vertex<T> v)
Add a vertex to the graph
|
void |
breadthFirstSearch(Grafo.Vertex<T> v,
Grafo.Visitor<T> visitor)
Perform a breadth first search of this graph, starting at v.
|
<E extends java.lang.Exception> |
breadthFirstSearch(Grafo.Vertex<T> v,
Grafo.VisitorEX<T,E> visitor)
Perform a breadth first search of this graph, starting at v.
|
void |
clearEdges()
Clear the mark state of all edges in the graph by calling clearMark() on
all edges.
|
void |
clearMark()
Clear the mark state of all verticies in the graph by calling clearMark()
on all verticies.
|
<E extends java.lang.Exception> |
depthFirstSearch(Grafo.Vertex<T> v,
Grafo.VisitorEX<T,E> visitor)
Perform a depth first serach using recursion.
|
void |
dfsSpanningTree(Grafo.Vertex<T> v,
Grafo.DFSVisitor<T> visitor)
Find the spanning tree using a DFS starting from v.
|
Grafo.Edge<T>[] |
findCycles()
Search the graph for cycles.
|
Grafo.Vertex<T> |
findVertexByData(T data,
java.util.Comparator<T> compare)
Search the verticies for one with data.
|
Grafo.Vertex<T> |
findVertexByName(java.lang.String name)
Search the verticies for one with name.
|
java.util.List<Grafo.Edge<T>> |
getEdges()
Get the graph edges
|
Grafo.Vertex<T> |
getRootVertex()
Get the root vertex
|
Grafo.Vertex<T> |
getVertex(int n)
Get the given Vertex.
|
java.util.List<Grafo.Vertex<T>> |
getVerticies()
Get the graph verticies
|
boolean |
insertBiEdge(Grafo.Vertex<T> from,
Grafo.Vertex<T> to,
int cost)
Insert a bidirectional Edge in the graph
|
boolean |
isEmpty()
Are there any verticies in the graph
|
boolean |
removeEdge(Grafo.Vertex<T> from,
Grafo.Vertex<T> to)
Remove an Edge from the graph
|
boolean |
removeVertex(Grafo.Vertex<T> v)
Remove a vertex from the graph
|
void |
setRootVertex(Grafo.Vertex<T> root)
Set a root vertex.
|
int |
size()
Get the vertex count.
|
java.lang.String |
toString() |
private void |
visit(Grafo.Vertex<T> v,
java.util.ArrayList<Grafo.Edge<T>> cycleEdges) |
public static final int VISIT_COLOR_WHITE
public static final int VISIT_COLOR_GREY
public static final int VISIT_COLOR_BLACK
private java.util.List<Grafo.Vertex<T>> verticies
private java.util.List<Grafo.Edge<T>> edges
private Grafo.Vertex<T> rootVertex
public boolean isEmpty()
public boolean addVertex(Grafo.Vertex<T> v)
v
- the Vertex to addpublic int size()
public Grafo.Vertex<T> getRootVertex()
public void setRootVertex(Grafo.Vertex<T> root)
root
- -
the vertex to set as the root and optionally add if it does not
exist in the graph.public Grafo.Vertex<T> getVertex(int n)
n
- the index [0, size()-1] of the Vertex to accesspublic java.util.List<Grafo.Vertex<T>> getVerticies()
public boolean addEdge(Grafo.Vertex<T> from, Grafo.Vertex<T> to, int cost) throws java.lang.IllegalArgumentException
from
- -
the Edge starting vertexto
- -
the Edge ending vertexcost
- -
the Edge weight/costjava.lang.IllegalArgumentException
- if from/to are not verticies in the graphpublic boolean insertBiEdge(Grafo.Vertex<T> from, Grafo.Vertex<T> to, int cost) throws java.lang.IllegalArgumentException
from
- -
the Edge starting vertexto
- -
the Edge ending vertexcost
- -
the Edge weight/costjava.lang.IllegalArgumentException
- if from/to are not verticies in the graphpublic java.util.List<Grafo.Edge<T>> getEdges()
public boolean removeVertex(Grafo.Vertex<T> v)
v
- the Vertex to removepublic boolean removeEdge(Grafo.Vertex<T> from, Grafo.Vertex<T> to)
from
- -
the Edge starting vertexto
- -
the Edge ending vertexpublic void clearMark()
Grafo.Vertex.clearMark()
public void clearEdges()
public <E extends java.lang.Exception> void depthFirstSearch(Grafo.Vertex<T> v, Grafo.VisitorEX<T,E> visitor) throws E extends java.lang.Exception
E
- Exceptionv
- -
the Vertex to start the search fromvisitor
- -
the vistor to inform prior toE
- if visitor.visit throws an exceptionE extends java.lang.Exception
public void breadthFirstSearch(Grafo.Vertex<T> v, Grafo.Visitor<T> visitor)
v
- -
the search starting pointvisitor
- -
the vistor whose vist method is called prior to visting a vertex.public <E extends java.lang.Exception> void breadthFirstSearch(Grafo.Vertex<T> v, Grafo.VisitorEX<T,E> visitor) throws E extends java.lang.Exception
E
- -
exceptionv
- -
the search starting pointvisitor
- -
the vistor whose vist method is called prior to visting a vertex.E
- if vistor.visit throws an exceptionE extends java.lang.Exception
public void dfsSpanningTree(Grafo.Vertex<T> v, Grafo.DFSVisitor<T> visitor)
v
- -
the vertex to start the search fromvisitor
- -
visitor invoked after each vertex is visited and an edge is added
to the tree.public Grafo.Vertex<T> findVertexByName(java.lang.String name)
name
- -
the vertex namepublic Grafo.Vertex<T> findVertexByData(T data, java.util.Comparator<T> compare)
data
- -
the vertex data to matchcompare
- -
the comparator to perform the matchpublic Grafo.Edge<T>[] findCycles()
private void visit(Grafo.Vertex<T> v, java.util.ArrayList<Grafo.Edge<T>> cycleEdges)
public java.lang.String toString()
toString
in class java.lang.Object