Set initial bestSolution to all INT_MAX and if all INT_MAX set
bestSolutionLength to 17
This commit is contained in:
parent
5398b9dccd
commit
029ce6264f
13
supervisor.c
13
supervisor.c
@ -6,6 +6,7 @@
|
|||||||
*/
|
*/
|
||||||
|
|
||||||
#include "common.h"
|
#include "common.h"
|
||||||
|
#include <limits.h>
|
||||||
|
|
||||||
static const char *pname;
|
static const char *pname;
|
||||||
|
|
||||||
@ -67,7 +68,7 @@ void initCircBuf()
|
|||||||
}
|
}
|
||||||
|
|
||||||
for (int i = 0; i < MAX_ITEMS; i++) {
|
for (int i = 0; i < MAX_ITEMS; i++) {
|
||||||
bestSolution[i] = -1;
|
bestSolution[i] = INT_MAX;
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -107,22 +108,26 @@ void getSolution(sem_t *sUsedSpace, sem_t *sFreeSpace)
|
|||||||
int newSolutionLength = 0;
|
int newSolutionLength = 0;
|
||||||
|
|
||||||
// Compute length of current bestSolution
|
// Compute length of current bestSolution
|
||||||
if (bestSolution[0] != -1) {
|
if ((bestSolution[0] != -1) && (bestSolution[0] != INT_MAX)) {
|
||||||
for (int i = 0; i < MAX_ITEMS; i++) {
|
for (int i = 0; i < MAX_ITEMS; i++) {
|
||||||
if (bestSolution[i] == -1) {
|
if (bestSolution[i] == -1) {
|
||||||
bestSolutionLength = i;
|
bestSolutionLength = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
} else if (bestSolution[0] == INT_MAX) {
|
||||||
|
bestSolutionLength = 17;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Compute length of newSolution
|
// Compute length of newSolution
|
||||||
|
if (solution[0] != -1) {
|
||||||
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) {
|
||||||
newSolutionLength = i+1;
|
newSolutionLength = i;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (newSolutionLength == 0) {
|
if (newSolutionLength == 0) {
|
||||||
printf("[%s] The graph is acyclic!\n", pname);
|
printf("[%s] The graph is acyclic!\n", pname);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user