#include <iostream.h>
#include <limits.h>
#include <LINK/basic/Matrix.h>
#include <LINK/algorithm/Algorithms.h>
#include <LINK/graph/Attribute.h>
#include <LINK/graph/Graph.h>

double Radius(Graph* g, char *gv)
{
	double radius = (double)INT_MAX;
	if (!g || !g->simpleQ())
		return radius;

	Vertex **gverts = g->vertexStart();
	Matrix<double> sh_paths = FloydWarshall(g);
	int i, j;
	double row_max; 
	int max_i, max_j, min_max_i, min_max_j;
	for(i = 0; i < sh_paths.numRows(); i++) {
		row_max = (double)INT_MIN;
		for(j = 0; j < sh_paths.numCols(); j++) {
			if(sh_paths(i,j) > row_max) {
				row_max = sh_paths(i,j);	
				max_i = i;
				max_j = j;
			}
		}
		if(row_max < radius) {
			radius = row_max;
			min_max_i = max_i;
			min_max_j = max_j;
		}
	}
	Vertex *v1 = gverts[min_max_i];
	Vertex *v2 = gverts[min_max_j];
	Dijkstra(g, "", v1);
	Set<Vertex*> verts = g->vertices();
	Iterator<Vertex*> get_vert(&verts);
	Vertex* vert;
	while(get_vert(vert)) 
		setAttribute((GraphObject*)vert, "type", 0);  //For STk to find.
		
	setAttribute((GraphObject*) v2, "type", 1);  // For STk to find.
						   // "pred" attributes will
						   // trace out a radius path

	return radius;
}
