a bit better

This commit is contained in:
René Fuhry 2023-06-01 12:38:55 +02:00 committed by GitHub
parent 42b2e37765
commit 1a7ddb2231
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4,25 +4,25 @@ pub fn calculate_distanz_matrix(adjazenz_matrix: &Vec<Vec<usize>>) -> Vec<Vec<us
let mut distanz_matrix: Vec<Vec<usize>> = vec![];
let mut potenz_matrix = adjazenz_matrix.clone();
for i in 0..adjazenz_matrix.len() {
distanz_matrix.push(vec![]);
for j in 0..adjazenz_matrix.len() {
if i == j {
distanz_matrix[i].push(0)
} else if adjazenz_matrix[i][j] == 1 {
distanz_matrix[i].push(1);
} else {
distanz_matrix[i].push(usize::MAX);
}
}
}
for k in 2..adjazenz_matrix.len() {
for k in 1..adjazenz_matrix.len() {
potenz_matrix = matrix::mult(&potenz_matrix, &adjazenz_matrix);
for i in 0..adjazenz_matrix.len() {
if k == 1 {
distanz_matrix.push(vec![]);
}
for j in 0..adjazenz_matrix.len() {
if potenz_matrix[i][j] != 0 && distanz_matrix[i][j] == usize::MAX {
distanz_matrix[i][j] = k;
if k != 1 {
if potenz_matrix[i][j] != 0 && distanz_matrix[i][j] == usize::MAX {
distanz_matrix[i][j] = k;
}
continue;
}
if i == j {
distanz_matrix[i].push(0)
} else if adjazenz_matrix[i][j] == 1 {
distanz_matrix[i].push(1);
} else {
distanz_matrix[i].push(usize::MAX);
}
}
}
@ -34,25 +34,25 @@ pub fn calculate_weg_matrix(adjazenz_matrix: &Vec<Vec<usize>>) -> Vec<Vec<usize>
let mut weg_matrix: Vec<Vec<usize>> = vec![];
let mut potenz_matrix = adjazenz_matrix.clone();
for i in 0..adjazenz_matrix.len() {
weg_matrix.push(vec![]);
for j in 0..adjazenz_matrix.len() {
if i == j {
weg_matrix[i].push(1)
} else if adjazenz_matrix[i][j] == 1 {
weg_matrix[i].push(1);
} else {
weg_matrix[i].push(0);
}
}
}
for _k in 2..adjazenz_matrix.len() {
for k in 1..adjazenz_matrix.len() {
potenz_matrix = matrix::mult(&potenz_matrix, &adjazenz_matrix);
for i in 0..adjazenz_matrix.len() {
if k == 1 {
weg_matrix.push(vec![]);
}
for j in 0..adjazenz_matrix.len() {
if potenz_matrix[i][j] != 0 {
weg_matrix[i][j] = 1;
if k != 1 {
if potenz_matrix[i][j] != 0 {
weg_matrix[i][j] = 1;
}
continue;
}
if i == j {
weg_matrix[i].push(1)
} else if adjazenz_matrix[i][j] == 1 {
weg_matrix[i].push(1);
} else {
weg_matrix[i].push(0);
}
}
}
@ -68,7 +68,7 @@ pub fn calculate_exzentrizitaeten(distanz_matrix: &Vec<Vec<usize>>) -> Vec<usize
exzentrizitaet = 0;
for j in 0..distanz_matrix.len() {
if distanz_matrix[i][j] > exzentrizitaet && i != j {
if i != j && distanz_matrix[i][j] > exzentrizitaet {
exzentrizitaet = distanz_matrix[i][j];
}
}