From 029ce6264f0cf3ec7733ded30f09f9c141b47ae6 Mon Sep 17 00:00:00 2001 From: zenon Date: Fri, 8 Jun 2018 11:31:31 +0200 Subject: [PATCH] Set initial bestSolution to all INT_MAX and if all INT_MAX set bestSolutionLength to 17 --- supervisor.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/supervisor.c b/supervisor.c index 7d0369a..385acc7 100644 --- a/supervisor.c +++ b/supervisor.c @@ -6,6 +6,7 @@ */ #include "common.h" +#include static const char *pname; @@ -67,7 +68,7 @@ void initCircBuf() } for (int i = 0; i < MAX_ITEMS; i++) { - bestSolution[i] = -1; + bestSolution[i] = INT_MAX; } return; } @@ -107,20 +108,24 @@ void getSolution(sem_t *sUsedSpace, sem_t *sFreeSpace) int newSolutionLength = 0; // 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++) { if (bestSolution[i] == -1) { bestSolutionLength = i; break; } } + } else if (bestSolution[0] == INT_MAX) { + bestSolutionLength = 17; } // Compute length of newSolution - for (int i = 0; i < MAX_ITEMS; i++) { - if ((solution[i] == -1) && (i != 0)) { - newSolutionLength = i+1; - break; + if (solution[0] != -1) { + for (int i = 0; i < MAX_ITEMS; i++) { + if (solution[i] == -1) { + newSolutionLength = i; + break; + } } }