Calculate bestSolutionLength correctly

This commit is contained in:
zenon 2018-06-08 11:21:03 +02:00
parent 72da8e371b
commit 5398b9dccd

View File

@ -106,12 +106,17 @@ void getSolution(sem_t *sUsedSpace, sem_t *sFreeSpace)
int bestSolutionLength = 0; int bestSolutionLength = 0;
int newSolutionLength = 0; int newSolutionLength = 0;
for (int i = 0; i < MAX_ITEMS; i++) { // Compute length of current bestSolution
if ((bestSolution[i] == -1) && (i != 0)) { if (bestSolution[0] != -1) {
bestSolutionLength = i+1; for (int i = 0; i < MAX_ITEMS; i++) {
break; if (bestSolution[i] == -1) {
bestSolutionLength = i;
break;
}
} }
} }
// Compute length of newSolution
for (int i = 0; i < MAX_ITEMS; i++) { for (int i = 0; i < MAX_ITEMS; i++) {
if ((solution[i] == -1) && (i != 0)) { if ((solution[i] == -1) && (i != 0)) {
newSolutionLength = i+1; newSolutionLength = i+1;
@ -121,6 +126,7 @@ void getSolution(sem_t *sUsedSpace, sem_t *sFreeSpace)
if (newSolutionLength == 0) { if (newSolutionLength == 0) {
printf("[%s] The graph is acyclic!\n", pname); printf("[%s] The graph is acyclic!\n", pname);
quit = 1;
return; return;
} }