Compare commits

...

4 Commits
Dev ... Testing

Author SHA1 Message Date
2077955eb3 Add Graph 2022-06-17 19:04:22 +02:00
0a11547e66 adjacent matrix can be calculated 2022-06-17 16:43:13 +02:00
b3a9cad35d New Matrix 2022-06-17 13:00:20 +02:00
a42afb9642 Testing 2022-06-17 12:22:17 +02:00
3 changed files with 129 additions and 19 deletions

1
Graphen_Projekt.json Normal file
View File

@ -0,0 +1 @@
[[{"x":223,"y":338,"id":0,"art":false},{"x":353,"y":344,"id":1,"art":true},{"x":222,"y":222,"id":2,"art":false},{"x":361,"y":222,"id":3,"art":false},{"x":361,"y":476,"id":4,"art":false}],[{"n1":{"x":353,"y":344,"id":1,"art":true},"n2":{"x":223,"y":338,"id":0,"art":false},"bridge":false},{"n1":{"x":222,"y":222,"id":2,"art":false},"n2":{"x":223,"y":338,"id":0,"art":false},"bridge":false},{"n1":{"x":361,"y":222,"id":3,"art":false},"n2":{"x":222,"y":222,"id":2,"art":false},"bridge":false},{"n1":{"x":353,"y":344,"id":1,"art":true},"n2":{"x":361,"y":222,"id":3,"art":false},"bridge":false},{"n1":{"x":361,"y":222,"id":3,"art":false},"n2":{"x":223,"y":338,"id":0,"art":false},"bridge":false},{"n1":{"x":361,"y":476,"id":4,"art":false},"n2":{"x":353,"y":344,"id":1,"art":true},"bridge":true}]]

View File

@ -7,31 +7,128 @@ import java.io.IOException;
import java.util.ArrayList;
public class Graph {
private ArrayList<Graph> values;
private static int[][] adjacent = { {0,1,1,1,0},
{1,0,0,1,1},
{1,0,0,1,0},
{1,1,1,0,0},
{0,1,0,0,0} };
private static int[][] distance = { {0,1,1,1,2},
{1,0,2,1,1},
{1,2,0,1,3},
{1,1,1,0,2},
{2,1,3,2,0} };
private static int[] eccentricities = {2,2,3,2,3}; // max Number from each individual Array in the distance Array
private static int diameter = 3; // max Number in eccentricities
private static int radius = 2; // half of the diameter
private static int center[] = {1,2,4}; // Every Knoten were eccentricities == radius
private static int component[][] = { {1,2,3,4}, {2,5} };
private static int[] articulations = {2};
private static int[][] bridges = {{2,5}};
public Graph() {
values = new ArrayList<Graph>();
}
public boolean receiveValues() throws GraphException {
try (BufferedReader br = new BufferedReader(new FileReader(""))) { // filePath von application.RootBorderPane.importCSV()
String zeile;
String[] zeilenTeile;
String sep = ";"; // erwartetes Trennzeichen in der csv-Datei
zeile = br.readLine(); // wenn keine Zeile gefunden, dann return null
while (zeile != null) {
zeilenTeile = zeile.trim().split(sep);
public static int[][] calculateAdjacent2(int[][] adjacent) {
int[][] adjacent2 = new int[adjacent.length][adjacent.length];
for(int row = 0; row < adjacent.length; row++) {
for(int col = 0; col < adjacent.length; col++) {
adjacent2[row][col] = 0; // Initialize Array
for(int pos = 0; pos < adjacent.length; pos++) { // Position in Array
adjacent2[row][col] += adjacent[row][pos] * adjacent[pos][col]; // row * col
}
}
} catch (FileNotFoundException e) {
throw new GraphException("Datei-Fehler bei receiveValues(): " + e.getMessage());
} catch (IOException e) {
throw new GraphException("Datei-Fehler bei receiveValues(): " + e.getMessage());
}
return false;
return adjacent2;
}
public static void getAdjacent2() {
int[][] adjacent2 = calculateAdjacent2(adjacent);
System.out.println("A²(G):");
if (adjacent.length > 0)
{
for (int i = 0; i < adjacent.length; i++) {
for (int j = 0; j < adjacent.length; j++) {
System.out.print(adjacent2[i][j] + ", ");
}
System.out.println("\n");
}
}
else
{
System.out.println("Empty Array");
}
}
public static int[][] calculateAdjacent3(int[][] adjacent, int[][] adjacent2) {
int[][] adjacent3 = new int[adjacent.length][adjacent.length];
for(int row = 0; row < adjacent.length; row++) {
for(int col = 0; col < adjacent.length; col++) {
for(int pos = 0; pos < adjacent.length; pos++) {
adjacent3[row][col] += adjacent2[pos][col] * adjacent[row][pos];
}
}
}
return adjacent3;
}
public static void getAdjacent3() {
int[][] adjacent3 = calculateAdjacent3(adjacent, calculateAdjacent2(adjacent));
System.out.println("A³(G):");
if (adjacent.length > 0)
{
for (int i = 0; i < adjacent.length; i++) {
for (int j = 0; j < adjacent.length; j++) {
System.out.print(adjacent3[i][j] + ", ");
}
System.out.println("\n");
}
}
else
{
System.out.println("Empty Array");
}
}
// public boolean receiveValues() throws GraphException {
// try (BufferedReader br = new BufferedReader(new FileReader(""))) { // filePath von application.RootBorderPane.importCSV()
// String zeile;
// String[] zeilenTeile;
// String sep = ";"; // erwartetes Trennzeichen in der csv-Datei
// int rowLength = 0;
//
//
// zeile = br.readLine(); // wenn keine Zeile gefunden, dann return null
//
// while(zeile != null) {
// rowLength++;
// }
//
// } catch (FileNotFoundException e) {
// throw new GraphException("Datei-Fehler bei receiveValues(): " + e.getMessage());
// } catch (IOException e) {
// throw new GraphException("Datei-Fehler bei receiveValues(): " + e.getMessage());
// }
// return false;
// }
}

12
src/test/GraphTest.java Normal file
View File

@ -0,0 +1,12 @@
package test;
import model.Graph;
public class GraphTest {
public static void main(String[] args) {
Graph.getAdjacent3();
}
}