|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--Graph.Graph
An Internet topology is represented as graph with the nodes representing routers (or ASs, depending on the topology level) and the edges representing links between them.
We use an adjacency list representation as our Graph implementation. Nodes are represented by their own class, Node and similary, edges by a class, Edge. The Graph implementation is independent from any semantics attached to a Graph, its nodes, and its edges. As such, if you decide to use a different representation of a graph, you can do so by simply replacing this representation with your own and not affecting BRITE's generation (as long as you expose a similar interface). The idea is to allow for the ability to "plug and play" different graph representations depending on your need. (Some graph representations might be faster than others for specific analysis tasks etc)
We now provide implementation details of this Graph representation:
This Graph representation has three HashMaps:
Nodes
, Edges
and
adjList
. The Nodes
HashMap contains as
keys the node-ids and as values, the Node
objects
themselves. Similarly, the Edges
HashMap contains
Edge-IDs as keys and Edge
objects as values. The
adjList
HashMap contains as keys node-ids of source
nodes and destination node-ids as values. (How NodeIDs and EdgeIDs
are computed can be found in the documentation for the Node and
Edge class respectively.)
Field Summary | |
protected java.util.HashMap |
adjList
|
protected java.util.HashMap |
Edges
|
protected java.util.HashMap |
Nodes
|
protected int |
numEdges
|
protected int |
numNodes
|
Constructor Summary | |
Graph()
Create a graph with default initial capacity. |
|
Graph(java.util.ArrayList graphs)
Given a vector of graphs, produce a single graph with disconnected components. |
|
Graph(int numNodes)
Create a graph with specified intial capacity. |
Method Summary | |
void |
addDirectedEdge(Edge e)
The addDirectedEdge method of a Graph takes the source node of the edge to be added and adds it as a key in the adjList. |
void |
addEdge(Edge e)
The addEdge method checks if the Edge is directed or undirected. |
void |
addNode(Node n)
add a node to our adjacency list. |
void |
addUndirectedEdge(Edge e)
The addUndirectedEdge method adds the given edge's source node-id and destination node-id to the adjList twice: once with the source node-id as the key and next with the desitnation node-id as the key. |
void |
dfs()
does a depth first traversal of the graph, marking all visited nodes black. |
void |
dumpToOutput()
a useful debug routine. |
java.util.HashMap |
getAdjList()
returns a HashMap representation of the adjacency list. |
java.util.HashMap |
getEdges()
returns a HashMap representation of the Edges in the graph. |
Edge[] |
getEdgesArray()
returns an Array representation (copy) of all the edges in this graph |
java.util.ArrayList |
getEdgesVector()
Returns an ArrayList representation (copy) of all the edges in this graph |
Edge[] |
getIncidentEdges(Node src)
Given a node, returns all node that are incident to this node (incoming and outgoing). |
Node |
getKthNode(int k)
returns the kth node in the ordering of the nodes. |
Node[] |
getLeafNodes()
returns the leaf nodes of a graph. |
Node[] |
getNeighborsOf(Node n)
Given node n, returns an array of Node objects that are n's neighbors. |
Node |
getNodeFromID(int id)
a lookup function to get a node from its id. |
java.util.HashMap |
getNodes()
returns a HashMap representation of the Nodes in the graph. |
Node[] |
getNodesArray()
Returns an Array representation (copy) of the ndoes in this graph |
java.util.ArrayList |
getNodesVector()
Returns an ArrayList representation (copy) of the nodes in this graph. |
int |
getNumEdges()
get number of edges in this graph |
int |
getNumNeighborsOf(Node n)
Given Node n, returns number of neighbors of N. |
int |
getNumNodes()
get number of nodes in this graph |
Node |
getSmallestDegreeNode()
returns the node with smallest out degree |
Node |
getSmallestDegreeNodeThreshold(int k)
returns the node with smallest degree that is more than or equal to k |
boolean |
hasEdge(int srcID,
int dstID)
given IDs of source and destination nodes, returns true if an edge between the corresponding nodes exists. |
boolean |
hasEdge(Node src,
Node dst)
given source and destination nodes, returns true if an edge exists between those nodes |
boolean |
hasNode(int nID)
|
boolean |
hasNode(java.lang.Integer id)
returns true if the graph contains a node with specified node-id |
boolean |
isConnected()
returns true if the graph is connected, false if it has disconnected components. |
void |
markAllNodes(int color)
helper function to mark all nodes in the graph a specific color. |
void |
removeNode(Node n)
not implemented yet |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
protected int numNodes
protected int numEdges
protected java.util.HashMap Nodes
protected java.util.HashMap Edges
protected java.util.HashMap adjList
Constructor Detail |
public Graph()
public Graph(int numNodes)
numNodes
- The initial number of nodes in the graphpublic Graph(java.util.ArrayList graphs)
Method Detail |
public void addEdge(Edge e)
e
- The edge to be addedpublic void addUndirectedEdge(Edge e)
e
- The edge to be added to our graphpublic void addDirectedEdge(Edge e)
e
- the Edge to be added to our graphpublic boolean hasEdge(Node src, Node dst)
src
- the srouce nodedst
- the destination nodepublic boolean hasEdge(int srcID, int dstID)
srcID
- the node id of the source nodedstID
- the node if of the destination nodepublic void addNode(Node n)
n
- the node to be addedpublic boolean hasNode(java.lang.Integer id)
id
- the Integer and int representation of the nodepublic boolean hasNode(int nID)
public void removeNode(Node n)
public void dumpToOutput()
from -> to1, to2, to3 from2 -> to7, to8, to9 ... NumEdges =NumNodes =
public Edge[] getIncidentEdges(Node src)
src
- The source node to examinepublic java.util.ArrayList getNodesVector()
public Node[] getNodesArray()
public java.util.ArrayList getEdgesVector()
public Edge[] getEdgesArray()
public int getNumNodes()
public int getNumEdges()
public java.util.HashMap getNodes()
public java.util.HashMap getEdges()
public java.util.HashMap getAdjList()
public int getNumNeighborsOf(Node n)
Node
- npublic Node[] getNeighborsOf(Node n)
Node
- npublic Node getNodeFromID(int id)
public Node getKthNode(int k)
public Node getSmallestDegreeNode()
public Node[] getLeafNodes()
public Node getSmallestDegreeNodeThreshold(int k)
public void dfs()
public boolean isConnected()
public void markAllNodes(int color)
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |