edu.stanford.multiagent.gamer.graphs
Class Graph

java.lang.Object
  |
  +--edu.stanford.multiagent.gamer.ParameterizedObject
        |
        +--edu.stanford.multiagent.gamer.graphs.Graph
Direct Known Subclasses:
ALGraph, AMGraph

public abstract class Graph
extends ParameterizedObject

An abstract base class for graph implementations. Note that currently nodes are assumed to be consecutive, starting at 0, and that this class must be updated, if node removal is desired.


Field Summary
protected  int nEdges
           
protected  int nNodes
           
protected  java.util.HashMap nodeData
           
protected static Parameters.ParamInfo pReflexEdges
           
protected static Parameters.ParamInfo pSymEdges
           
 
Fields inherited from class edu.stanford.multiagent.gamer.ParameterizedObject
parameters
 
Constructor Summary
protected Graph()
          Constructor.
 
Method Summary
abstract  void addEdge(int s, int t)
          Adds a new edge to the graph between nodes s and t.
abstract  void addEdge(int s, int t, java.lang.Object data)
          Adds a new edge to the graph between nodes s and t and sets the edge data for this edge.
abstract  void addNode()
          Adds a new node to the graph.
abstract  boolean areNeighbours(int from, int to)
          Checks if two nodes are neighbours, i.e.
abstract  edu.stanford.multiagent.gamer.graphs.Edge getEdge(int s, int t)
          Gets an Edge.
abstract  java.util.Iterator getEdges(int from)
          Returns an iterator over the outgoing edges from a node.
protected abstract  java.lang.String getGraphHelp()
          Returns a help information string about the particular graph, does not include parameter information.
 java.lang.String getHelp()
          Returns the help string with information about the graph class and the parameters taken by the class.
 int getNEdges()
          Returns the number of edges in the graph.
abstract  java.util.Iterator getNeighbours(int from)
          Returns an iterator over a node's neighbours.
 int getNNodes()
          Returns the number of vertices in the graph.
 java.lang.Object getNodeData(int n)
          Returns any data that is being stored at a node.
abstract  boolean hasSymEdges()
          Returns true if the graph is symmetric, i.e.
 void initialize()
          Initializes the graph structure using preset parameter values.
abstract  boolean reflexEdgesOk()
          Returns true if reflexive edges are allowed in the graph.
abstract  void removeEdge(edu.stanford.multiagent.gamer.graphs.Edge e)
          Removes an edge from the graph.
abstract  void removeEdge(int s, int t)
          Removes an edge from the graph.
abstract  void setEdgeData(int s, int t, java.lang.Object data)
          Sets the edge data for an already existing edge.
 void setNodeData(int n, java.lang.Object data)
          Sets node data.
 
Methods inherited from class edu.stanford.multiagent.gamer.ParameterizedObject
checkParameters, doGenerate, getBooleanParameter, getDescription, getDoubleParameter, getLongParameter, getParamDescription, getParameter, getParameters, getStringParameter, randomizeParameters, setParameter, setParameter, setParameters, setParameters
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

nEdges

protected int nEdges

nNodes

protected int nNodes

nodeData

protected java.util.HashMap nodeData

pSymEdges

protected static Parameters.ParamInfo pSymEdges

pReflexEdges

protected static Parameters.ParamInfo pReflexEdges
Constructor Detail

Graph

protected Graph()
         throws java.lang.Exception
Constructor. Currently only one version is available and it does not take parameters.

Method Detail

initialize

public void initialize()
                throws java.lang.Exception
Initializes the graph structure using preset parameter values.

Overrides:
initialize in class ParameterizedObject
Throws:
java.lang.Exception

getHelp

public java.lang.String getHelp()
Returns the help string with information about the graph class and the parameters taken by the class.

Specified by:
getHelp in class ParameterizedObject

getGraphHelp

protected abstract java.lang.String getGraphHelp()
Returns a help information string about the particular graph, does not include parameter information.


getNEdges

public int getNEdges()
Returns the number of edges in the graph.


getNNodes

public int getNNodes()
Returns the number of vertices in the graph.


getNodeData

public java.lang.Object getNodeData(int n)
Returns any data that is being stored at a node.

Parameters:
n - the index of the node

setNodeData

public void setNodeData(int n,
                        java.lang.Object data)
Sets node data.

Parameters:
n - the index of the node
data - the data to be stored at the node

addNode

public abstract void addNode()
Adds a new node to the graph.


addEdge

public abstract void addEdge(int s,
                             int t)
Adds a new edge to the graph between nodes s and t.

Parameters:
s - index of first node
t - index of second node

addEdge

public abstract void addEdge(int s,
                             int t,
                             java.lang.Object data)
Adds a new edge to the graph between nodes s and t and sets the edge data for this edge.

Parameters:
s - index of first node
t - index of second node
data - data to be stored on this edge

setEdgeData

public abstract void setEdgeData(int s,
                                 int t,
                                 java.lang.Object data)
Sets the edge data for an already existing edge.

Parameters:
s - index of the first node on the edge
t - index of the second node on the egde
data - data to be stored on the edge

removeEdge

public abstract void removeEdge(int s,
                                int t)
Removes an edge from the graph.

Parameters:
s - index of the first node on the edge
t - index of the second node on the edge

removeEdge

public abstract void removeEdge(edu.stanford.multiagent.gamer.graphs.Edge e)
Removes an edge from the graph.

Parameters:
e - the edge to be removed

getEdge

public abstract edu.stanford.multiagent.gamer.graphs.Edge getEdge(int s,
                                                                  int t)
Gets an Edge.

Parameters:
s - index of the first node on the edge
t - index of the second node on the edge

areNeighbours

public abstract boolean areNeighbours(int from,
                                      int to)
Checks if two nodes are neighbours, i.e. if there exists an edge from the first node to the second. Note that the order of nodes specified does matter for directed graphs.

Parameters:
from - index of the node at which the edge begins
to - index of the node at which the egde ends

getNeighbours

public abstract java.util.Iterator getNeighbours(int from)
Returns an iterator over a node's neighbours.

Parameters:
from - index of the node

getEdges

public abstract java.util.Iterator getEdges(int from)
Returns an iterator over the outgoing edges from a node.

Parameters:
from - index of the node

hasSymEdges

public abstract boolean hasSymEdges()
Returns true if the graph is symmetric, i.e. if it must be the case that for every edge from node a to node b there also exists an edge from node b to node a.


reflexEdgesOk

public abstract boolean reflexEdgesOk()
Returns true if reflexive edges are allowed in the graph.