kth.csc.inda
Interface Graph

All Known Implementing Classes:
HashGraph, MatrixGraph

public interface Graph

A graph with a fixed number of vertices. The vertices are numbered from 0 to n-1, were n is the number of vertices in the graph. Edges may be added or removed from the graph. An edge may have an optional non-negative cost.

Version:
2013-01-01
Author:
Stefan Nilsson

Field Summary
static int NO_COST
          An edge with no cost has this value.
 
Method Summary
 void add(int from, int to)
          Inserts a directed edge.
 void add(int from, int to, int c)
          Inserts an edge with edge cost c.
 void addBi(int v, int w)
          Inserts two edges between v and w.
 void addBi(int v, int w, int c)
          Inserts edges with edge cost c between v and w.
 int cost(int v, int w)
          Returns the edge cost if v and w are adjacent and an edge cost has been assigned, NO_COST otherwise.
 int degree(int v)
          Returns the degree of vertex v.
 boolean hasEdge(int v, int w)
          Returns true if there is an edge from v to w.
 VertexIterator neighbors(int v)
          Returns an iterator of vertices adjacent to v.
 int numEdges()
          Returns the number of edges in this graph.
 int numVertices()
          Returns the number of vertices in this graph.
 void remove(int from, int to)
          Removes the edge.
 void removeBi(int v, int w)
          Removes the edges between v and w.
 

Field Detail

NO_COST

static final int NO_COST
An edge with no cost has this value.

See Also:
Constant Field Values
Method Detail

numVertices

int numVertices()
Returns the number of vertices in this graph.

Returns:
the number of vertices in this graph

numEdges

int numEdges()
Returns the number of edges in this graph.

Returns:
the number of edges in this graph

degree

int degree(int v)
           throws java.lang.IllegalArgumentException
Returns the degree of vertex v.

Parameters:
v - vertex
Returns:
the degree of vertex v
Throws:
java.lang.IllegalArgumentException - if v is out of range

neighbors

VertexIterator neighbors(int v)
                         throws java.lang.IllegalArgumentException
Returns an iterator of vertices adjacent to v.

Parameters:
v - vertex
Returns:
an iterator of vertices adjacent to v
Throws:
java.lang.IllegalArgumentException - if v is out of range

hasEdge

boolean hasEdge(int v,
                int w)
                throws java.lang.IllegalArgumentException
Returns true if there is an edge from v to w.

Parameters:
v - vertex
w - vertex
Returns:
true if there is an edge from v to w.
Throws:
java.lang.IllegalArgumentException - if v or w are out of range

cost

int cost(int v,
         int w)
         throws java.lang.IllegalArgumentException
Returns the edge cost if v and w are adjacent and an edge cost has been assigned, NO_COST otherwise.

Parameters:
v - vertex
w - vertex
Returns:
edge cost if available, NO_COST otherwise
Throws:
java.lang.IllegalArgumentException - if v or w are out of range

add

void add(int from,
         int to)
         throws java.lang.IllegalArgumentException
Inserts a directed edge. (No edge cost is assigned.)

Parameters:
from - vertex
to - vertex
Throws:
java.lang.IllegalArgumentException - if from or to are out of range

add

void add(int from,
         int to,
         int c)
         throws java.lang.IllegalArgumentException
Inserts an edge with edge cost c.

Parameters:
c - edge cost, c >= 0
from - vertex
to - vertex
Throws:
java.lang.IllegalArgumentException - if from or to are out of range
java.lang.IllegalArgumentException - if c < 0

addBi

void addBi(int v,
           int w)
           throws java.lang.IllegalArgumentException
Inserts two edges between v and w. (No edge cost is assigned.)

Parameters:
v - vertex
w - vertex
Throws:
java.lang.IllegalArgumentException - if v or w are out of range

addBi

void addBi(int v,
           int w,
           int c)
           throws java.lang.IllegalArgumentException
Inserts edges with edge cost c between v and w.

Parameters:
c - edge cost, c >= 0
v - vertex
w - vertex
Throws:
java.lang.IllegalArgumentException - if v or w are out of range
java.lang.IllegalArgumentException - if c < 0

remove

void remove(int from,
            int to)
            throws java.lang.IllegalArgumentException
Removes the edge.

Parameters:
from - vertex
to - vertex
Throws:
java.lang.IllegalArgumentException - if from or to are out of range

removeBi

void removeBi(int v,
              int w)
              throws java.lang.IllegalArgumentException
Removes the edges between v and w.

Parameters:
v - vertex
w - vertex
Throws:
java.lang.IllegalArgumentException - if v or w are out of range