Package ptolemy.graph
Class Edge
- java.lang.Object
-
- ptolemy.graph.Element
-
- ptolemy.graph.Edge
-
public final class Edge extends Element
A weighted or unweighted edge for a directed or undirected graph. The connectivity of edges is specified by source nodes and sink nodes. A directed edge is directed from its source node to its sink node. For an undirected edge, the source node is simply the first node that was specified when the edge was created, and the sink node is the second node. This convention allows undirected edges to later be converted in a consistent manner to directed edges, if desired.On creation of an edge, an arbitrary object can be associated with the edge as the weight of the edge. We say that an edge is unweighted if it does not have an assigned weight. It is an error to attempt to access the weight of an unweighted edge.
Self-loop edges (edges whose source and sink nodes are identical) are allowed.
Once an edge is created, its source node and sink node cannot be changed.
- Since:
- Ptolemy II 2.0
- Version:
- $Id$
- Author:
- Shuvra S. Bhattacharyya
- See Also:
Node
- Pt.AcceptedRating:
- Red (cxh)
- Pt.ProposedRating:
- Red (cxh)
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.String
descriptor()
A one-word description of the type of this graph element.boolean
isSelfLoop()
Return true if this is a self-loop edge.Node
sink()
Return the sink node of the edge.Node
source()
Return the source node of the edge.java.lang.String
toString()
Return a string representation of the edge, including information about the edge weight.java.lang.String
toString(boolean showWeight)
Return a string representation of the edge, optionally including information about the edge weight.-
Methods inherited from class ptolemy.graph.Element
getWeight, hasWeight, removeWeight, setWeight
-
-
-
-
Constructor Detail
-
Edge
public Edge(Node source, Node sink)
Construct an unweighted edge with a specified source node and sink node.- Parameters:
source
- The source node.sink
- The sink node.
-
Edge
public Edge(Node source, Node sink, java.lang.Object weight)
Construct a weighted edge with a specified source node, sink node, and edge weight.- Parameters:
source
- The source node.sink
- The sink node.weight
- The edge weight.- Throws:
java.lang.IllegalArgumentException
- If the specified weight isnull
.
-
-
Method Detail
-
descriptor
public java.lang.String descriptor()
A one-word description of the type of this graph element.- Overrides:
descriptor
in classElement
- Returns:
- The description.
-
isSelfLoop
public boolean isSelfLoop()
Return true if this is a self-loop edge.- Returns:
- True if this is a self-loop edge.
-
sink
public Node sink()
Return the sink node of the edge.- Returns:
- The sink node.
-
source
public Node source()
Return the source node of the edge.- Returns:
- The source node.
-
toString
public java.lang.String toString(boolean showWeight)
Return a string representation of the edge, optionally including information about the edge weight. The string representation is of the form(source, sink, weight)
,where
source
,sink
, andweight
are string representations of the source node, sink node, and edge weight, respectively. If the edge is unweighted or theshowWeight
argument is false, then the string representation is simply(source, sink)
.- Parameters:
showWeight
- True to include a string representation of the edge weight in the string representation of the edge.- Returns:
- A string representation of the edge.
-
toString
public java.lang.String toString()
Return a string representation of the edge, including information about the edge weight.- Overrides:
toString
in classjava.lang.Object
- Returns:
- A string representation of the edge.
- See Also:
toString(boolean)
-
-