a bit better
This commit is contained in:
parent
42b2e37765
commit
1a7ddb2231
66
src/graph.rs
66
src/graph.rs
@ -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 distanz_matrix: Vec<Vec<usize>> = vec![];
|
||||||
let mut potenz_matrix = adjazenz_matrix.clone();
|
let mut potenz_matrix = adjazenz_matrix.clone();
|
||||||
|
|
||||||
for i in 0..adjazenz_matrix.len() {
|
for k in 1..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() {
|
|
||||||
potenz_matrix = matrix::mult(&potenz_matrix, &adjazenz_matrix);
|
potenz_matrix = matrix::mult(&potenz_matrix, &adjazenz_matrix);
|
||||||
for i in 0..adjazenz_matrix.len() {
|
for i in 0..adjazenz_matrix.len() {
|
||||||
|
if k == 1 {
|
||||||
|
distanz_matrix.push(vec![]);
|
||||||
|
}
|
||||||
for j in 0..adjazenz_matrix.len() {
|
for j in 0..adjazenz_matrix.len() {
|
||||||
if potenz_matrix[i][j] != 0 && distanz_matrix[i][j] == usize::MAX {
|
if k != 1 {
|
||||||
distanz_matrix[i][j] = k;
|
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 weg_matrix: Vec<Vec<usize>> = vec![];
|
||||||
let mut potenz_matrix = adjazenz_matrix.clone();
|
let mut potenz_matrix = adjazenz_matrix.clone();
|
||||||
|
|
||||||
for i in 0..adjazenz_matrix.len() {
|
for k in 1..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() {
|
|
||||||
potenz_matrix = matrix::mult(&potenz_matrix, &adjazenz_matrix);
|
potenz_matrix = matrix::mult(&potenz_matrix, &adjazenz_matrix);
|
||||||
for i in 0..adjazenz_matrix.len() {
|
for i in 0..adjazenz_matrix.len() {
|
||||||
|
if k == 1 {
|
||||||
|
weg_matrix.push(vec![]);
|
||||||
|
}
|
||||||
for j in 0..adjazenz_matrix.len() {
|
for j in 0..adjazenz_matrix.len() {
|
||||||
if potenz_matrix[i][j] != 0 {
|
if k != 1 {
|
||||||
weg_matrix[i][j] = 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;
|
exzentrizitaet = 0;
|
||||||
|
|
||||||
for j in 0..distanz_matrix.len() {
|
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];
|
exzentrizitaet = distanz_matrix[i][j];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user