From ac7e93bd2698d2e6b186babb4338983a9decc3de Mon Sep 17 00:00:00 2001 From: Antonio Gomez Date: Fri, 15 Nov 2024 07:00:44 -0800 Subject: [PATCH] Fix problem with minimization functions that reach 0 value --- src/ProblemCristina.py | 3 ++- src/SolutionsQueue.py | 10 ++++++++-- src/SolverDAB.py | 4 ++-- 3 files changed, 12 insertions(+), 5 deletions(-) diff --git a/src/ProblemCristina.py b/src/ProblemCristina.py index 9655147..67e2281 100755 --- a/src/ProblemCristina.py +++ b/src/ProblemCristina.py @@ -37,7 +37,8 @@ def __init__(self): def solve(self, solution): val = random.randint(0, 1000000) solution.setValue(val) -# print("ProblemCristina. Solution found with value: " + str(val)) +# if val==0: +# print("ProblemCristina. Solution found with value: " + str(val)) return val def extractSolution(self): diff --git a/src/SolutionsQueue.py b/src/SolutionsQueue.py index e42521b..a006177 100755 --- a/src/SolutionsQueue.py +++ b/src/SolutionsQueue.py @@ -325,7 +325,10 @@ def GetTotalSolutionsValues(self): total_sum = 0.0 for i in range(self.qSize()): sol_tuple = self.__queue[i] - total_sum += 1.0 / float(sol_tuple[1]) + if float(sol_tuple[1])==0.0: + total_sum += util.infinity/100 + else: + total_sum += 1.0 / float(sol_tuple[1]) return total_sum """ @@ -338,7 +341,10 @@ def GetTupleOnPriorityByValue(self, value): total_val = self.GetTotalSolutionsValues() for i in range(self.qSize()): if util.objective == util.objectiveType.MINIMIZE: - temp_sum += float(1.0 / float(self.__queue[i][1])) + if float(self.__queue[i][1])==0.0: + temp_sum += util.infinity + else: + temp_sum += float(1.0 / float(self.__queue[i][1])) else: temp_sum += float(self.__queue[i][1]) util.logger.debug("TempSum: " + str(temp_sum) + "/" + diff --git a/src/SolverDAB.py b/src/SolverDAB.py index 55a4aff..ac223b3 100644 --- a/src/SolverDAB.py +++ b/src/SolverDAB.py @@ -758,7 +758,7 @@ def receiveSolutions(self): str(sys.exc_info()[2].tb_lineno)) try: u.logger.info("SOLVERDAB. Received solution with value " + str(solVal[0]) + " from bee " + str(beeIdx[0])) - if (float(solVal[0]) > 0.0 and float(solVal[0]) < u.infinity / 100): + if (float(solVal[0]) >= 0.0 and float(solVal[0]) < u.infinity / 100): #Add the solution to the list of best solutions (the method will implement the #priority list) solutionTemp = None @@ -837,7 +837,7 @@ def receiveSolutions(self): self.__finishedSolutions.PutSolution(solutionTemp, solVal[0], beeIdx[0]) u.logger.info("DRIVER. Solution (value " + str(solVal[0]) + ") added to the list of finished solutions") - if (float(solVal[0]) > 0.0 and float(solVal[0])<(u.infinity/100.0)): + if (float(solVal[0]) >= 0.0 and float(solVal[0])<(u.infinity/100.0)): if isNewBest: parameters = solutionTemp.getParameters() if (self.__useMatrix):