Skip to content

Commit

Permalink
Fix problem with minimization functions that reach 0 value
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniogi committed Nov 15, 2024
1 parent 6eac9e8 commit ac7e93b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
3 changes: 2 additions & 1 deletion src/ProblemCristina.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
10 changes: 8 additions & 2 deletions src/SolutionsQueue.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""
Expand All @@ -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) + "/" +
Expand Down
4 changes: 2 additions & 2 deletions src/SolverDAB.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit ac7e93b

Please sign in to comment.