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;0;1;0;1;1;0;0;0;1;0;0;1;1;0;1;0;1;0;0;0;1;0;1;0 +0;0;0;1;0;0;0;1;0;0;1;1;0;1;0;1;0;0;1;0;1;1;1;0;0;0;0;0;1;0;1;1;0;0;1;1;0;0;0;1;0;1;1;1;0;1;1;0;0;1 +1;0;0;0;0;1;0;1;0;0;0;0;0;0;1;1;1;1;1;1;1;0;0;0;1;1;1;0;1;1;1;0;1;0;1;0;1;0;1;1;1;1;0;1;0;1;0;0;0;0 diff --git a/csv/5n.csv b/csv/5n.csv new file mode 100644 index 0000000..f5122d0 --- /dev/null +++ b/csv/5n.csv @@ -0,0 +1,7 @@ +0;0;0;0;0;0;0 +0;0;0;0;1;0;0 +0;0;0;0;0;0;0 +0;0;0;0;1;0;0 +0;1;0;1;0;0;0 +0;0;0;0;0;0;1 +0;0;0;0;0;1;0 diff --git a/csv/art-brck.csv b/csv/art-brck.csv new file mode 100644 index 0000000..4863ae8 --- /dev/null +++ b/csv/art-brck.csv @@ -0,0 +1,5 @@ +0;0;1;1;0 +0;0;1;1;0 +1;1;0;1;0 +1;1;1;0;1 +0;0;0;1;0 \ No newline at end of file diff --git a/csv/empty.csv b/csv/empty.csv new file mode 100644 index 0000000..398c1d8 --- /dev/null +++ b/csv/empty.csv @@ -0,0 +1,5 @@ +0;0;0;0;0 +0;0;0;0;0 +0;0;0;0;0 +0;0;0;0;0 +0;0;0;0;0 \ No newline at end of file diff --git a/csv/graph.csv b/csv/graph.csv new file mode 100644 index 0000000..9ed6b1a --- /dev/null +++ b/csv/graph.csv @@ -0,0 +1,5 @@ +0;0;1;0;0 +0;0;1;0;0 +1;1;0;1;1 +0;0;1;0;1 +0;0;1;1;0 diff --git a/src/Graph.java b/src/Graph.java index fef94a6..e71ff6d 100644 --- a/src/Graph.java +++ b/src/Graph.java @@ -86,6 +86,7 @@ public class Graph { public void calculateExzentrizitäten() { exzentrizitäten = new ArrayList<>(1); + connected = true; for(int rowIndex = 0; rowIndex < distanzMatrix.getRowLength(); rowIndex++) { int exzentrizität = 0; @@ -110,7 +111,6 @@ public class Graph { radius = Integer.MAX_VALUE; diameter = -1; - connected = true; centre = new ArrayList<>(1); for(int rowIndex = 0; rowIndex < exzentrizitäten.size(); rowIndex++) { diff --git a/src/Matrix.java b/src/Matrix.java index c62b760..d891d09 100644 --- a/src/Matrix.java +++ b/src/Matrix.java @@ -1,7 +1,10 @@ import java.io.BufferedReader; import java.io.IOException; +import java.util.Random; import java.io.FileReader; import java.io.FileNotFoundException; +import java.io.BufferedWriter; +import java.io.FileWriter; public class Matrix { private int[][] matrix; @@ -10,6 +13,19 @@ public class Matrix { public static void main(String[] args) {} + public Matrix(int rowLength, int columnLength, boolean random) { + if(!random) { + matrix = new int[rowLength][columnLength]; + this.rowLength = rowLength; + this.columnLength = columnLength; + return; + } + matrix = new int[rowLength][columnLength]; + this.rowLength = rowLength; + this.columnLength = columnLength; + randomAdjazenzMatrix(); + } + public Matrix(String file) { readCSV(file); } @@ -79,6 +95,49 @@ public class Matrix { } } + public int[][] clone() { + int[][] clone = new int[rowLength][columnLength]; + + for(int columnIndex=0; columnIndex < columnLength; columnIndex++) { + for(int rowIndex=0; rowIndex < rowLength; rowIndex++) { + clone[rowIndex][columnIndex] = matrix[rowIndex][columnIndex]; + } + } + + return clone; + } + + public void randomAdjazenzMatrix() { + Random r = new Random(); + for(int columnIndex=0; columnIndex < columnLength; columnIndex++) { + for(int rowIndex=0; rowIndex < rowLength; rowIndex++) { + if(rowIndex == columnIndex) { + continue; + } + matrix[rowIndex][columnIndex] = r.nextInt(2); + } + } + } + + public void WriteToCsv(String filename) { + String s = ""; + + try (BufferedWriter bw = new BufferedWriter(new FileWriter(filename))) { + for(int columnIndex=0; columnIndex < columnLength; columnIndex++) { + s = ""; + for(int rowIndex=0; rowIndex < rowLength; rowIndex++) { + s += matrix[columnIndex][rowIndex]; + if(rowIndex < rowLength - 1) { + s += ";"; + } + } + bw.write(s + "\n"); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + public String toString() { String s = ""; for(int columnIndex=0; columnIndex < columnLength; columnIndex++) { diff --git a/src/TestGraph.java b/src/TestGraph.java index 0fa9a36..8d295b4 100644 --- a/src/TestGraph.java +++ b/src/TestGraph.java @@ -1,6 +1,53 @@ public class TestGraph { public static void main(String[] args) { - Graph g = new Graph(""); + // test1(); + // test2(); + // test3(); + // test4(); + test5(); + } + + static String pathToProgramRoot = "/home/rene/projects/Java/graphprogram"; + + + /* + * This is a small not connected graph with articulations and bridges + */ + public static void test1() { + Graph g = new Graph(pathToProgramRoot + "/csv/5n.csv"); + System.out.println(g); + } + + + /* + * Bigger graph with bridges and many articulations + */ + public static void test2() { + Graph g = new Graph(pathToProgramRoot + "/csv/24n.csv"); + System.out.println(g); + } + + /* + * Graph where each vetex is not connected to anything + */ + public static void test3() { + Graph g = new Graph(pathToProgramRoot + "/csv/empty.csv"); + System.out.println(g); + } + + /* + * small connected graph with one articulation and one bridge + */ + public static void test4() { + Graph g = new Graph(pathToProgramRoot + "/csv/art-brck.csv"); + System.out.println(g); + } + + /* + * randomly generated graph with x nodes + */ + public static void test5() { + Graph g = new Graph(pathToProgramRoot + "/csv/50n.csv"); System.out.println(g); } } \ No newline at end of file diff --git a/src/TestMatrix.java b/src/TestMatrix.java index b8a244d..c714b6d 100644 --- a/src/TestMatrix.java +++ b/src/TestMatrix.java @@ -1,6 +1,14 @@ public class TestMatrix { public static void main(String[] args) { - Matrix matrix = new Matrix(""); + // test1(); + // test2(); + createCsv(); + } + + public static void test1() { + String pathToProgramRoot = "/home/rene/projects/grpahprogram"; + + Matrix matrix = new Matrix(pathToProgramRoot + "/csv/graph.csv"); Matrix scalarProduct; System.out.println("RowLength: " + matrix.getRowLength()); @@ -11,4 +19,14 @@ public class TestMatrix { scalarProduct = matrix.multiply(matrix); System.out.println("\nScalarProduct A²: \n" + scalarProduct); } + + public static void test2() { + Matrix bruh = new Matrix(10, 10, true); + System.out.println(bruh); + } + + public static void createCsv() { + Matrix bruh = new Matrix(50, 50, true); + bruh.WriteToCsv("csv/50n.csv"); + } }