import java.awt.Dimension;
import java.util.ArrayList;
import javax.swing.JTable;
/*
* Created on 03.04.2006
*
* To change the template for this generated file go to
* Window>Preferences>Java>Code Generation>Code and Comments
*/
/**
*
*
* To change the template for this generated type comment go to
*
* Window>Preferences>Java>Code Generation>Code and Comments
*/
public class AG3
{
private int n, j = 0;
private double werte;
private double[][] mat, mat2;
private JTable jt;
private boolean zusammenhaengend, uebergabe;
private int[] anzahl;
public AG3(int wert, JTable tab, boolean uebergabe)
{
n = wert;
jt =null;
jt = tab;
mat = new double[n][n];
mat2 = new double[n][n];
anzahl = new int[n];
this.uebergabe = uebergabe;
}
public AG3()
{
n = 4;
mat = new double[n][n];
}
public double ausgabe()
{
return werte;
}
public boolean berechneGraphZusammenhaengend()
{
kanten();
zusammenhaengend=true;
for (int i = 0;i < n;i++)
if (anzahl[i] == 0)
zusammenhaengend=false;
return zusammenhaengend;
}
public void kanten()
{
for(int i = 0;i < n;i++)
{
anzahl[i]=0;
for(int j = 0;j < n;j++)
if(Integer.parseInt(jt.getValueAt(i,j).toString()) > 0)
anzahl[i]++;
}
}
public void speichern() throws Exception
{
if(uebergabe == false)
{
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
{
mat[i][j] = Double.parseDouble(jt.getValueAt(i,j).toString());
if(i == j)
mat2[i][j] = anzahl[i];
}
}
else
{
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
{
if(Double.parseDouble(jt.getValueAt(i,j).toString()) >= 1)
mat[i][j] = 1;
if(i == j)
mat2[i][j] = anzahl[i];
}
}
subtraktion();
if(!berechneGraphZusammenhaengend())
throw new Exception("Graph ist nicht zusammenhaengend!");
nxN(mat);
}
public void subtraktion()
{
for(int i = 0; i < n; i++)
for(int j = 0; j < n; j++)
mat[i][j] = mat2[i][j] - mat[i][j];
}
public double nxN(double[][] matrix)
{
int n2 = matrix.length;
double wert = 0;
switch (n2)
{
case 3: wert = this.dreixDrei(matrix); break;
default: wert = this.entwickeln(matrix); j++; break;
}
return wert;
}
public double dreixDrei(double[][] matrix)
{
double wert1 = matrix[0][0] * matrix[1][1] * matrix[2][2];
double wert2 = matrix[0][1] * matrix[1][2] * matrix[2][0];
double wert3 = matrix[0][2] * matrix[1][0] * matrix[2][1];
double wert4 = matrix[0][2] * matrix[1][1] * matrix[2][0];
double wert5 = matrix[0][0] * matrix[1][2] * matrix[2][1];
double wert6 = matrix[0][1] * matrix[1][0] * matrix[2][2];
double gesamt = wert1 + wert2 + wert3 -wert4 -wert5 -wert6;
werte = Math.abs(gesamt);
return gesamt;
}
public double entwickeln(double[][] matrix)
{
double wert = 0;
double zw = this.nxN(this.unterMatrix(matrix, 0, l));
wert += Math.pow(-1, 0+l) * matrix[0][l] * Math.abs(zw);
System.out.println(wert + " " + matrix[0][l] + " " + Math.abs(zw) + " " + matrix.length);
return wert;
}
public double[][] unterMatrix(double[][] matrix, int zeile, int spalte)
{
int n = matrix.length;
double[][] umatrix = new double[n-1][n-1];
int r = 0;
int s = 0;
for (int i=0; i<n; i++)
{
for (int k=0; k<n; k++)
if (i != zeile && k != spalte)
{
umatrix[r][s] = (int) matrix[i][k];
if (s+1 < n-1)
s++;
}
if (i != zeile && r+1 < n-1)
{
s=0;
r++;
}
}
return umatrix;
}
}