Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG]: Tabu search doesn't update correctly #163

Closed
ericho-bbai opened this issue Aug 20, 2024 · 2 comments · May be fixed by #164
Closed

[BUG]: Tabu search doesn't update correctly #163

ericho-bbai opened this issue Aug 20, 2024 · 2 comments · May be fixed by #164
Assignees
Labels
bug Something isn't working

Comments

@ericho-bbai
Copy link

ericho-bbai commented Aug 20, 2024

Description of the bug

The global and current best fitness stays the same during optimization. The issue is that TS.OriginalTS.pop needs to be updated so that the base Optimizer class can optimize properly.

Steps To Reproduce

Run tabu search example:

import numpy as np
from mealpy import FloatVar, TS

def objective_function(solution):
    res = np.sum(solution**2)
    return res

problem_dict = {
    "bounds": FloatVar(lb=(-10.,) * 2, ub=(10.,) * 2, name="delta"),
    "minmax": "min",
    "obj_func": objective_function,
}

model = TS.OriginalTS(epoch=10, pop_size=5, tabu_size = 3, neighbour_size = 7, perturbation_scale = 0.05)
g_best = model.solve(problem_dict)
print(f"Solution: {model.g_best.solution}, Fitness: {model.g_best.target.fitness}")

Output example:

2024/08/20 12:38:04 PM, INFO, mealpy.math_based.TS.OriginalTS: Solving single objective optimization problem.
2024/08/20 12:38:04 PM, INFO, mealpy.math_based.TS.OriginalTS: >>>Problem: P, Epoch: 1, Current best: 6.724059899786338, Global best: 6.724059899786338, Runtime: 0.00223 seconds
2024/08/20 12:38:04 PM, INFO, mealpy.math_based.TS.OriginalTS: >>>Problem: P, Epoch: 2, Current best: 6.724059899786338, Global best: 6.724059899786338, Runtime: 0.00223 seconds
2024/08/20 12:38:04 PM, INFO, mealpy.math_based.TS.OriginalTS: >>>Problem: P, Epoch: 3, Current best: 6.724059899786338, Global best: 6.724059899786338, Runtime: 0.00256 seconds
2024/08/20 12:38:04 PM, INFO, mealpy.math_based.TS.OriginalTS: >>>Problem: P, Epoch: 4, Current best: 6.724059899786338, Global best: 6.724059899786338, Runtime: 0.00130 seconds
2024/08/20 12:38:04 PM, INFO, mealpy.math_based.TS.OriginalTS: >>>Problem: P, Epoch: 5, Current best: 6.724059899786338, Global best: 6.724059899786338, Runtime: 0.00295 seconds
2024/08/20 12:38:04 PM, INFO, mealpy.math_based.TS.OriginalTS: >>>Problem: P, Epoch: 6, Current best: 6.724059899786338, Global best: 6.724059899786338, Runtime: 0.00217 seconds
2024/08/20 12:38:04 PM, INFO, mealpy.math_based.TS.OriginalTS: >>>Problem: P, Epoch: 7, Current best: 6.724059899786338, Global best: 6.724059899786338, Runtime: 0.00121 seconds
2024/08/20 12:38:04 PM, INFO, mealpy.math_based.TS.OriginalTS: >>>Problem: P, Epoch: 8, Current best: 6.724059899786338, Global best: 6.724059899786338, Runtime: 0.00115 seconds
2024/08/20 12:38:04 PM, INFO, mealpy.math_based.TS.OriginalTS: >>>Problem: P, Epoch: 9, Current best: 6.724059899786338, Global best: 6.724059899786338, Runtime: 0.00145 seconds
2024/08/20 12:38:04 PM, INFO, mealpy.math_based.TS.OriginalTS: >>>Problem: P, Epoch: 10, Current best: 6.724059899786338, Global best: 6.724059899786338, Runtime: 0.00098 seconds

Additional Information

No response

@ericho-bbai ericho-bbai added the bug Something isn't working label Aug 20, 2024
@thieu1995
Copy link
Owner

Hi @ericho-bbai ,
This is normal behaviours from weak algorithms.

@ericho-bbai
Copy link
Author

ericho-bbai commented Aug 29, 2024

Hello @thieu1995, please see the linked PR. Those changes fixed this issue for me. Since the BaseOptimizer uses self.pop to optimize, the tabu list needs to be part of self.pop in some way.

Also, what are some strong algorithms in your opinion?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants