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

update grasp

parent e1efa231
......@@ -166,6 +166,7 @@ void solution::rechercheLocale(bierwirth v, solution_t& solution)
{
}
/*
void grasp(solution_t* sol, t_graph graphe, int best_cost)
{
solution_t solution_tab[SOLUTION_MAX_TAB];
......@@ -194,7 +195,7 @@ void grasp(solution_t* sol, t_graph graphe, int best_cost)
evaluer(new_solution.v, graphe);
//solution ::rechercheLocale(new_solution.v)
if (sameH(new_solution, hash, size))
if (sameH(new_solution, hash, size) == 0) //s'ils ont un hash différent
{
solution_tab[nb_neighbours] = new_solution;
++nb_neighbours;
......@@ -217,5 +218,67 @@ 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;
int nb_neighbours = 0;
//int i = 0;
int nb_it = 0;
int count;
int size = graphe.nb_machines * graphe.nb_pieces;
int hash[HASH_SIZE];
for (int i = 0; i < HASH_SIZE; i++)
{
hash[i] = 0;
}
while ((nb_it < MAX_IT) && (sol->cost != best_cost))
{
nb_neighbours = 0;
count = 0;
best_neighbour.cost = INT_FAST32_MAX;
do
{
new_solution.v = generateVector(graphe.nb_pieces, graphe.nb_machines);
//solution ::rechercheLocale(new_solution.v)
} while (sameH(new_solution, hash, size));
while (nb_neighbours < MAX_NEIGHBOURS && count < MAX_COUNT && nb_neighbours < 1)
{
new_solution = genNeighbour(*sol, size);
//solution ::rechercheLocale(new_solution.v)
//solution ::rechercheLocale(new_solution.v)
if (sameH(new_solution, hash, size) == 0) //s'ils ont un hash différent
{
++nb_neighbours;
}
else
{
++count;
}
if (new_solution.cost < best_neighbour.cost)
{
best_neighbour = new_solution;
}
}
if (best_neighbour.cost<sol->cost)
{
*sol = best_neighbour;
}
++nb_it;
}
}
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