Skip to content
Snippets Groups Projects
Commit fc4c50c9 authored by Sinaro LY's avatar Sinaro LY
Browse files

grasp un peu plus joli

parent 864e2866
No related branches found
No related tags found
No related merge requests found
...@@ -8,35 +8,17 @@ ...@@ -8,35 +8,17 @@
using namespace std; using namespace std;
int main() { int main() {
srand(21058497); srand(21058465);
t_graphe graph; t_graphe graph;
graph = lecture_fichier("la01.txt"); graph = lecture_fichier("la01.txt");
//int best = INT16_MAX;
//for (int i = 0; i < 1000; i++)
//{
// bierwirth v = generateVector(graph.nb_pieces, graph.nb_machines);
// solution_t sol = evaluer(v, graph);
// auto solRech = solution::rechercheLocale(v, graph, 1000);
// if (solRech.cost < best) {
// best = solRech.cost;
// }
//}
//cout << best << endl;
solution_t sol; solution_t sol;
bierwirth v = generateVector(graph.nb_pieces, graph.nb_machines); bierwirth v = generateVector(graph.nb_pieces, graph.nb_machines);
//sol = evaluer(v, graph);
//cout << "oui" << endl;
sol.cost = INT16_MAX; sol.cost = INT16_MAX;
grasp(&sol, graph, 666); grasp(&sol, graph, 666);
//affiche_solution(sol); affiche_solution(sol);
cout << "meilleur cout final : " << sol.cost << endl; cout << "meilleur cout final : " << sol.cost << endl;
... ...
......
...@@ -260,12 +260,10 @@ void grasp(solution_t* sol, t_graph graphe, int best_cost) ...@@ -260,12 +260,10 @@ void grasp(solution_t* sol, t_graph graphe, int best_cost)
void grasp(solution_t* sol, t_graph graphe, int best_cost) void grasp(solution_t* sol, t_graph graphe, int best_cost)
{ {
//solution_t solution_tab[SOLUTION_MAX_TAB];
solution_t new_solution; solution_t new_solution;
solution_t best_neighbour; solution_t best_neighbour;
bierwirth v; bierwirth v;
int nb_neighbours = 0; int nb_neighbours = 0;
//int i = 0;
int nb_it = 0; int nb_it = 0;
int count; int count;
int size = graphe.nb_machines * graphe.nb_pieces; int size = graphe.nb_machines * graphe.nb_pieces;
...@@ -287,22 +285,15 @@ void grasp(solution_t* sol, t_graph graphe, int best_cost) ...@@ -287,22 +285,15 @@ void grasp(solution_t* sol, t_graph graphe, int best_cost)
do do
{ {
v = generateVector(graphe.nb_pieces, graphe.nb_machines); v = generateVector(graphe.nb_pieces, graphe.nb_machines);
new_solution = solution::rechercheLocale(v, graphe, 1000); new_solution = solution::rechercheLocale(v, graphe, 1000);
new_solution.v = v; new_solution.v = v;
//cout << "oui2" << endl;
} while (sameH(new_solution, hash, HASH_SIZE)); } while (sameH(new_solution, hash, HASH_SIZE));
//cout << "oui3" << endl;
while (nb_neighbours < MAX_NEIGHBOURS && count < MAX_COUNT && nb_neighbours < 1) while (nb_neighbours < MAX_NEIGHBOURS && count < MAX_COUNT && nb_neighbours < 1)
{ {
new_solution = genNeighbour(new_solution.v, size, graphe.nb_pieces, graphe.nb_machines); new_solution = genNeighbour(new_solution.v, size, graphe.nb_pieces, graphe.nb_machines);
v = new_solution.v; v = new_solution.v;
//cout << "oui4" << endl;
//vecteur_valide(v, graphe.nb_machines, graphe.nb_pieces);
new_solution = solution::rechercheLocale(v, graphe, 1000); new_solution = solution::rechercheLocale(v, graphe, 1000);
//cout << new_solution.cost << endl;
new_solution.v = v; new_solution.v = v;
if (sameH(new_solution, hash, HASH_SIZE) == 0) //s'ils ont un hash diffrent if (sameH(new_solution, hash, HASH_SIZE) == 0) //s'ils ont un hash diffrent
...@@ -323,13 +314,13 @@ void grasp(solution_t* sol, t_graph graphe, int best_cost) ...@@ -323,13 +314,13 @@ void grasp(solution_t* sol, t_graph graphe, int best_cost)
if (best_neighbour.cost<sol->cost) if (best_neighbour.cost<sol->cost)
{ {
*sol = best_neighbour; *sol = best_neighbour;
cout << best_neighbour.cost << endl; //cout << best_neighbour.cost << endl;
} }
++nb_it; ++nb_it;
} }
cout << "nombre d'iterations : " << nb_it << endl;
} }
No preview for this file type
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment