finish calculate_distance_matrix()

This commit is contained in:
AustrianToast 2024-10-07 09:03:29 +02:00
parent 6ab823c1fc
commit 49cab7b2cc
Signed by: AustrianToast
GPG Key ID: 174D780E041684FF
3 changed files with 30 additions and 19 deletions

10
graph.c
View File

@ -20,11 +20,12 @@ void random_adjacency(const uint64_t vertex_count, uint64_t matrix[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_distance_matrix(const uint64_t vertex_count, const uint64_t adjacency_matrix[vertex_count][vertex_count], uint64_t distance_matrix[vertex_count][vertex_count]) {
uint64_t power_matrix[vertex_count][vertex_count]; uint64_t power_matrix[vertex_count][vertex_count];
uint64_t temp_power_matrix[vertex_count][vertex_count];
copy(vertex_count, vertex_count, adjacency_matrix, power_matrix); copy(vertex_count, vertex_count, adjacency_matrix, power_matrix);
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 (row_index == column_index) {
distance_matrix[row_index][column_index] = 0; distance_matrix[row_index][column_index] = 0;
} else if (adjacency_matrix[row_index][column_index] == 1) { } else if (adjacency_matrix[row_index][column_index] == 1) {
distance_matrix[row_index][column_index] = 1; distance_matrix[row_index][column_index] = 1;
@ -34,8 +35,9 @@ void calculate_distance_matrix(const uint64_t vertex_count, const uint64_t adjac
} }
} }
for(uint64_t k = 2; k < vertex_count; k++) { 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); copy(vertex_count, vertex_count, power_matrix, temp_power_matrix);
matrix_multiply_basic(vertex_count, vertex_count, adjacency_matrix, vertex_count, vertex_count, temp_power_matrix, power_matrix);
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++) {
@ -47,5 +49,5 @@ void calculate_distance_matrix(const uint64_t vertex_count, const uint64_t adjac
} }
} }
void calculate_eccentricities(const uint64_t vertex_count, const uint64_t output_matrix[vertex_count][vertex_count]) { void calculate_eccentricities(const uint64_t vertex_count, const uint64_t output_arraay[vertex_count]) {
} }

View File

@ -10,7 +10,4 @@ void calculate_distance_matrix(const uint64_t vertex_count,
const uint64_t adjacency_matrix[vertex_count][vertex_count], const uint64_t adjacency_matrix[vertex_count][vertex_count],
uint64_t distance_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

22
main.c
View File

@ -44,14 +44,26 @@ void test() {
print_matrix(vertex_count, vertex_count, adjacency_matrix); print_matrix(vertex_count, vertex_count, adjacency_matrix);
printf("\n"); printf("\n");
// uint64_t new_matrix[row_length1][column_length1]; // uint64_t new_matrix1[vertex_count][vertex_count];
// //
// matrix_multiply_basic(row_length1, column_length1, matrix1, // matrix_multiply_basic(vertex_count, vertex_count, adjacency_matrix,
// row_length1, column_length1, matrix1, // vertex_count, vertex_count, adjacency_matrix,
// new_matrix); // new_matrix1);
// //
// printf("G²:\n"); // printf("G²:\n");
// print_matrix(row_length1, column_length1, new_matrix); // print_matrix(vertex_count, vertex_count, new_matrix1);
// printf("\n");
//
// uint64_t new_matrix2[vertex_count][vertex_count];
//
// copy(vertex_count, vertex_count, new_matrix1, new_matrix2);
//
// matrix_multiply_basic(vertex_count, vertex_count, new_matrix1,
// vertex_count, vertex_count, adjacency_matrix,
// new_matrix2);
//
// printf("G³:\n");
// print_matrix(vertex_count, vertex_count, new_matrix2);
// printf("\n"); // printf("\n");
uint64_t distance_matrix[vertex_count][vertex_count]; uint64_t distance_matrix[vertex_count][vertex_count];