/*
* DistanceGeometry.java
*
* Created on July 12, 2007, 3:55 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package medusa.georgios.Distance_Geometry;
import java.util.ArrayList;
import medusa.georgios.vecmathpackage.Point3d;
/**
*
* @author Georgios
*/
public class DistanceGeometry {
/** Creates a new instance of DistanceGeometry */
public DistanceGeometry() {
}
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
double[][] m = new double[4][4];
for (int i = 0; i < m.length; i++) {
for (int j = i; j < m.length; j++) {
m[i][j]=m[j][i]=Math.random();
if(i==j)m[i][j]=0;
}
}
// System.out.println("Distance Matrix\n");
// for (int i = 0; i < m.length; i++) {
// for (int j = 0; j < m.length; j++) {
// System.out.print(m[i][j]+"\t");
// }System.out.println("");
// }
DistanceGeometry d = new DistanceGeometry();
System.out.println("");
d.distribute_nodes(m);
}
public ArrayList distribute_nodes(double[][] distance_matrix )
{
ArrayList points = new ArrayList();
double[][] metric_matrix = new double[distance_matrix.length][distance_matrix.length];
Distance_Geometry_Matrix Metric_matrix;
// System.out.println("Distance Matrix\n");
// for (int i = 0; i < distance_matrix.length; i++) {
// for (int j = 0; j < distance_matrix.length; j++) {
// System.out.print(distance_matrix[i][j]+"\t");
// }System.out.println("");
// }
ArrayList nums = new ArrayList();
// System.out.println("");
for (int i = 0; i < distance_matrix.length; i++) {
double sum1=0;
double sum2=0;
for (int j = 0; j < distance_matrix.length; j++)
sum1+=Math.pow(distance_matrix[i][j],2);
sum1=sum1/distance_matrix.length;
sum2=0;
for (int j = 1; j < distance_matrix.length; j++)
for (int k = 0; k < j; k++)
sum2+=Math.pow(distance_matrix[j][k],2);
sum2=sum2/Math.pow(distance_matrix.length,2);
double substraction=sum1-sum2;
if(substraction<0)substraction=0;
// System.out.println(substraction);
double result=Math.sqrt(substraction);
nums.add(result);
}
for (int i = 0; i < distance_matrix.length; i++)
for (int j = i; j < distance_matrix.length; j++)
metric_matrix[j][i]=metric_matrix[i][j]=(Math.pow(nums.get(i),2)+Math.pow(nums.get(j),2)-Math.pow(distance_matrix[i][j],2))/2;
Metric_matrix= new Distance_Geometry_Matrix(metric_matrix);
// System.out.println("metric_matrix\n");
// for (int j = 0; j < distance_matrix.length; j++) {
// for (int k = 0; k < distance_matrix.length; k++) {
// System.out.print(metric_matrix[j][k] +"\t");
// }System.out.println("");
// }
Distance_Geometry_Matrix point_matrix= new Distance_Geometry_Matrix(Metric_matrix.eig().getV().getArray());
for (int i = 0; i < distance_matrix.length; i++)
{Point3d p = new Point3d();
p.x=point_matrix.get(i,distance_matrix.length-1);
p.y=point_matrix.get(i,distance_matrix.length-2);
p.z=point_matrix.get(i,distance_matrix.length-3);
points.add(p);
}
return points;
}
}
Ads help maintain this website.