Class Vertex

java.lang.Object
  |
  +--Vertex
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
ColoringVertex, EdgeColoringVertex, MDSVertex, MISVertex

public abstract class Vertex
extends java.lang.Object
implements java.lang.Cloneable

This class has been designed to test self-stabilizing algorithms. In a model of self-stabilization each vertex has its state. Having this state and information about states of its neighbors vertex can determine(agree()) if it should change its state(is enabled) or not. In first case vertex makes a move(change its state move(int)), in second stays without changing state. We consider a set of vertices connected in some way with edges. Such a structure we call a (Graph). To show this structure to the user we have to place vertices somehow. Each vertex has its coordinates in a virtual Panel. Dimension of this rectangular panel is given by points (0,0) (Graph.MAXX, Graph.MAXY). Of course when program runs we have to adjust this coordinates to screen Panel dimensions (Graph.setFactors(int, int)).


Field Summary
protected  java.util.HashSet neighbors
          All neighbors of a vertex in a graph
 float xFactor
          This factor allows to adjust screen Vertex x coordinate .
 float yFactor
          This factor allows to adjust screen Vertex y coordinate .
 
Constructor Summary
Vertex()
           
Vertex(java.lang.String name)
           
Vertex(java.lang.String name, int radius)
           
 
Method Summary
 boolean addEdge(Vertex u)
           
abstract  boolean agree()
          This method should determine if vertex state agrees to rules of a specified algorithm
 java.lang.Object clone()
          This method works properly only with vertices without edges.
 int deg()
          Return vertex degree in a graph
 double distance(int x, int y)
          Count a distance between given point (x,y) and Vertex coordinates (getXCoordinate(),getYCoordinate) in screen pixels.
 java.lang.String getInfo()
          returns a String describing Vertex
 java.lang.String getName()
           
 int getRadius()
          Gets radius in pixels.
abstract  java.lang.String getStateInfo()
          This method should get a state info of a vertex.
 int getXCoordinate()
          Gets the x coordinate
 int getYCoordinate()
          Gets the y coordinate
 java.util.Iterator iterator()
          Iterator over the neighbors of a vertex.
abstract  void move(int info)
          This method should make a move assuming that vertex is enabled.
 void paintState(java.awt.Graphics graphics)
          This method should paint a vertex according to its state, however in Vertex class it just paint circles with radius in red.
 void print()
          Print vertex info.
abstract  void printState()
          This method should print a state of a vertex.
abstract  void randomState(java.util.Random r)
          This method should random a state of a vertex.
 void setCoordinates(int x, int y)
          Sets vertex coordinate a
 void setFactors(float x, float y)
          Sets vertex factors
 void setName(java.lang.String name)
           
 void setRadius(int radius)
          Sets radius in pixels.
 void setXCoordinate(int x)
          Sets the x coordinate
 void setYCoordinate(int y)
          Sets the y coordinate
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

xFactor

public float xFactor
This factor allows to adjust screen Vertex x coordinate .

See Also:
Vertex

yFactor

public float yFactor
This factor allows to adjust screen Vertex y coordinate .

See Also:
Vertex

neighbors

protected java.util.HashSet neighbors
All neighbors of a vertex in a graph

Constructor Detail

Vertex

public Vertex()

Vertex

public Vertex(java.lang.String name)

Vertex

public Vertex(java.lang.String name,
              int radius)
Method Detail

setXCoordinate

public void setXCoordinate(int x)
Sets the x coordinate

Parameters:
x - coordinate in screen pixels
See Also:
Vertex

setYCoordinate

public void setYCoordinate(int y)
Sets the y coordinate

Parameters:
y - coordinate in screen pixels
See Also:
Vertex

setCoordinates

public void setCoordinates(int x,
                           int y)
Sets vertex coordinate a

Parameters:
x - X coordinates in screen pixels
y - Y coordinates in screen pixels
See Also:
Vertex

getXCoordinate

public int getXCoordinate()
Gets the x coordinate

Returns:
x coordinate in screen pixels
See Also:
Vertex

getYCoordinate

public int getYCoordinate()
Gets the y coordinate

Returns:
y coordinate in screen pixels
See Also:
Vertex

setRadius

public void setRadius(int radius)
Sets radius in pixels.

Parameters:
radius - length of radius in screen pixels
See Also:
Vertex

getRadius

public int getRadius()
Gets radius in pixels.

Returns:
radius length of radius in screen pixels
See Also:
Vertex

setFactors

public void setFactors(float x,
                       float y)
Sets vertex factors

Parameters:
x - X factor
y - Y factor
See Also:
Vertex

distance

public double distance(int x,
                       int y)
Count a distance between given point (x,y) and Vertex coordinates (getXCoordinate(),getYCoordinate) in screen pixels.

Returns:
distance between given point (x,y) and Vertex coordinates

clone

public java.lang.Object clone()
                       throws java.lang.CloneNotSupportedException
This method works properly only with vertices without edges. It is used when constructing a Graph

Overrides:
clone in class java.lang.Object
java.lang.CloneNotSupportedException

getInfo

public java.lang.String getInfo()
returns a String describing Vertex

See Also:
VertexInfoDialog

print

public void print()
Print vertex info.

See Also:
Graph.print()

getName

public java.lang.String getName()

setName

public void setName(java.lang.String name)

addEdge

public boolean addEdge(Vertex u)

deg

public int deg()
Return vertex degree in a graph

Returns:
vertex degree in a graph
See Also:
Graph.delta()

iterator

public java.util.Iterator iterator()
Iterator over the neighbors of a vertex.

Returns:
returns iterator over the neighbors of a vertex.

paintState

public void paintState(java.awt.Graphics graphics)
This method should paint a vertex according to its state, however in Vertex class it just paint circles with radius in red. and should be rather overridden in subclasses.

See Also:
setRadius(int), Graph.paintStates(java.awt.Graphics)

agree

public abstract boolean agree()
This method should determine if vertex state agrees to rules of a specified algorithm

Returns:
true means that vertex agree, false other way vertex is available.

move

public abstract void move(int info)
This method should make a move assuming that vertex is enabled.


randomState

public abstract void randomState(java.util.Random r)
This method should random a state of a vertex.


printState

public abstract void printState()
This method should print a state of a vertex.


getStateInfo

public abstract java.lang.String getStateInfo()
This method should get a state info of a vertex.

Returns:
String describing a vertex state.
See Also:
VertexInfoDialog