Skip to content

Commit

Permalink
Now sending and receiving proper data
Browse files Browse the repository at this point in the history
  • Loading branch information
antoniogi committed Nov 1, 2024
1 parent 33459fa commit d950627
Show file tree
Hide file tree
Showing 3 changed files with 10 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 @@ -36,7 +36,8 @@ def __init__(self):

def solve(self, solution):
val = random.randint(0, 1000000)
print("ProblemCristina. Solution found with value: " + str(val))
solution.setValue(val)
# print("ProblemCristina. Solution found with value: " + str(val))
return val

def extractSolution(self):
Expand Down
7 changes: 4 additions & 3 deletions src/SolverDAB.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,7 +297,7 @@ def createNewCandidate(self, probMatrix, totalSumGoodSolutions, topSolutions=Non
else:
if minVal > maxVal:
minVal, maxVal = maxVal, minVal
newVal = random.randint(minVal, maxVal)
newVal = random.randint(int(minVal), int(maxVal))

currentVal = parameters[i].get_value()
if newVal != currentVal:
Expand Down Expand Up @@ -405,9 +405,9 @@ def createNewCandidate(self, probMatrix, totalSumGoodSolutions, topSolutions):
minVal = maxVal - 1
if minVal > maxVal:
minVal, maxVal = maxVal, minVal
newVal = random.randint(minVal, maxVal)
newVal = random.randint(int(minVal), int(maxVal))
while newVal == currentVal:
newVal = random.randint(minVal, maxVal)
newVal = random.randint(int(minVal), int(maxVal))
p.set_value(newVal)
#Here: go through the parameters of the solution and change those
#parameters considering the min and max values of each parameter,
Expand Down Expand Up @@ -758,6 +758,7 @@ def receiveSolutions(self):
u.logger.error("DRIVER (comm). " + str(e) + " line: " +
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):
#Add the solution to the list of best solutions (the method will implement the
#priority list)
Expand Down
5 changes: 4 additions & 1 deletion src/Worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ def run(self, infile, cfile):
req.wait(status)

u.logger.info("WORKER (" + str(self.__rank) +
") has received a solution from bee " +
") has received a solution to evaluate from bee " +
str(agent_idx[0]))
solution.setParametersValues(buff)

Expand All @@ -139,6 +139,9 @@ def run(self, infile, cfile):

u.logger.debug("WORKER (" + str(self.__rank) +
"). Buffer size: " + str(len(buff)))
u.logger.debug("WORKER (" + str(self.__rank) +
"- " + str(agent_idx) + ") found solution with value "
+ str(solution_value[0]))

self.__comm.Send(buff, 0, u.tags.COMMSOLUTION)
self.__comm.Send(solution_value, 0, u.tags.COMMSOLUTION)
Expand Down

0 comments on commit d950627

Please sign in to comment.