forked from juan230500/Server_P2_DatosII
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
98 lines (85 loc) · 2.6 KB
/
main.cpp
File metadata and controls
98 lines (85 loc) · 2.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
// Bibliotecas
#include "mainwindow.h"
#include "Pathfinding/Backtracking.hpp"
#include "Pathfinding/a_star.hpp"
#include "Data_Structures/nodo.hpp"
#include "Data_Structures/lista.hpp"
#include <QApplication>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <bits/stdc++.h>
using namespace std;
// Declaracion de funciones
void print_maze(int(*maze)[10]);
int Backtracking_test();
int A_star_test();
void lista_test();
typedef pair<int,int> Pair;
int main()
{
//lista_test();
cout<<"Backtracking:";
Backtracking_test();
cout<<"A*:";
A_star_test();
return 0;
}
/*
* Funcion que se encarga de realizar una prueba al algoritmo Backtracking
*/
int Backtracking_test(){
// Declarar la matriz que se usara como laberinto
int maze[][10] = { {0,0,1,0,0,0,0,0,0,0},
{0,0,1,0,0,0,0,0,0,0},
{0,0,1,0,0,0,0,0,0,0},
{0,1,0,0,0,1,1,0,0,0},
{0,0,1,0,0,0,1,0,0,0},
{0,0,0,0,0,0,0,0,0,1},
{0,0,0,1,0,0,0,0,0,1},
{0,0,0,1,0,0,0,0,0,1},
{0,0,0,1,0,0,1,1,0,0},
{0,0,0,1,0,0,0,1,0,0}};
Backtracking* solver = new Backtracking();
string my_path = solver->Backtracking_Search(maze);
int time = solver->get_Time();
delete(solver);
cout<<my_path<<endl;
cout<<"Encuentra la ruta en: "<< time<<" ns"<<endl;
return 0;
}
// Imprime el laberinto en la consola
void print_maze(int(*maze)[10]){
for(int row=0;row<10;row++){
cout<<"{ ";
for(int col=0;col<10;col++){
cout<<maze[row][col]<<" ";
}
cout<<" }"<<endl;
}
}
// Función que ejecuta el algoritmo A*
int A_star_test(){
// Declarar un laberinto
int maze[][10] = { {0,0,1,0,0,0,0,0,0,0},
{0,0,1,0,0,0,0,0,0,0},
{0,0,1,0,0,0,0,0,0,0},
{0,1,0,0,0,1,1,0,0,0},
{0,0,1,0,0,0,1,0,0,0},
{0,0,0,0,0,0,0,0,0,1},
{0,0,0,1,0,0,0,0,0,1},
{0,0,0,1,0,0,0,0,0,1},
{0,0,0,1,0,0,1,1,0,0},
{0,0,0,1,0,0,0,1,0,0}};
// Ejecutar el algoritmo A*
A_star* solver = new A_star();
solver->A_star_Search(maze,make_pair(0,0));
// Obtener la ruta como String
string my_Path = solver->get_Path();
int time = solver->get_Time();
delete(solver);
// Muestra en consola la ruta encontrada
cout<<my_Path<<endl;
cout<<"Encuentra la ruta en: "<<time<<" ns"<<endl;
return 0;
}