Compare commits

..

2 Commits
dev ... main

Author SHA1 Message Date
René Fuhry
b636e22e69
new random graph feature (#6)
* new folder with csv

* more files

* improvements

* new method

* quick fix

* revert

* Too tired to write descriptive message

* can now create random graphs

* random graph with 50 nodes
2023-05-26 12:41:13 +02:00
René Fuhry
e95b94ec7b
small fix (#5) 2023-05-25 23:29:26 +02:00
2 changed files with 30 additions and 34 deletions

View File

@ -20,12 +20,12 @@ public class Graph {
public Graph(String file) {
adjazenzMatrix = new Matrix(file);
calculateDistanzMatrix();
calculateWegMatrix(adjazenzMatrix);
calculateWegMatrix();
calculateExzentrizitäten();
calculateProperties();
findComponents();
findBridges();
findArticulations();
findBridges(file);
findArticulations(file);
}
public void calculateDistanzMatrix() {
@ -57,22 +57,22 @@ public class Graph {
}
}
public void calculateWegMatrix(Matrix matrix) {
wegMatrix = new Matrix(matrix.getRowLength(), matrix.getColumnLength());
Matrix potenzMatrix = matrix;
public void calculateWegMatrix() {
wegMatrix = new Matrix(adjazenzMatrix.getRowLength(), adjazenzMatrix.getColumnLength());
Matrix potenzMatrix = adjazenzMatrix;
for(int columnIndex=0; columnIndex < wegMatrix.getColumnLength(); columnIndex++) {
for(int rowIndex=0; rowIndex < wegMatrix.getRowLength(); rowIndex++) {
if(columnIndex == rowIndex) {
wegMatrix.insert(rowIndex, columnIndex, 1);
} else if(matrix.getValueAt(rowIndex, columnIndex) > 0 && wegMatrix.getValueAt(rowIndex, columnIndex) == 0) {
} else if(adjazenzMatrix.getValueAt(rowIndex, columnIndex) > 0 && wegMatrix.getValueAt(rowIndex, columnIndex) == 0) {
wegMatrix.insert(rowIndex, columnIndex, 1);
}
}
}
for(int k = 2; k < wegMatrix.getRowLength(); k++) {
potenzMatrix = potenzMatrix.multiply(matrix);
potenzMatrix = potenzMatrix.multiply(adjazenzMatrix);
for(int columnIndex=0; columnIndex < wegMatrix.getColumnLength(); columnIndex++) {
for(int rowIndex=0; rowIndex < wegMatrix.getRowLength(); rowIndex++) {
@ -164,18 +164,17 @@ public class Graph {
newComponents.add(component);
}
}
return newComponents;
return newComponents;
}
public void findBridges() {
Matrix tempMatrix = adjazenzMatrix.clone();
public void findBridges(String file) {
bridges = new ArrayList<>(1);
ArrayList<ArrayList<Integer>> newComponents;
int[] bridge;
boolean contains;
for(int rowIndex = 0; rowIndex < tempMatrix.getRowLength(); rowIndex++) {
for(int columnIndex = 0; columnIndex < tempMatrix.getColumnLength(); columnIndex++) {
for(int rowIndex = 0; rowIndex < adjazenzMatrix.getRowLength(); rowIndex++) {
for(int columnIndex = 0; columnIndex < adjazenzMatrix.getColumnLength(); columnIndex++) {
if(rowIndex == columnIndex) {
continue;
}
@ -188,11 +187,12 @@ public class Graph {
bridge[1] = columnIndex + 1;
bridge[0] = rowIndex + 1;
}
tempMatrix.insert(rowIndex, columnIndex, 0);
tempMatrix.insert(columnIndex, rowIndex, 0);
adjazenzMatrix.insert(rowIndex, columnIndex, 0);
adjazenzMatrix.insert(columnIndex, rowIndex, 0);
calculateWegMatrix(tempMatrix);
calculateWegMatrix();
newComponents = findComponents(wegMatrix);
@ -208,26 +208,25 @@ public class Graph {
bridges.add(bridge);
}
tempMatrix = adjazenzMatrix.clone();
adjazenzMatrix = new Matrix(file);
}
}
calculateWegMatrix(adjazenzMatrix);
calculateWegMatrix();
}
public void findArticulations() {
Matrix tempMatrix = adjazenzMatrix.clone();
public void findArticulations(String file) {
articulations = new ArrayList<>(1);
ArrayList<ArrayList<Integer>> newComponents;
for(int i = 0; i < tempMatrix.getRowLength(); i++) {
for(int rowIndex = 0; rowIndex < tempMatrix.getRowLength(); rowIndex++) {
for(int columnIndex = 0; columnIndex < tempMatrix.getColumnLength(); columnIndex++) {
tempMatrix.insert(rowIndex, i, 0);
tempMatrix.insert(i, columnIndex, 0);
for(int i = 0; i < adjazenzMatrix.getRowLength(); i++) {
for(int rowIndex = 0; rowIndex < adjazenzMatrix.getRowLength(); rowIndex++) {
for(int columnIndex = 0; columnIndex < adjazenzMatrix.getColumnLength(); columnIndex++) {
adjazenzMatrix.insert(rowIndex, i, 0);
adjazenzMatrix.insert(i, columnIndex, 0);
}
}
calculateWegMatrix(tempMatrix);
calculateWegMatrix();
newComponents = findComponents(wegMatrix);
@ -235,9 +234,9 @@ public class Graph {
articulations.add(i + 1);
}
tempMatrix = adjazenzMatrix.clone();
adjazenzMatrix = new Matrix(file);
}
calculateWegMatrix(adjazenzMatrix);
calculateWegMatrix();
}
public String toString() {
@ -280,10 +279,7 @@ public class Graph {
}
s += "}";
s += "\nArtikulationen: ";
if(articulations != null)
s += articulations.toString();
s += "\nArtikulationen: " + articulations.toString();
return s;
}
}

View File

@ -95,7 +95,7 @@ public class Matrix {
}
}
public Matrix clone() {
public int[][] clone() {
int[][] clone = new int[rowLength][columnLength];
for(int columnIndex=0; columnIndex < columnLength; columnIndex++) {
@ -104,7 +104,7 @@ public class Matrix {
}
}
return new Matrix(clone);
return clone;
}
public void randomAdjazenzMatrix() {