new random graph feature #6
@ -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++) {
|
||||
|
@ -3,6 +3,8 @@ 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;
|
||||
@ -13,6 +15,9 @@ public class Matrix {
|
||||
|
||||
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];
|
||||
@ -114,6 +119,25 @@ public class Matrix {
|
||||
}
|
||||
}
|
||||
|
||||
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++) {
|
||||
|
@ -1,12 +1,13 @@
|
||||
public class TestGraph {
|
||||
public static void main(String[] args) {
|
||||
test1();
|
||||
test2();
|
||||
test3();
|
||||
test4();
|
||||
// test1();
|
||||
// test2();
|
||||
// test3();
|
||||
// test4();
|
||||
test5();
|
||||
}
|
||||
|
||||
static String pathToProgramRoot = "";
|
||||
static String pathToProgramRoot = "/home/rene/projects/Java/graphprogram";
|
||||
|
||||
|
||||
/*
|
||||
@ -41,4 +42,12 @@ public class TestGraph {
|
||||
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);
|
||||
}
|
||||
}
|
@ -1,11 +1,12 @@
|
||||
public class TestMatrix {
|
||||
public static void main(String[] args) {
|
||||
test1();
|
||||
test2();
|
||||
// test1();
|
||||
// test2();
|
||||
createCsv();
|
||||
}
|
||||
|
||||
public static void test1() {
|
||||
String pathToProgramRoot = "";
|
||||
String pathToProgramRoot = "/home/rene/projects/grpahprogram";
|
||||
|
||||
Matrix matrix = new Matrix(pathToProgramRoot + "/csv/graph.csv");
|
||||
Matrix scalarProduct;
|
||||
@ -22,5 +23,10 @@ public class TestMatrix {
|
||||
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");
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user