public class Graph
extends java.lang.Object
Graph data structure. A Graph can contain none to infinitely many GraphNode objects with or
without edges between them, which again can be either weighted ur unweighted.| Modifier and Type | Class and Description |
|---|---|
static class |
Graph.GraphNode
Defines
GraphNode objects as they are used in the Graph class. |
| Constructor and Description |
|---|
Graph()
Creates a
Graph object with no GraphNode objects. |
| Modifier and Type | Method and Description |
|---|---|
void |
addBidirectionalEdge(Graph.GraphNode graphNode1,
Graph.GraphNode graphNode2,
double weight)
Adds an edge from graphNode1 to graphNode2 and from graphNode1 to graphNode2, both with the specified weight.
|
void |
addEdge(Graph.GraphNode graphNode1,
Graph.GraphNode graphNode2,
double weight)
Adds an edge from graphNode1 to graphNode2 with the specified weight.
|
void |
addNode(Graph.GraphNode graphNode)
Adds the specified
GraphNode object to the Graph. |
boolean |
allNodesMarked()
Returns whether all
GraphNode objects in the Graph are marked. |
boolean |
contains(Graph.GraphNode graphNode)
Returns whether a specified
GraphNode object is in the Graph. |
boolean |
contains(java.lang.String nodeName)
Returns whether a
GraphNode object with the specified name is in the Graph. |
double |
cumulativeEdgeWeight(Graph.GraphNode graphNode)
Returns the summed up edgeWeights of all edges of the specified
GraphNode object. |
double |
edgeWeightSum()
Returns the sum of all edgeWeights in the
Graph. |
double |
getEdgeWeight(Graph.GraphNode graphNode1,
Graph.GraphNode graphNode2)
Returns the weight of the edge from graphNode1 to graphNode2.
|
List |
getNeighbors(Graph.GraphNode graphNode)
Returns a new
List object containing all GraphNode objects that are neighbors of the specified
GraphNode object. |
Graph.GraphNode |
getNode(java.lang.String nodeName)
Returns the
GraphNode object with the specified name. |
List |
getNodes()
Returns a new
List object containing all GraphNode objects in the Graph. |
boolean |
hasEdge(Graph.GraphNode graphNode1,
Graph.GraphNode graphNode2)
Returns whether there is an edge between the specified
GraphNode objects in the Graph. |
Graph.GraphNode |
highestWeight()
Returns the
GraphNode object with the highest summed up edgeWeights in the Graph. |
boolean |
isEmpty()
Returns true if the
Graph contains no GraphNode objects. |
void |
removeEdge(Graph.GraphNode graphNode1,
Graph.GraphNode graphNode2)
Removes the edge from graphNode1 to graphNode2 if there was any.
|
void |
removeEdges(Graph.GraphNode graphNode1,
Graph.GraphNode graphNode2)
Removes both edges between graphNode1 and graphNode2 if there were any.
|
void |
removeMarks()
Sets the 'marked' boolean to false for all
GraphNode objects in the Graph. |
void |
removeNode(Graph.GraphNode graphNode)
If graphNode !
|
public boolean isEmpty()
Graph contains no GraphNode objects. Else false.Graph contains no GraphNode objects. Else false.public void addNode(Graph.GraphNode graphNode)
GraphNode object to the Graph.
If it is null or a GraphNode object with the same name exists in the Graph already it is not
added.graphNode - the GraphNode object to add to the Graph.public boolean contains(java.lang.String nodeName)
GraphNode object with the specified name is in the Graph.nodeName - the name of a GraphNode object.GraphNode object with the specified name is in the Graph, else false.public boolean contains(Graph.GraphNode graphNode)
GraphNode object is in the Graph.graphNode - a GraphNode object.GraphNode is in the Graph, else false.public Graph.GraphNode getNode(java.lang.String nodeName)
GraphNode object with the specified name.
Returns null if there is no such GraphNode in the Graph.nodeName - the name of a GraphNode object.GraphNode object with the specified name or null if not on the Graph.public void removeNode(Graph.GraphNode graphNode)
Graph, it and all its edges are removed from the
Graph.
If graphNode == null or not in the Graph nothing happens.graphNode - the graphNode object to remove from the Graph.public void addEdge(Graph.GraphNode graphNode1, Graph.GraphNode graphNode2, double weight)
GraphNode object is null or not in the Graph, nothing changes.graphNode1 - the GraphNode object to create an edge to graphNode2 from.graphNode2 - the GraphNode object to create an edge from graphNode 1 to.weight - the weight of the new edge.public void addBidirectionalEdge(Graph.GraphNode graphNode1, Graph.GraphNode graphNode2, double weight)
GraphNode object is null or not in the Graph, nothing changes.graphNode1 - the GraphNode object to create an edge to and from graphNode2.graphNode2 - the GraphNode object to create an edge to and from graphNode1.weight - the weight of the new edges.public boolean hasEdge(Graph.GraphNode graphNode1, Graph.GraphNode graphNode2)
GraphNode objects in the Graph.
If any GraphNode object is null or not in the Graph the result is always false.graphNode1 - a GraphNode object.graphNode2 - another GraphNode object.public void removeEdge(Graph.GraphNode graphNode1, Graph.GraphNode graphNode2)
graphNode1 - a GraphNode object in the Graph.graphNode2 - another GraphNode object in the Graph.public void removeEdges(Graph.GraphNode graphNode1, Graph.GraphNode graphNode2)
graphNode1 - a GraphNode object in the Graph.graphNode2 - another GraphNode object in the Graph.public double getEdgeWeight(Graph.GraphNode graphNode1, Graph.GraphNode graphNode2)
graphNode1 - a GraphNode object.graphNode2 - another GraphNode object.public void removeMarks()
GraphNode objects in the Graph.public boolean allNodesMarked()
GraphNode objects in the Graph are marked.GraphNode objects in the Graph are marked, else false. Also true if
Graph is empty.public List getNodes()
List object containing all GraphNode objects in the Graph.List object containing all GraphNode objects in the Graph.public List getNeighbors(Graph.GraphNode graphNode)
List object containing all GraphNode objects that are neighbors of the specified
GraphNode object.graphNode - a GraphNode object which the Graph contains.List object containing all GraphNode objects that are neighbors of the specified
GraphNode object.public double edgeWeightSum()
Graph.Graph summed up.public double cumulativeEdgeWeight(Graph.GraphNode graphNode)
GraphNode object.graphNode - a GraphNode object.GraphNode (and his neighbors).public Graph.GraphNode highestWeight()
GraphNode object with the highest summed up edgeWeights in the Graph.GraphNode with the highest summed up edgeWeights.