Class Graph

java.lang.Object
  |
  +--Graph

public class Graph
extends java.lang.Object

This represents a mathematical object graph as lists of neighbors. Graph is a pair (V,E), where V is a set of vertices and V is a set of edges. Each edge e is a pair of vertices e = (v1 , v2)


Field Summary
static int MAXX
          Width of virtual Panel used to place vertices
static int MAXY
          Height of virtual Panel used to place vertices
 int moves
          A number of moves after initialization or last randomStates()
 
Constructor Summary
Graph()
          Creates an empty graph without vertices
Graph(Graph g, Vertex v)
          creates a new graph with the same structure as g, but with vertices of the same type as v
Graph(Vertex v, int n)
          Creates a tree with n vertices
Graph(Vertex v, int n, float p)
          Creates a random graph with n vertices, where each edge appears with probability p
Graph(Vertex v, int n1, int n2, float p)
          Creates a random bipartite graph with n=n1+n2 vertices, where each edge appears with probability p
 
Method Summary
 boolean addEdge(Vertex u, Vertex v)
          Tries to add an edge between two specified vertices.
 boolean addRandomEdge()
          Tries to add random edge to a graph.
 void addVertex(Vertex v, java.lang.String name)
          Add a vertex v to a graph as isolated one.
 void addVertex(Vertex v, java.lang.String name, float p)
          Add a vertex v to a graph with some edges.
 void addVertex(Vertex v, java.lang.String name, int d)
          Add a vertex v to a graph with degree d.
 int countEdges()
          Count number of edges in a graph.
 int delta()
          Count maximum degree in a graph.
 Vertex firstAvailable()
          First available vertex in a graph
 void getCoordinates(int maxX, int maxY)
          Gets Coordinates given by graphplace, to use this method graphplace must be available, and writing files must be allowed.
 java.util.Iterator iterator()
          Iterator over vertices of a graph.
 void paintStates(java.awt.Graphics graphics)
          Paint vertices in a graph using graphics
 void print()
          Print graph info.
 void printStates()
          Print vertices in a graph
 Vertex randomAvailable()
          Chooses one of the available vertices in a graph
 void randomCoordinates(int maxX, int maxY)
          Random coordinates of all vertices in a graph
 void randomStates()
          Set states of vertices in a random manner.
 void setFactors(int maxX, int maxY)
          Each vertex in a graph has its coordinates.
 void setRadius(int r)
          Each vertex in a graph is painted as a circle with radius in pixels.
 int size()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

MAXX

public static final int MAXX
Width of virtual Panel used to place vertices

See Also:
Vertex.getXCoordinate(), setFactors(int, int), Constant Field Values

MAXY

public static final int MAXY
Height of virtual Panel used to place vertices

See Also:
Vertex.getYCoordinate(), setFactors(int, int), Constant Field Values

moves

public int moves
A number of moves after initialization or last randomStates()

See Also:
randomStates(), Vertex.move(int)
Constructor Detail

Graph

public Graph()
Creates an empty graph without vertices


Graph

public Graph(Vertex v,
             int n)
Creates a tree with n vertices


Graph

public Graph(Graph g,
             Vertex v)
creates a new graph with the same structure as g, but with vertices of the same type as v


Graph

public Graph(Vertex v,
             int n,
             float p)
Creates a random graph with n vertices, where each edge appears with probability p


Graph

public Graph(Vertex v,
             int n1,
             int n2,
             float p)
Creates a random bipartite graph with n=n1+n2 vertices, where each edge appears with probability p

Method Detail

addVertex

public void addVertex(Vertex v,
                      java.lang.String name)
Add a vertex v to a graph as isolated one.


addVertex

public void addVertex(Vertex v,
                      java.lang.String name,
                      int d)
Add a vertex v to a graph with degree d. If d is greater then actual number of vertices then the new vertex will be connected with each one.


addVertex

public void addVertex(Vertex v,
                      java.lang.String name,
                      float p)
Add a vertex v to a graph with some edges. Vertex v is connected to each other vertex with probability p


size

public int size()
Returns:
number of vertices in a graph

addEdge

public boolean addEdge(Vertex u,
                       Vertex v)
Tries to add an edge between two specified vertices.

Returns:
true when succeed, false other way.

addRandomEdge

public boolean addRandomEdge()
Tries to add random edge to a graph.

Returns:
true when succeed, false other way

print

public void print()
Print graph info.

See Also:
Vertex.print()

delta

public int delta()
Count maximum degree in a graph.

Returns:
maximum degree in a graph.

countEdges

public int countEdges()
Count number of edges in a graph.

Returns:
number of edges in a graph.

setRadius

public void setRadius(int r)
Each vertex in a graph is painted as a circle with radius in pixels. This method sets radius for all vertices equal to r. parameter r is a radius of Vertices in pixels.

See Also:
Vertex.paintState(java.awt.Graphics), Vertex.setRadius(int), Vertex.getRadius()

firstAvailable

public Vertex firstAvailable()
First available vertex in a graph

Returns:
first available vertex according to iterator over vertices, or null when all agree.
See Also:
iterator(), Vertex.agree()

randomAvailable

public Vertex randomAvailable()
Chooses one of the available vertices in a graph

Returns:
available vertex or null when all agree
See Also:
Vertex.agree()

randomStates

public void randomStates()
Set states of vertices in a random manner.

See Also:
Vertex.randomState(java.util.Random)

printStates

public void printStates()
Print vertices in a graph

See Also:
Vertex.printState()

paintStates

public void paintStates(java.awt.Graphics graphics)
Paint vertices in a graph using graphics

See Also:
Vertex.paintState(java.awt.Graphics)

iterator

public java.util.Iterator iterator()
Iterator over vertices of a graph.


setFactors

public void setFactors(int maxX,
                       int maxY)
Each vertex in a graph has its coordinates. To paint a vertex in a proper place this coordinates must be adjusted to actual Panel size. This is done by setting xFactor and yFactor in each vertex.


getCoordinates

public void getCoordinates(int maxX,
                           int maxY)
Gets Coordinates given by graphplace, to use this method graphplace must be available, and writing files must be allowed.


randomCoordinates

public void randomCoordinates(int maxX,
                              int maxY)
Random coordinates of all vertices in a graph