@@ -99,11 +99,11 @@ class Algorithm():
def progress(self):
- logging.info("-- %s evaluation n°%s of %s, %s%% - %s" % (type(self).__name__, self.numberOfEvaluations, self.maxEvalutations, "{0:.2f}".format((self.numberOfEvaluations) / self.maxEvalutations * 100.), self.bestSolution.fitness()))
+ logging.info("-- %s evaluation n°%s of %s (%s%%) - BEST SCORE %s" % (type(self).__name__, self.numberOfEvaluations, self.maxEvalutations, "{0:.2f}".format((self.numberOfEvaluations) / self.maxEvalutations * 100.), self.bestSolution.fitness()))
def information(self):
- logging.info("-- Best solution %s with score of %s" % (self.bestSolution, self.bestSolution.fitness()))
+ logging.info("-- Best solution %s - SCORE %s" % (self.bestSolution, self.bestSolution.fitness()))
def __str__(self):
@@ -30,7 +30,7 @@ class LocalSearch(Algorithm):
self.numberOfEvaluations += 1
self.progress()
- logging.info("-- Found %s with score of %s" % (newSolution, newSolution.fitness()))
+ logging.info("---- Current %s - SCORE %s" % (newSolution, newSolution.fitness()))
# stop algorithm if necessary
if self.numberOfEvaluations >= self.maxEvalutations:
@@ -34,7 +34,7 @@ def main():
algo = ILS(init, evaluatorExample, operators, policy, validator, True)
- bestSol = algo.run(100000)
+ bestSol = algo.run(1000)
print("Found ", bestSol)
@@ -26,14 +26,15 @@ class Policy():
operator = self.select()
- logging.info("-- Applying %s on %s" % (type(operator).__name__, solution))
+ logging.info("---- Applying %s on %s" % (type(operator).__name__, solution))
# check kind of operator
if operator.kind == Operator.CROSSOVER:
- return operator.apply(solution, secondSolution)
+ newSolution = operator.apply(solution, secondSolution)
if operator.kind == Operator.MUTATOR:
- return operator.apply(solution)
+ newSolution = operator.apply(solution)
- # by default
+ logging.info("---- Obtaining %s" % (solution))
+
+ return newSolution
@@ -27,6 +27,8 @@ class BinarySolution(Solution):
Use of validator to generate valid random solution
"""
+ self.data = np.random.randint(2, size=self.size)
while not self.isValid(_validator):
self.data = np.random.randint(2, size=self.size)
@@ -34,5 +36,5 @@ class BinarySolution(Solution):
- return "Binary solution %s of size %s" % (self.data, self.size)
+ return "Binary solution %s" % (self.data)
@@ -27,6 +27,8 @@ class CombinatoryIntegerSolution(Solution):
+ self.data = np.random.shuffle(np.arange(self.size))
self.data = np.random.shuffle(np.arange(self.size))
@@ -34,5 +36,5 @@ class CombinatoryIntegerSolution(Solution):
- return "Combinatory integer solution %s of size %s" % (self.data, self.size)
+ return "Combinatory integer solution %s" % (self.data)
@@ -27,6 +27,8 @@ class IntegerSolution(Solution):
+ self.data = np.random.randint(self.size, size=self.size)
self.data = np.random.randint(self.size, size=self.size)
@@ -34,5 +36,5 @@ class IntegerSolution(Solution):
- return "Integer solution %s of size %s" % (self.data, self.size)
+ return "Integer solution %s" % (self.data)