startet distance_matrix bullshit

This commit is contained in:
AustrianToast 2024-10-04 17:36:40 +02:00
parent 9f17802c49
commit 9929a4470c
Signed by: AustrianToast
GPG Key ID: 174D780E041684FF
5 changed files with 73 additions and 17 deletions

35
graph.c
View File

@ -2,13 +2,14 @@
#include <stdio.h> #include <stdio.h>
#include <time.h> #include <time.h>
#include <stdlib.h> #include <stdlib.h>
#include "matrix.h"
void random_adjacency(const uint64_t vertex_count, uint64_t matrix[vertex_count][vertex_count]) { void random_adjacency(const uint64_t vertex_count, uint64_t matrix[vertex_count][vertex_count]) {
srand(time(NULL)); srand(time(NULL));
for (uint64_t row_index=0; row_index < vertex_count; row_index++) { for (uint64_t row_index=0; row_index < vertex_count; row_index++) {
for (uint64_t column_index=0; column_index < vertex_count; column_index++) { for (uint64_t column_index=0; column_index < vertex_count; column_index++) {
if(column_index == row_index) { if (column_index == row_index) {
matrix[row_index][column_index] = 0; matrix[row_index][column_index] = 0;
continue; continue;
} }
@ -17,6 +18,34 @@ void random_adjacency(const uint64_t vertex_count, uint64_t matrix[vertex_count]
} }
} }
int calculate_eccentricities() { void calculate_distance_matrix(const uint64_t vertex_count, const uint64_t adjacency_matrix[vertex_count][vertex_count], uint64_t distance_matrix[vertex_count][vertex_count]) {
return 0; uint64_t power_matrix[vertex_count][vertex_count];
copy(vertex_count, vertex_count, adjacency_matrix, power_matrix);
for (uint64_t row_index=0; row_index < vertex_count; row_index++) {
for (uint64_t column_index=0; column_index < vertex_count; column_index++) {
if (column_index == row_index) {
distance_matrix[row_index][column_index] = 0;
} else if (adjacency_matrix[row_index][column_index] == 1) {
distance_matrix[row_index][column_index] = 1;
} else {
distance_matrix[row_index][column_index] = UINT64_MAX;
}
}
}
for(uint64_t k = 2; k < vertex_count; k++) {
matrix_multiply_basic(vertex_count, vertex_count, adjacency_matrix, vertex_count, vertex_count, power_matrix, power_matrix);
for (uint64_t row_index=0; row_index < vertex_count; row_index++) {
for (uint64_t column_index=0; column_index < vertex_count; column_index++) {
if (power_matrix[row_index][column_index] != 0 && distance_matrix[row_index][column_index] == UINT64_MAX) {
distance_matrix[row_index][column_index] = k;
}
}
}
}
}
void calculate_eccentricities(const uint64_t vertex_count, const uint64_t output_matrix[vertex_count][vertex_count]) {
} }

View File

@ -6,4 +6,11 @@
void random_adjacency(const uint64_t vertex_count, void random_adjacency(const uint64_t vertex_count,
uint64_t matrix[vertex_count][vertex_count]); uint64_t matrix[vertex_count][vertex_count]);
void calculate_distance_matrix(const uint64_t vertex_count,
const uint64_t adjacency_matrix[vertex_count][vertex_count],
uint64_t distance_matrix[vertex_count][vertex_count]);
void calculate_eccentricities(const uint64_t vertex_count,
const uint64_t output_matrix[vertex_count][vertex_count]);
#endif #endif

33
main.c
View File

@ -35,28 +35,35 @@ void benchmark() {
} }
void test() { void test() {
const uint64_t row_length1 = 5; const uint64_t vertex_count = 5;
const uint64_t column_length1 = 5; uint64_t adjacency_matrix[vertex_count][vertex_count];
uint64_t matrix1[row_length1][column_length1];
read_csv("csv/graph.csv", row_length1, column_length1, matrix1); read_csv("csv/graph.csv", vertex_count, vertex_count, adjacency_matrix);
printf("G:\n"); printf("G:\n");
print_matrix(row_length1, column_length1, matrix1); print_matrix(vertex_count, vertex_count, adjacency_matrix);
printf("\n"); printf("\n");
uint64_t new_matrix[row_length1][column_length1]; // uint64_t new_matrix[row_length1][column_length1];
//
// matrix_multiply_basic(row_length1, column_length1, matrix1,
// row_length1, column_length1, matrix1,
// new_matrix);
//
// printf("G²:\n");
// print_matrix(row_length1, column_length1, new_matrix);
// printf("\n");
matrix_multiply_basic(row_length1, column_length1, matrix1, uint64_t distance_matrix[vertex_count][vertex_count];
row_length1, column_length1, matrix1,
new_matrix);
printf("G²:\n"); calculate_distance_matrix(vertex_count, adjacency_matrix, distance_matrix);
print_matrix(row_length1, column_length1, new_matrix);
printf("distance_matrix:\n");
print_matrix(vertex_count, vertex_count, distance_matrix);
printf("\n"); printf("\n");
} }
int main(void) { int main(void) {
// test(); test();
benchmark(); // benchmark();
} }

View File

@ -25,7 +25,7 @@ int matrix_multiply_basic(const uint64_t row_length1, const uint64_t column_leng
uint64_t sum; uint64_t sum;
for (uint64_t i = 0; i < row_length1; i++) { for (uint64_t i = 0; i < row_length1; i++) {
for(uint64_t j = 0; j < column_length2; j++) { for (uint64_t j = 0; j < column_length2; j++) {
sum = 0; sum = 0;
for (uint64_t k = 0; k <row_length1; k++) { for (uint64_t k = 0; k <row_length1; k++) {
@ -76,3 +76,11 @@ int read_csv(const char *file_name, const uint64_t row_length, const uint64_t co
return 0; return 0;
} }
void copy(const uint64_t row_length, const uint64_t column_length, const uint64_t input_matrix[row_length][column_length], uint64_t output_matrix[row_length][column_length]) {
for (uint64_t row_index = 0; row_index < row_length; row_index++) {
for (uint64_t column_index = 0; column_index <column_length; column_index++) {
output_matrix[row_index][column_length] = input_matrix[row_index][column_index];
}
}
}

View File

@ -26,4 +26,9 @@ int read_csv(char *file_name,
uint64_t column_length, uint64_t column_length,
uint64_t output_matrix[row_length][column_length]); uint64_t output_matrix[row_length][column_length]);
void copy(const uint64_t row_length,
const uint64_t column_length,
const uint64_t input_matrix[row_length][column_length],
uint64_t output_matrix[row_length][column_length]);
#endif #endif