Commit 63f2f22d authored by Sinaro LY's avatar Sinaro LY
Browse files

Merge branch 'sinaro' of https://gitlab.isima.fr/mapoulain1/oad-tp2 into sinaro

parents 11d59dc6 b12cc989
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
......@@ -36,6 +36,9 @@ t_graphe lecture_fichier(string nom_fichier)
void affiche_taches(t_graphe graphe)
{
cout << "graphe : " << endl;
cout << "---------------------"<< endl;
for (int i = 0; i < graphe.nb_pieces; i++)
{
cout << "piece : " << i << endl;
......@@ -46,4 +49,5 @@ void affiche_taches(t_graphe graphe)
cout << endl;
}
cout << "---------------------" << endl;
}
\ No newline at end of file
......@@ -10,6 +10,7 @@ using namespace std;
int main() {
srand(1000074);
t_graphe graphe;
graphe = lecture_fichier("cours.txt");
affiche_taches(graphe);
......@@ -17,6 +18,12 @@ int main() {
solution_t sol = evaluer(v, graphe);
affiche_solution(sol);
//t_graphe graphe;
//graphe = lecture_fichier("la01.txt");
//affiche_taches(graphe);
//solution_t sol = evaluer(generateVector(graphe.nb_pieces, graphe.nb_machines), graphe);
//affiche_solution(sol);
return 0;
}
\ No newline at end of file
......@@ -10,10 +10,8 @@ solution_t evaluer(bierwirth v, t_graphe graphe)
int pos;
int j;
int val;
//pr_t finpere;
sol.cost = -INT_FAST32_MAX;
int m[SOLUTION_MAX_SIZE][SOLUTION_MAX_SIZE];
//pr_t pere[SOLUTION_MAX_SIZE][SOLUTION_MAX_SIZE];
int np[SOLUTION_MAX_SIZE];
pr_t nm[SOLUTION_MAX_SIZE];
......@@ -35,28 +33,24 @@ solution_t evaluer(bierwirth v, t_graphe graphe)
for (int i = 0; i < (n*graphe.nb_machines); i++)
{
j = v[i];
cout << "j : " << j << endl;
//np[j] += 1;
npj = np[j];
np[j] += 1;
machine = graphe.mach[j][npj];
if (npj > 0)
if (npj == 0)
{
if (m[j][npj - 1] + graphe.d[j][npj - 1] > m[j][npj])
{
m[j][npj] = m[j][npj - 1] + graphe.d[j][npj - 1];
sol.father[j][npj].piece = j;
sol.father[j][npj].rang = npj - 1;
}
m[j][npj] = 0;
sol.father[j][npj] = { -1, -1 };
}
else
{
m[j][npj] = 0;
sol.father[j][npj] = { 0, 0 };
m[j][npj] = m[j][npj - 1] + graphe.d[j][npj - 1];
sol.father[j][npj].piece = j;
sol.father[j][npj].rang = npj-1;
}
//cout << machine << endl;
if ((nm[machine].piece != 0) || (nm[machine].rang != 0))
{
......@@ -72,24 +66,31 @@ solution_t evaluer(bierwirth v, t_graphe graphe)
}
}
nm[machine].piece = j;
nm[machine].rang = np[j];
cout << "npj : " << np[j] << endl;
nm[machine].rang = npj;
if (np[j] == graphe.nb_machines-1)
if (npj == graphe.nb_machines-1)
{
cout << "lastFather" << endl;
if (m[j][npj] + graphe.d[j][npj] > sol.cost)
{
sol.cost = m[j][npj] + graphe.d[j][npj];
sol.lastFather.piece = j;
sol.lastFather.rang = np[j];
sol.lastFather.rang = npj;
}
}
np[j] += 1;
}
pr_t cour = sol.lastFather;
int i = 0;
do
{
sol.ST[i] = m[cour.piece][cour.rang];
cour = sol.father[cour.piece][cour.rang];
++i;
} while ((cour.piece >= 0) && (cour.rang >= 0) && (i != 50));
return sol;
}
......@@ -101,25 +102,22 @@ void affiche_solution(solution_t sol)
do
{
cout << "cour piece : " << cour.piece << " cour rang : " << cour.rang << endl;
chemin[i] = cour;
cour = sol.father[cour.piece][cour.rang];
++i;
} while ((cour.piece != 0) && (cour.rang != 0) && (i != 50));
} while ((cour.piece >= 0) && (cour.rang >= 0) && (i != 50));
cout << "chemin : " << endl;
cout << "ordre des taches : " << endl;
for (int p = i-1; p > 1; p--)
for (int p = i-1; p >= 0; p--)
{
cout << "piece : " << chemin[p].piece << " rang : " << chemin[p].rang;
cout << "piece : " << chemin[p].piece << " | rang : " << chemin[p].rang << " | date de debut : " << sol.ST[p];
cout << endl;
}
cout << endl;
cout << "duree totale : " << sol.cost << endl;
}
void grasp(solution_t* sol, t_graph graphe, int sizeH, int best_cost)
......
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