Commit fc4c50c9 authored by Sinaro LY's avatar Sinaro LY
Browse files

grasp un peu plus joli

parent 864e2866
......@@ -8,35 +8,17 @@
using namespace std;
int main() {
srand(21058497);
srand(21058465);
t_graphe graph;
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;
bierwirth v = generateVector(graph.nb_pieces, graph.nb_machines);
//sol = evaluer(v, graph);
//cout << "oui" << endl;
sol.cost = INT16_MAX;
grasp(&sol, graph, 666);
//affiche_solution(sol);
affiche_solution(sol);
cout << "meilleur cout final : " << sol.cost << endl;
......
......@@ -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)
{
//solution_t solution_tab[SOLUTION_MAX_TAB];
solution_t new_solution;
solution_t best_neighbour;
bierwirth v;
int nb_neighbours = 0;
//int i = 0;
int nb_it = 0;
int count;
int size = graphe.nb_machines * graphe.nb_pieces;
......@@ -287,22 +285,15 @@ void grasp(solution_t* sol, t_graph graphe, int best_cost)
do
{
v = generateVector(graphe.nb_pieces, graphe.nb_machines);
new_solution = solution::rechercheLocale(v, graphe, 1000);
new_solution.v = v;
//cout << "oui2" << endl;
} while (sameH(new_solution, hash, HASH_SIZE));
//cout << "oui3" << endl;
while (nb_neighbours < MAX_NEIGHBOURS && count < MAX_COUNT && nb_neighbours < 1)
{
new_solution = genNeighbour(new_solution.v, size, graphe.nb_pieces, graphe.nb_machines);
v = new_solution.v;
//cout << "oui4" << endl;
//vecteur_valide(v, graphe.nb_machines, graphe.nb_pieces);
new_solution = solution::rechercheLocale(v, graphe, 1000);
//cout << new_solution.cost << endl;
new_solution.v = v;
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)
if (best_neighbour.cost<sol->cost)
{
*sol = best_neighbour;
cout << best_neighbour.cost << endl;
//cout << best_neighbour.cost << endl;
}
++nb_it;
}
cout << "nombre d'iterations : " << nb_it << endl;
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment