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 distanz_matrix: Vec<Vec<u8>> = vec![vec![]; adjazenz_matrix.len()];
|
||||||
let mut potenz_matrix = clone(adjazenz_matrix);
|
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);
|
potenz_matrix = matrix::mult(&potenz_matrix, adjazenz_matrix);
|
||||||
for i in 0..adjazenz_matrix.len() {
|
for i in 0..adjazenz_matrix.len() {
|
||||||
for j 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 weg_matrix: Vec<Vec<u8>> = vec![vec![]; adjazenz_matrix.len()];
|
||||||
let mut potenz_matrix = clone(adjazenz_matrix);
|
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);
|
potenz_matrix = matrix::mult(&potenz_matrix, adjazenz_matrix);
|
||||||
for i in 0..adjazenz_matrix.len() {
|
for i in 0..adjazenz_matrix.len() {
|
||||||
for j in 0..adjazenz_matrix.len() {
|
for j in 0..adjazenz_matrix.len() {
|
||||||
|
@ -1,6 +1,11 @@
|
|||||||
use csv::ReaderBuilder;
|
use csv::ReaderBuilder;
|
||||||
|
|
||||||
pub fn fill_with_random(size: usize) -> Vec<Vec<u8>> {
|
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![];
|
let mut matrix: Vec<Vec<u8>> = vec![];
|
||||||
for i in 0..size {
|
for i in 0..size {
|
||||||
matrix.push(vec![]);
|
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());
|
vector.push(array[index].into());
|
||||||
}
|
}
|
||||||
for array in matrix1 {
|
for array in matrix1 {
|
||||||
let sum = array.iter().zip(vector.iter()).map(|(x, y)| x * y).sum();
|
product[k].push(array.iter().zip(vector.iter()).map(|(x, y)| x * y).sum());
|
||||||
//println!("{sum}");
|
|
||||||
product[k].push(sum);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
product
|
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 mod graph;
|
||||||
|
|
||||||
pub fn main() {
|
pub fn main() {
|
||||||
let file_name = "24n.csv";
|
//let file_name = "50n.csv";
|
||||||
let mut adjazenz_matrix = read_csv(file_name);
|
//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 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 distanz_matrix = calculate_distanz_matrix(&adjazenz_matrix);
|
||||||
let weg_matrix = calculate_weg_matrix(&adjazenz_matrix);
|
let weg_matrix = calculate_weg_matrix(&adjazenz_matrix);
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user