Skip to content
Snippets Groups Projects
Commit b7e914b6 authored by Maxime POULAIN's avatar Maxime POULAIN
Browse files

working rech local

parent 4ea462b1
No related branches found
No related tags found
No related merge requests found
......@@ -39,26 +39,37 @@ void permutation(bierwirth& vectorIn, bierwirth& vectorOut, pr_t i, pr_t j, int
int iIndex = prToIndex(vectorIn, i, n, m);
int jIndex = prToIndex(vectorIn, j, n, m);
if (iIndex != -1 && jIndex != -1) {
for (int i = 0; i < n*m; i++)
{
vectorOut[i] = vectorIn[i];
}
vectorOut[jIndex] = vectorIn[iIndex];
vectorOut[iIndex] = vectorIn[jIndex];
}
else {
cout << "ERROR PERMUT" << endl;
cout << "piece : " << i.piece << " rang : " << i.rang << endl;
cout << "piece : " << j.piece << " rang : " << j.rang << endl;
}
}
int prToIndex(bierwirth& vector, pr_t i, int n, int m) {
int index = n * m - 1;
int cpt = 0;
int cpt = m ;
while (index >= 0) {
if (vector[index] == i.piece)
cpt++;
if (cpt == m - i.rang)
cpt--;
if (cpt == i.rang)
return index;
index--;
}
return index;
}
bool isVectorValid(bierwirth& v, int nbPiece) {
vector<int> count(nbPiece);
std::fill(count.begin(), count.end(), 0);
......
......
......@@ -8,31 +8,26 @@
using namespace std;
int main() {
srand(2410557);
srand(21058497);
t_graphe graph;
graph = lecture_fichier("la01.txt");
affiche_taches(graph);
//bierwirth v{0, 0, 0, 1, 1, 1, 2, 2, 2};
int best = INT16_MAX;
for (int i = 0; i < 100; i++)
{
bierwirth v = generateVector(graph.nb_pieces, graph.nb_machines);
solution_t sol = evaluer(v, graph);
affiche_solution(sol);
auto solRech = solution::rechercheLocale(v, graph, 1000);
cout << endl << endl << endl;
affiche_solution(sol);
/*
bierwirth v{ 0, 0, 0, 1, 1, 1, 2, 2, 2 };
bierwirth v2 = v;
permutation(v, v2, { 0,0 }, { 1,0 }, 3, 3);
utils::print(v);
utils::print(v2);
*/
if (solRech.cost < best) {
best = solRech.cost;
}
}
cout << best << endl;
return 0;
......
......
......@@ -10,24 +10,12 @@ solution_t solution::rechercheLocale(bierwirth& v, t_graph& graph, int maxIterat
pr_t jFather = solutionEvaluated.father[j.piece][j.rang];
bierwirth vInput = v;
bierwirth vOpti = v;
int iteration = 0;
while ((jFather.piece != -1 && jFather.rang != -1) && iteration < maxIteration) {
cout << iteration << endl;
while (iteration < maxIteration && (jFather.piece != -1 && jFather.rang != -1)) {
if (graph.mach[j.piece][j.rang] == graph.mach[jFather.piece][jFather.rang]) {
permutation(vInput, vOpti, j, jFather, graph.nb_pieces, graph.nb_machines);
if (!isVectorValid(vOpti, graph.nb_pieces)) {
cout << "Vector vOpti invalid" << endl;
utils::print(vInput);
utils::print(vOpti);
break;
}
solutionOpti = evaluer(vOpti, graph);
cout << "Cost found : " << solutionOpti.cost << endl;
if (solutionOpti.cost < solutionEvaluated.cost) {
cout << "NEW BEST : " << solutionOpti.cost << endl;
vInput = vOpti;
solutionEvaluated = solutionOpti;
j = solutionEvaluated.lastFather;
......
......
......@@ -17,3 +17,14 @@ void utils::print(std::vector<int> v)
}
cout << endl << endl;
}
void utils::print2(std::vector<int> v1, std::vector<int> v2)
{
for (size_t i = 0; i < v1.size(); i++)
{
cout << i << " : " << v1[i] << " " << v2[i] << endl;
}
cout << endl << endl;
}
......@@ -10,7 +10,7 @@ static class utils
public:
static int random(int a, int b);
static void print(std::vector<int> v);
static void print2(std::vector<int> v1, std::vector<int> v2);
};
No preview for this file type
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