peersim.core
Class OverlayGraph

java.lang.Object
  extended by peersim.core.OverlayGraph
All Implemented Interfaces:
Graph

public class OverlayGraph
extends java.lang.Object
implements Graph

This class is an adaptor which makes a Linkable protocol layer look like a graph. It is useful because it allows the application of many graph algorithms and graph topology initialization methods. If the overlay network changes after creating this object, the changes will be reflected. However, if the nodes are reshuffled (see Network.shuffle()), or if the node list changes (addition/removal), then the behaviour becomes unspecified. The indices of nodes are from 0 to Network.size()-1. The fail state of nodes has an effect on the graph: all nodes are included but edges are included only if both ends are up. This expresses the fact that this graph is in fact defined by the "can communicate with" relation.


Field Summary
 int protocolID
          The protocol ID that selects the Linkable protocol to convert to a graph.
 boolean wireDirected
          Tells if the graph should be wired in an undirected way.
 
Constructor Summary
OverlayGraph(int protocolID)
           
OverlayGraph(int protocolID, boolean wireDirected)
           
 
Method Summary
 boolean clearEdge(int i, int j)
          Not supported
 int degree(int i)
          Returns number of neighbors that are up.
 boolean directed()
          Returns always true
 int fullDegree(int i)
          Returns number of neighbors that are either up or down.
 java.lang.Object getEdge(int i, int j)
          Returns null always
 java.util.Collection<java.lang.Integer> getNeighbours(int i)
          Returns those neighbors that are up.
 java.lang.Object getNode(int i)
          Returns Network.node[i]
 boolean isEdge(int i, int j)
          Returns true if there is a directed edge between node i and node j.
 boolean setEdge(int i, int j)
          Sets given edge.
 int size()
          Returns Network.size()
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

protocolID

public final int protocolID
The protocol ID that selects the Linkable protocol to convert to a graph.


wireDirected

public final boolean wireDirected
Tells if the graph should be wired in an undirected way. Method directed() returns true always, this affects only method setEdge(int, int): if false, then the opposite edge is set too.

Constructor Detail

OverlayGraph

public OverlayGraph(int protocolID)
Parameters:
protocolID - The protocol on which this adaptor is supposed to operate.

OverlayGraph

public OverlayGraph(int protocolID,
                    boolean wireDirected)
Parameters:
protocolID - The protocol on which this adaptor is supposed to operate.
wireDirected - specifies if setEdge(int, int) would wire the opposite edge too.
Method Detail

isEdge

public boolean isEdge(int i,
                      int j)
Description copied from interface: Graph
Returns true if there is a directed edge between node i and node j.

Specified by:
isEdge in interface Graph

getNeighbours

public java.util.Collection<java.lang.Integer> getNeighbours(int i)
Returns those neighbors that are up. If node i is not up, it returns an empty list.

Specified by:
getNeighbours in interface Graph

getNode

public java.lang.Object getNode(int i)
Returns Network.node[i]

Specified by:
getNode in interface Graph

getEdge

public java.lang.Object getEdge(int i,
                                int j)
Returns null always

Specified by:
getEdge in interface Graph

size

public int size()
Returns Network.size()

Specified by:
size in interface Graph

directed

public boolean directed()
Returns always true

Specified by:
directed in interface Graph

setEdge

public boolean setEdge(int i,
                       int j)
Sets given edge. In some cases this behaves strangely. Namely, when node i or j is not up, but is not dead (e.g. it can be down temporarily). In such situations the relevant link is made, but afterwards getEdge(i,j) will NOT return true, only when the fail state has changed back to OK.

Conceptually one can think of it as a successful operation which is immediately overruled by the dynamics of the underlying overlay network. Let's not forget that this class is an adaptor only.

The behaviour of this method is affected by parameter wireDirected. If it is false, then the opposite edge is set too.

Specified by:
setEdge in interface Graph

clearEdge

public boolean clearEdge(int i,
                         int j)
Not supported

Specified by:
clearEdge in interface Graph

degree

public int degree(int i)
Returns number of neighbors that are up. If node i is down, returns 0.

Specified by:
degree in interface Graph

fullDegree

public int fullDegree(int i)
Returns number of neighbors that are either up or down. If node i is down, returns 0.