|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnet.scheinerman.graph.Graph<E>
public class Graph<E>
A Graph
is a group of vertices, with edges between vertices. This implementation places
vertices in a HashMap
with the key being a Location
and the value for a given key being
a Vertex
. Each vertex has an array of Edge
objects. Each Edge
has two
vertices.
Graph can read files given in the simple graph format. The simple graph format consists of three
parts:
4 3
1 3
2 3
2 4
140 200
210 120
50 50
60 80
xLoc yLoc
, (x,y).
Constructor Summary | |
---|---|
Graph()
Creates a new empty graph. |
Method Summary | ||
---|---|---|
boolean |
add(Vertex<E> v)
Adds a vertex at its given location to this graph. |
|
boolean |
addAll(java.util.Collection<? extends Vertex<E>> arg0)
|
|
void |
clear()
|
|
void |
complete()
|
|
boolean |
contains(java.lang.Object o)
|
|
boolean |
containsAll(java.util.Collection<?> c)
|
|
static
|
createInputGraph(java.io.File file)
Creates a Graph object given a file in the Simple Graph Format. |
|
java.io.File |
createOutputFile(java.lang.String path)
Creates an output file at the given location using the Simple Graph Format. |
|
void |
genMinSpanTree(Vertex<E> v)
|
|
Vertex<E> |
get(Location loc)
Returns the Vertex contained at Location loc . |
|
java.util.Set<Vertex<E>> |
getComponent(Vertex<E> v)
|
|
java.util.Set<Location> |
getLocations()
Retrieves the set of all vertex locations for this graph. |
|
Vertex<E> |
getVertexAt(Location l)
Retrieves the vertex at a given location. |
|
java.util.Collection<Vertex<E>> |
getVertexCollection()
|
|
java.util.HashMap<Location,Vertex<E>> |
getVertices()
Returns the map of locations to vertices in this graph. |
|
double |
getWeight()
|
|
boolean |
isEmpty()
|
|
java.util.Iterator<Vertex<E>> |
iterator()
Returns an iterator that iterates over the vertices in the graph. |
|
Vertex<E> |
remove(Location loc)
Removes and returns the vertex at the given location. |
|
boolean |
remove(java.lang.Object arg0)
|
|
boolean |
removeAll(java.util.Collection<?> arg0)
|
|
boolean |
retainAll(java.util.Collection<?> arg0)
|
|
int |
size()
|
|
java.lang.Object[] |
toArray()
|
|
|
toArray(T[] a)
|
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
---|
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Methods inherited from interface java.util.Collection |
---|
equals, hashCode |
Constructor Detail |
---|
public Graph()
Method Detail |
---|
public boolean add(Vertex<E> v)
add
in interface java.util.Collection<Vertex<E>>
v
- - a vertexpublic boolean addAll(java.util.Collection<? extends Vertex<E>> arg0)
addAll
in interface java.util.Collection<Vertex<E>>
public void clear()
clear
in interface java.util.Collection<Vertex<E>>
public void complete()
public java.io.File createOutputFile(java.lang.String path) throws java.io.IOException
path
- - a path for the file.
java.io.IOException
- - if the file cannot be read or created.public static <E> Graph<E> createInputGraph(java.io.File file) throws java.io.FileNotFoundException
Graph
object given a file in the Simple Graph Format.
file
- - the file to be read
java.io.FileNotFoundException
- - if the file cannot be found.public boolean contains(java.lang.Object o)
contains
in interface java.util.Collection<Vertex<E>>
public boolean containsAll(java.util.Collection<?> c)
containsAll
in interface java.util.Collection<Vertex<E>>
public java.util.Set<Vertex<E>> getComponent(Vertex<E> v)
public java.util.Set<Location> getLocations()
public Vertex<E> getVertexAt(Location l)
loc == getVertexAt(loc).getLocation()
will always return true.
l
- - a location
l
.public java.util.Collection<Vertex<E>> getVertexCollection()
public java.util.HashMap<Location,Vertex<E>> getVertices()
public double getWeight()
public Vertex<E> get(Location loc)
loc
. If no vertex
exists at the given location, null
will be returned.
loc
- - a location
public boolean isEmpty()
isEmpty
in interface java.util.Collection<Vertex<E>>
public void genMinSpanTree(Vertex<E> v)
public Vertex<E> remove(Location loc)
null
is returned.
loc
- - a location
public boolean remove(java.lang.Object arg0)
remove
in interface java.util.Collection<Vertex<E>>
public boolean removeAll(java.util.Collection<?> arg0)
removeAll
in interface java.util.Collection<Vertex<E>>
public boolean retainAll(java.util.Collection<?> arg0)
retainAll
in interface java.util.Collection<Vertex<E>>
public int size()
size
in interface java.util.Collection<Vertex<E>>
public java.lang.Object[] toArray()
toArray
in interface java.util.Collection<Vertex<E>>
public <T> T[] toArray(T[] a)
toArray
in interface java.util.Collection<Vertex<E>>
public java.lang.String toString()
toString
in class java.lang.Object
public java.util.Iterator<Vertex<E>> iterator()
iterator
in interface java.lang.Iterable<Vertex<E>>
iterator
in interface java.util.Collection<Vertex<E>>
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |