renamed variables

This commit is contained in:
René Fuhry 2023-06-02 23:31:31 +02:00 committed by GitHub
parent 40db6c2188
commit 3abc3a8e75
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 41 deletions

@ -64,16 +64,14 @@ pub fn calculate_exzentrizitaeten(distanz_matrix: Vec<Vec<usize>>) -> Vec<usize>
let mut exzentrizitaeten: Vec<usize> = vec![]; let mut exzentrizitaeten: Vec<usize> = vec![];
let mut exzentrizitaet: usize; let mut exzentrizitaet: usize;
for i in 0..distanz_matrix.len() { for vector in distanz_matrix {
exzentrizitaet = 0; exzentrizitaet = 0;
for j in 0..distanz_matrix.len() { for value in vector {
if i == j || distanz_matrix[i][j] == usize::MAX { if value == usize::MAX {
continue; continue;
} }
if distanz_matrix[i][j] > exzentrizitaet { exzentrizitaet = exzentrizitaet.max(value);
exzentrizitaet = distanz_matrix[i][j];
}
} }
exzentrizitaeten.push(exzentrizitaet); exzentrizitaeten.push(exzentrizitaet);
} }
@ -86,19 +84,21 @@ pub fn calculate_properties(exzentrizitaeten: &Vec<usize>) -> (usize, usize, Vec
let mut centre: Vec<usize> = vec![]; let mut centre: Vec<usize> = vec![];
let mut connected: bool = true; let mut connected: bool = true;
for i in 0..exzentrizitaeten.len() { for index in 0..exzentrizitaeten.len() {
if exzentrizitaeten[i] > diameter { let value = exzentrizitaeten[index];
diameter = exzentrizitaeten[i];
if value > diameter {
diameter = value;
} }
if exzentrizitaeten[i] == radius { if value == radius {
centre.push(i + 1); centre.push(index + 1);
} }
if exzentrizitaeten[i] < radius { if value < radius {
radius = exzentrizitaeten[i]; radius = value;
centre.clear(); centre.clear();
centre.push(i + 1); centre.push(index + 1);
} }
if exzentrizitaeten[i] == 0 { if value == 0 {
connected = false; connected = false;
} }
} }
@ -108,16 +108,13 @@ pub fn calculate_properties(exzentrizitaeten: &Vec<usize>) -> (usize, usize, Vec
pub fn find_components(weg_matrix: Vec<Vec<usize>>) -> Vec<Vec<usize>> { pub fn find_components(weg_matrix: Vec<Vec<usize>>) -> Vec<Vec<usize>> {
let mut components: Vec<Vec<usize>> = vec![]; let mut components: Vec<Vec<usize>> = vec![];
let mut component: Vec<usize>; let mut component: Vec<usize>;
let mut i: usize;
for array in weg_matrix { for array in weg_matrix {
component = vec![]; component = vec![];
i = 1; for index in 0..array.len() {
for value in array { if array[index] == 1 {
if value == 1 { component.push(index + 1);
component.push(i);
} }
i += 1;
} }
if !components.contains(&component) { if !components.contains(&component) {
components.push(component); components.push(component);
@ -128,10 +125,7 @@ pub fn find_components(weg_matrix: Vec<Vec<usize>>) -> Vec<Vec<usize>> {
pub fn find_articulations_and_bridges(adjazenz_matrix: &mut Vec<Vec<usize>>, components: &Vec<Vec<usize>>) -> (Vec<usize>,Vec<Vec<usize>>) { pub fn find_articulations_and_bridges(adjazenz_matrix: &mut Vec<Vec<usize>>, components: &Vec<Vec<usize>>) -> (Vec<usize>,Vec<Vec<usize>>) {
let mut bridges: Vec<Vec<usize>> = vec![]; let mut bridges: Vec<Vec<usize>> = vec![];
let mut bridge: Vec<usize>;
let mut prev_value: usize;
let mut articulations: Vec<usize> = vec![]; let mut articulations: Vec<usize> = vec![];
let mut new_components: Vec<Vec<usize>>;
let mut temp_matrix: Vec<Vec<usize>> = adjazenz_matrix.clone(); let mut temp_matrix: Vec<Vec<usize>> = adjazenz_matrix.clone();
for n in 0..temp_matrix.len() { for n in 0..temp_matrix.len() {
@ -143,17 +137,12 @@ pub fn find_articulations_and_bridges(adjazenz_matrix: &mut Vec<Vec<usize>>, com
if n != 0 { if n != 0 {
continue; continue;
} }
bridge = vec![]; let bridge = vec![usize::min(i + 1, j + 1), usize::max(i + 1, j + 1)];
bridge.push(usize::min(i + 1, j + 1)); let prev_value = adjazenz_matrix[i][j];
bridge.push(usize::max(i + 1, j + 1));
prev_value = adjazenz_matrix[i][j];
adjazenz_matrix[i][j] = 0; adjazenz_matrix[i][j] = 0;
adjazenz_matrix[j][i] = 0; adjazenz_matrix[j][i] = 0;
new_components = find_components(calculate_weg_matrix(&adjazenz_matrix)); if find_components(calculate_weg_matrix(&adjazenz_matrix)).len() > components.len() && !bridges.contains(&bridge) {
if new_components.len() > components.len() && !bridges.contains(&bridge) {
bridges.push(bridge); bridges.push(bridge);
} }
adjazenz_matrix[i][j] = prev_value; adjazenz_matrix[i][j] = prev_value;
@ -161,9 +150,7 @@ pub fn find_articulations_and_bridges(adjazenz_matrix: &mut Vec<Vec<usize>>, com
} }
} }
new_components = find_components(calculate_weg_matrix(&temp_matrix)); if find_components(calculate_weg_matrix(&temp_matrix)).len() > (components.len() + 1) {
if new_components.len() > (components.len() + 1) {
articulations.push(n + 1); articulations.push(n + 1);
} }
temp_matrix = adjazenz_matrix.clone(); temp_matrix = adjazenz_matrix.clone();

@ -1,5 +1,3 @@
#[allow(unused_imports)]
use std::{fs::File, io::Read};
use csv::ReaderBuilder; use csv::ReaderBuilder;
pub fn fill_with_random(size: usize) -> Vec<Vec<usize>> { pub fn fill_with_random(size: usize) -> Vec<Vec<usize>> {
@ -42,8 +40,8 @@ pub fn mult(matrix1: &Vec<Vec<usize>>, matrix2: &Vec<Vec<usize>>) -> Vec<Vec<usi
pub fn show(matrix: &Vec<Vec<usize>>) { pub fn show(matrix: &Vec<Vec<usize>>) {
for vector in matrix { for vector in matrix {
for int in vector { for value in vector {
print!("{int} "); print!("{value} ");
} }
println!(); println!();
} }