not good enough
This commit is contained in:
parent
a5484f4bfe
commit
11f90b5cc8
@ -6,7 +6,7 @@ pub fn calculate_distanz_matrix(adjazenz_matrix: &Vec<Vec<u8>>) -> Vec<Vec<u8>>
|
||||
let mut distanz_matrix: Vec<Vec<u8>> = vec![vec![]; adjazenz_matrix.len()];
|
||||
let mut potenz_matrix = clone(adjazenz_matrix);
|
||||
|
||||
for k in 1..adjazenz_matrix.len() {
|
||||
for k in 1..(adjazenz_matrix.len() + 1) {
|
||||
potenz_matrix = matrix::mult(&potenz_matrix, adjazenz_matrix);
|
||||
for i in 0..adjazenz_matrix.len() {
|
||||
for j in 0..adjazenz_matrix.len() {
|
||||
@ -33,7 +33,7 @@ pub fn calculate_weg_matrix(adjazenz_matrix: &Vec<Vec<u8>>) -> Vec<Vec<u8>> {
|
||||
let mut weg_matrix: Vec<Vec<u8>> = vec![vec![]; adjazenz_matrix.len()];
|
||||
let mut potenz_matrix = clone(adjazenz_matrix);
|
||||
|
||||
for k in 1..adjazenz_matrix.len() {
|
||||
for k in 1..(adjazenz_matrix.len() + 1) {
|
||||
potenz_matrix = matrix::mult(&potenz_matrix, adjazenz_matrix);
|
||||
for i in 0..adjazenz_matrix.len() {
|
||||
for j in 0..adjazenz_matrix.len() {
|
||||
|
@ -1,6 +1,11 @@
|
||||
use csv::ReaderBuilder;
|
||||
|
||||
pub fn fill_with_random(size: usize) -> Vec<Vec<u8>> {
|
||||
assert!(
|
||||
(size < u8::MAX.into() && size > 0),
|
||||
"fill_with_random: size must not be bigger than 255 or smaller than 1, size was: {size}"
|
||||
);
|
||||
|
||||
let mut matrix: Vec<Vec<u8>> = vec![];
|
||||
for i in 0..size {
|
||||
matrix.push(vec![]);
|
||||
@ -25,9 +30,7 @@ pub fn mult(matrix1: &Vec<Vec<usize>>, matrix2: &Vec<Vec<u8>>) -> Vec<Vec<usize>
|
||||
vector.push(array[index].into());
|
||||
}
|
||||
for array in matrix1 {
|
||||
let sum = array.iter().zip(vector.iter()).map(|(x, y)| x * y).sum();
|
||||
//println!("{sum}");
|
||||
product[k].push(sum);
|
||||
product[k].push(array.iter().zip(vector.iter()).map(|(x, y)| x * y).sum());
|
||||
}
|
||||
}
|
||||
product
|
||||
|
12
src/main.rs
12
src/main.rs
@ -1,11 +1,15 @@
|
||||
use crate::graph::{*, matrix::{read_csv, show}};
|
||||
#[allow(unused_imports)]
|
||||
use crate::graph::{
|
||||
matrix::{fill_with_random, read_csv, show},
|
||||
*,
|
||||
};
|
||||
|
||||
pub mod graph;
|
||||
|
||||
pub fn main() {
|
||||
let file_name = "24n.csv";
|
||||
let mut adjazenz_matrix = read_csv(file_name);
|
||||
//let mut adjazenz_matrix = fill_with_random(45); // with this many verteces, it runs in about 10.2 seconds (2023-06-02 14:39)
|
||||
//let file_name = "50n.csv";
|
||||
//let mut adjazenz_matrix = read_csv(file_name);
|
||||
let mut adjazenz_matrix = fill_with_random(1); // with 48 verteces, it runs in about 10.2 seconds (run on the 2023-06-03 at 12:36)
|
||||
let distanz_matrix = calculate_distanz_matrix(&adjazenz_matrix);
|
||||
let weg_matrix = calculate_weg_matrix(&adjazenz_matrix);
|
||||
|
||||
|
Reference in New Issue
Block a user