Graph
Class Edge

java.lang.Object
  |
  +--Graph.Edge

public final class Edge
extends java.lang.Object

The Edge class for our Graph contains only the base minimum member variables. Environment specific semantics (such as RouterEdge or bandwidth etc) that are often attached to an edge are divorced from the this class and stored in a decorator class, EdgeConf (short for EdgeConfiguration). As such you can add/remove attributes to the Edge at run-time without having to change the Edge representation.

We use the decorator pattern as the relationship between a Edge and its configuration, EdgeConf. This pattern is described in Design Patterns: Elements of Reusable Object-Oriented Software by Gamma et al. ISBN#: 0-201-63361-2.

Like NodeIDs, unique edge ids are determined by using a static int and incrementing it each time a new edge is created. This is the default method. However, for improved lookup performance, we also provide alternative methods of computing EdgeIDs which embed the ids of the source and destination nodes of this edge in the EdgeID. As such given the source and destination node, one can compute the EdgeID in constant time. See Edge.computeID(..) and Edge.computeDirectedID(..) methods for more on how this is done.

NOTE: The direction of the edge can be either DIRECTED or UNDIRECTED. This allows for graphs that contain a hybrid of directed and undirected edges.


Field Summary
static Graph.EdgeIDComparator IDcomparator
           
 
Constructor Summary
Edge(Node src, Node dst)
          Class Constructor.
 
Method Summary
static int computeDirectedID(int srcID, int dstID)
           
static long computeDirectedLongID(int srcID, int dstID)
          Analagous to computeLongID above but computes ID for directed graph.
static int computeID(int srcID, int dstID)
          Computes a unique EdgeID These IDs have the property that id(src,dest) = id(dest,src) and so should be used with undirected graphs only.
static long computeLongID(int srcID, int dstID)
          Similar to computeID(src,dest) except returns a long id.
 float getBW()
           
 int getColor()
           
 int getDirection()
          returns direction of this edge.
 Node getDst()
           
 EdgeConf getEdgeConf()
           
static int getEdgeCount()
           
 float getEuclideanDist()
          compute the euclidean distance for this edge.
 int getID()
           
 Node getSrc()
           
 void setBW(float bw)
           
 void setColor(int c)
           
 void setDirection(int d)
          Set the direction of this edge to either GraphConstants.DIRECTED or GraphConstants.UNDIRECTED
 void setDst(Node dst)
           
 void setEdgeConf(EdgeConf e)
           
 void setEuclideanDist(float d)
           
 void setSrc(Node src)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

IDcomparator

public static Graph.EdgeIDComparator IDcomparator
Constructor Detail

Edge

public Edge(Node src,
            Node dst)
Class Constructor.
Parameters:
src - The source node of this edge
dst - The destination node of this edge
Method Detail

setDirection

public void setDirection(int d)
Set the direction of this edge to either GraphConstants.DIRECTED or GraphConstants.UNDIRECTED
Parameters:
d - the direction of the graph, one of the possible values specified in class GraphConstants

getDirection

public int getDirection()
returns direction of this edge. (either GraphConstants.DIRECTED or GraphConstants.UNDIRECTED)
Returns:
int The Direction of the edge. Either GraphConstants.DIRECTED or GraphConstants.UNDIRECTED

computeID

public static int computeID(int srcID,
                            int dstID)
Computes a unique EdgeID These IDs have the property that id(src,dest) = id(dest,src) and so should be used with undirected graphs only. See the computeDirectedID method for computing edgeIDs for directed graphs. An EdgeID embeds the IDs of the srouce and destination nodes of this edge in it. This is done by simply concatenating the bit represenation of the source and destination. If the concatenated represenation is larger than an int, -1 is returned. The caller of the function should check for this condition and if a -1 is returned, computeLongID should be called instead.
Parameters:
srcID - generally, the id of the source-node
dstID - generally, the id of the dest-node
Returns:
int returns an int which is srcID concattenated with dstID. -1 if concattenated result overflows int.

computeLongID

public static long computeLongID(int srcID,
                                 int dstID)
Similar to computeID(src,dest) except returns a long id. this should be used if the srcID and destID are too large to yield an EdgeID which can fit in an int. Gurantees that id(src,dst) == id(dst,src)
Parameters:
srcID - the node-id of the srouce node
dstID - the node-id of the dest node
Returns:
long this edgeID is a long repr. of srcID concattenated with dstID

computeDirectedID

public static int computeDirectedID(int srcID,
                                    int dstID)

computeDirectedLongID

public static long computeDirectedLongID(int srcID,
                                         int dstID)
Analagous to computeLongID above but computes ID for directed graph. That is, ids returned by this method gurantee that id(a,b) ! = id(b,a).
Parameters:
srcID - the source node id
dstID - the dest node id
Returns:
long the result of concatenating srcID with dstID

getEuclideanDist

public float getEuclideanDist()
compute the euclidean distance for this edge. uses the (x,y) coords of the source and destination nodes to do this.
Returns:
float the eculidean dist: d = sqrt( (x1-x2)^2 + (y1-y2)^2).

getSrc

public Node getSrc()

getDst

public Node getDst()

getID

public int getID()

getEdgeCount

public static int getEdgeCount()

getColor

public int getColor()

getEdgeConf

public EdgeConf getEdgeConf()

getBW

public float getBW()

setSrc

public void setSrc(Node src)

setDst

public void setDst(Node dst)

setColor

public void setColor(int c)

setEdgeConf

public void setEdgeConf(EdgeConf e)

setBW

public void setBW(float bw)

setEuclideanDist

public void setEuclideanDist(float d)