add brute force
This commit is contained in:
59
src/points.c
59
src/points.c
@@ -17,9 +17,12 @@
|
||||
#include <stdlib.h>
|
||||
#include <getopt.h>
|
||||
#include <string.h>
|
||||
#include "timer.h"
|
||||
#include <float.h>
|
||||
#include "points.h"
|
||||
#include "distance.h"
|
||||
#include "timer.h"
|
||||
#include "read_file.h"
|
||||
#include "brute_force.h"
|
||||
|
||||
#define POINTS_VERSION "1.0.0"
|
||||
|
||||
@@ -36,6 +39,25 @@ void print_usage() {
|
||||
fprintf(stdout, " -v, --version mostrar la versión del programa\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* Empezar los pasos antes de correr
|
||||
*/
|
||||
void start_algorithm(const char *message, int n) {
|
||||
fprintf(stdout, "%s", message);
|
||||
fflush(stdout);
|
||||
start_timer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Empezar los pasos después de correr
|
||||
*/
|
||||
void end_algorithm() {
|
||||
stop_timer();
|
||||
fprintf(stdout, "done\n");
|
||||
print_timer();
|
||||
fprintf(stdout, "\n");
|
||||
}
|
||||
|
||||
/**
|
||||
* La entrada del programa
|
||||
* @param argc La cantidad de argumentos pasado al programa
|
||||
@@ -43,7 +65,9 @@ void print_usage() {
|
||||
* @return Retorna el codigo de error o 0 por exito
|
||||
*/
|
||||
int main (int argc, char **argv) {
|
||||
double dist = DBL_MAX;
|
||||
point_t *points = NULL;
|
||||
point_t *closest_points = NULL;
|
||||
char *filename = NULL;
|
||||
int brute = 0;
|
||||
int divide = 0;
|
||||
@@ -116,8 +140,7 @@ int main (int argc, char **argv) {
|
||||
return 2;
|
||||
}
|
||||
|
||||
points = malloc(sizeof(point_t));
|
||||
if ((opt = read_file(filename, &points, &n)) == 1) {
|
||||
if ((opt = read_file(filename, &points, &n))) {
|
||||
if (filename != NULL) {
|
||||
free(filename);
|
||||
}
|
||||
@@ -127,10 +150,38 @@ int main (int argc, char **argv) {
|
||||
}
|
||||
return 3;
|
||||
}
|
||||
|
||||
if (filename != NULL) {
|
||||
free(filename);
|
||||
}
|
||||
|
||||
if (n < 2) {
|
||||
fprintf(stderr, "Error: Se necesita un minimo de 2 puntos!\n");
|
||||
return 4;
|
||||
}
|
||||
|
||||
if (brute) {
|
||||
start_algorithm("Brute force corriendo... ", n);
|
||||
closest_points = brute_force(points, n, &dist);
|
||||
end_algorithm();
|
||||
printf("point 1: x: %f y: %f\n", closest_points[0].x, closest_points[0].y);
|
||||
printf("point 2: x: %f y: %f\n", closest_points[1].x, closest_points[1].y);
|
||||
printf("distance: %lf\n\n", dist);
|
||||
free(closest_points);
|
||||
closest_points = NULL;
|
||||
}
|
||||
|
||||
if (divide) {
|
||||
start_algorithm("Divide and conquer corriendo... ", n);
|
||||
//closest_points = divide_and_conquer(points, n, &dist);
|
||||
end_algorithm();
|
||||
/*printf("point 1: x: %f y: %f\n", closest_points[0].x, closest_points[0].y);
|
||||
printf("point 2: x: %f y: %f\n", closest_points[1].x, closest_points[1].y);
|
||||
printf("distance: %lf\n", dist);
|
||||
free(closest_points);
|
||||
closest_points = NULL;*/
|
||||
}
|
||||
|
||||
free(points);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user