Commit 1fe46aac authored by Maxime's avatar Maxime
Browse files

fix infinit loop

parent adb9aefe
3 3
-1 3 3
0 10 1 4 2 5
1 5 0 2 2 10
2 10 1 3 0 10
\ No newline at end of file
......@@ -13,7 +13,7 @@ int main() {
srand(21058465);
t_graphe graph;
graph = gestionGraph::lecture_fichier("ft06.txt");
graph = gestionGraph::lecture_fichier("cours.txt");
solution_t sol;
bierwirth v = bierwirth_t::generateVector(graph.nb_pieces, graph.nb_machines);
......
......@@ -213,7 +213,8 @@ void solution::grasp(solution_t* sol, t_graph graphe)
int nb_it = 0;
int count;
int size = graphe.nb_machines * graphe.nb_pieces;
bool needToStop = false;
int needToStopCount;
int hash[HASH_SIZE];
for (int i = 0; i < HASH_SIZE; i++)
......@@ -222,10 +223,13 @@ void solution::grasp(solution_t* sol, t_graph graphe)
}
while ((nb_it < MAX_IT) && (sol->cost != graphe.supposedBestSolution))
while ((nb_it < MAX_IT) && (sol->cost != graphe.supposedBestSolution) && !needToStop)
{
nb_neighbours = 0;
count = 0;
needToStop = false;
needToStopCount = 0;
best_neighbour.cost = INT_FAST32_MAX;
do
......@@ -233,13 +237,18 @@ void solution::grasp(solution_t* sol, t_graph graphe)
v = bierwirth_t::generateVector(graphe.nb_pieces, graphe.nb_machines);
new_solution = solution::rechercheLocale(v, graphe, 1000);
new_solution.v = v;
} while (sameH(new_solution, hash, HASH_SIZE));
needToStopCount++;
if (needToStopCount == MAX_COUNT_HASH) {
needToStop = true;
}
} while (sameH(new_solution, hash, HASH_SIZE) && !needToStop);
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;
new_solution = solution::rechercheLocale(v, graphe, 1000);
new_solution.v = v;
if (sameH(new_solution, hash, HASH_SIZE) == 0) //s'ils ont un hash diffrent
......
......@@ -13,6 +13,7 @@
#define HASH_SIZE 90000
#define MAX_NEIGHBOURS 5
#define MAX_COUNT 10
#define MAX_COUNT_HASH 100
#define MAX_IT 1000
......
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