|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectnct.graph.basic.BasicGraph<NodeType,WeightType>
public class BasicGraph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
A generic implementation of the Graph interface.
Field Summary | |
---|---|
protected boolean |
assumeGraphFinished
Used to indicate whether the graph has been updated (ie node or edge added) since the last time a value based on the graph (eg numEdges) was calculated. |
protected java.util.Map<NodeType,java.util.Map<NodeType,java.lang.String>> |
descMap
A mapping of nodes to nodes to edge descriptions. |
protected java.lang.String |
id
The id of the graph. |
protected int |
numEdges
The number of edges in the graph. |
protected WeightType |
score
The score of the graph. |
protected java.util.Map<NodeType,java.util.Map<NodeType,WeightType>> |
weightMap
A mapping of nodes to nodes to edge weights. |
Constructor Summary | |
---|---|
BasicGraph()
Constructor. |
|
BasicGraph(java.lang.String id)
Constructor. |
Method Summary | |
---|---|
boolean |
addEdge(NodeType nodeA,
NodeType nodeB,
WeightType weight)
Adds an edge to the graph. |
boolean |
addEdge(NodeType nodeA,
NodeType nodeB,
WeightType weight,
java.lang.String desc)
Adds an edge to the graph. |
boolean |
addNode(NodeType node)
Adds a node to the graph. |
BasicGraph<NodeType,WeightType> |
clone()
Returns a clone of this graph. |
int |
compareTo(Graph<NodeType,WeightType> g)
Returns the compareTo value of the score of this graph. |
int |
degreeOfNode(NodeType node)
Returns the degree (number of neighbors) of the node. |
Edge<NodeType,WeightType> |
getEdge(NodeType nodeA,
NodeType nodeB)
Returns the specified edge. |
java.lang.String |
getEdgeDescription(NodeType nodeA,
NodeType nodeB)
Returns a description of the edge implied by the two specified nodes. |
java.util.Set<Edge<NodeType,WeightType>> |
getEdges()
Returns a list of all edges in the graph. |
WeightType |
getEdgeWeight(NodeType nodeA,
NodeType nodeB)
Returns the weight of the edge implied by the two specified nodes. |
java.lang.String |
getId()
Returns the id of the graph, in this case the filename of the input file that specifies the graph. |
java.util.Set<NodeType> |
getNeighbors(NodeType node)
Returns a set all nodes adjacent to the specified node. |
java.util.Set<NodeType> |
getNodes()
Returns a set containing all nodes in the graph. |
WeightType |
getScore()
Returns the score of the graph. |
boolean |
isEdge(NodeType nodeA,
NodeType nodeB)
Indicates whether the specified nodes refer to a valid edge in the graph. |
boolean |
isNode(NodeType node)
Indicates whether the specified node is contained in the graph. |
int |
numberOfEdges()
Returns the number of edges in the graph. |
int |
numberOfNodes()
Returns the number of nodes in the graph. |
boolean |
removeEdge(NodeType nodeA,
NodeType nodeB)
Removes the specified edge from the graph. |
boolean |
removeNode(NodeType node)
Removes the specified node from the graph and all of its adjacent edges. |
boolean |
setEdgeDescription(NodeType nodeA,
NodeType nodeB,
java.lang.String desc)
Sets the description for the specified edge. |
boolean |
setEdgeWeight(NodeType nodeA,
NodeType nodeB,
WeightType weight)
Sets the edge weight of an existing edge. |
void |
setScore(WeightType score)
Sets the score of the graph. |
java.lang.String |
toString()
Returns a String representation of the graph format. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected java.util.Map<NodeType extends java.lang.Comparable<? super NodeType>,java.util.Map<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>> weightMap
protected java.util.Map<NodeType extends java.lang.Comparable<? super NodeType>,java.util.Map<NodeType extends java.lang.Comparable<? super NodeType>,java.lang.String>> descMap
protected java.lang.String id
protected WeightType extends java.lang.Comparable<? super WeightType> score
protected boolean assumeGraphFinished
protected int numEdges
Constructor Detail |
---|
public BasicGraph()
public BasicGraph(java.lang.String id)
id
- The graph id.Method Detail |
---|
public boolean addNode(NodeType node)
addNode
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
node
- The node to add.
public boolean addEdge(NodeType nodeA, NodeType nodeB, WeightType weight)
addEdge
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
nodeA
- The beginning node of the edge to add.nodeB
- The ending node of the edge to add.weight
- The edge weight.
public boolean addEdge(NodeType nodeA, NodeType nodeB, WeightType weight, java.lang.String desc)
addEdge
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
nodeA
- The beginning node of the edge to add.nodeB
- The ending node of the edge to add.weight
- The edge weight.desc
- The edge description.
public boolean isEdge(NodeType nodeA, NodeType nodeB)
isEdge
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
nodeA
- The beginning node of the edge to check.nodeB
- The ending node of the edge to check.
public boolean isNode(NodeType node)
isNode
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
node
- The node to check.
public WeightType getEdgeWeight(NodeType nodeA, NodeType nodeB)
getEdgeWeight
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
nodeA
- The source node of the edge.nodeB
- The target node of the edge.
public Edge<NodeType,WeightType> getEdge(NodeType nodeA, NodeType nodeB)
getEdge
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
nodeA
- The source node of the edge.nodeB
- The target node of the edge.
public java.util.Set<NodeType> getNodes()
getNodes
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
public java.util.Set<NodeType> getNeighbors(NodeType node)
getNeighbors
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
node
- The node whose neighbors we're requesting.
public java.lang.String getId()
getId
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
public int numberOfNodes()
numberOfNodes
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
public int numberOfEdges()
numberOfEdges
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
public int degreeOfNode(NodeType node)
degreeOfNode
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
node
- The node whose degree we're requesting.
public java.util.Set<Edge<NodeType,WeightType>> getEdges()
getEdges
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
public int compareTo(Graph<NodeType,WeightType> g)
compareTo
in interface java.lang.Comparable<Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>>
compareTo
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
g
- Graph to compare against this one.
public void setScore(WeightType score)
setScore
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
score
- The score to set the graph to.public WeightType getScore()
getScore
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
public BasicGraph<NodeType,WeightType> clone()
clone
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
clone
in class java.lang.Object
public java.lang.String getEdgeDescription(NodeType nodeA, NodeType nodeB)
getEdgeDescription
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
nodeA
- The beginning node of the edge.nodeB
- The ending node of the edge.
public boolean setEdgeDescription(NodeType nodeA, NodeType nodeB, java.lang.String desc)
setEdgeDescription
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
nodeA
- The source node of the edge.nodeB
- The target node of the edge.desc
- The description of the edge.
public java.lang.String toString()
Graph
toString
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
toString
in class java.lang.Object
public boolean removeEdge(NodeType nodeA, NodeType nodeB)
removeEdge
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
nodeA
- The beginning node of the edge to remove.nodeB
- The ending node of the edge to remove.
public boolean removeNode(NodeType node)
removeNode
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
node
- The node to be removed.
public boolean setEdgeWeight(NodeType nodeA, NodeType nodeB, WeightType weight)
setEdgeWeight
in interface Graph<NodeType extends java.lang.Comparable<? super NodeType>,WeightType extends java.lang.Comparable<? super WeightType>>
nodeA
- The source node of the edge.nodeB
- The target node of the edge.weight
- The weight of the edge.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |