You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I want to run multiple optimizers for a problem and each to have a time terminator, but when i use term_dict as the examples say most of the time used for the first algorithm and almost nothing for the rest of them.
(Using multiple dicts doesnt help)
Steps To Reproduce
import time
import numpy as np
from mealpy import FloatVar, GA, PSO, DE, AOA
There is a huge different between using time.time() and time.perf_counter(). We use time.perf_counter() in the search process. So when you use time.time() to wrap the outside computation, it will show the difference. Also, the time.time() will be effect when you are running multiple processes like checking website, opening word, other program.
Description of the bug
I want to run multiple optimizers for a problem and each to have a time terminator, but when i use term_dict as the examples say most of the time used for the first algorithm and almost nothing for the rest of them.
![image](https://private-user-images.githubusercontent.com/38087747/400169678-8e6d2ba2-1a5a-4103-88d6-3e6a0425e970.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyODk4NjUsIm5iZiI6MTczOTI4OTU2NSwicGF0aCI6Ii8zODA4Nzc0Ny80MDAxNjk2NzgtOGU2ZDJiYTItMWE1YS00MTAzLTg4ZDYtM2U2YTA0MjVlOTcwLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjExVDE1NTkyNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWQwNTA3YWUzYmYzMDE0M2Y0ODFiMmJkNWRlY2I2ODQ5NGY0ZjJiNjIzOGFiMmE5Mjc4MjNhMzVjY2ZiNjEwOWEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.m7t75Xp3MaZ5vFwuJjaXtAJxkzH8n5o33Lp7EXxz2cE)
![image](https://private-user-images.githubusercontent.com/38087747/400169694-1da97e15-ec4f-4ace-ab79-9c15f1df0eb8.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyODk4NjUsIm5iZiI6MTczOTI4OTU2NSwicGF0aCI6Ii8zODA4Nzc0Ny80MDAxNjk2OTQtMWRhOTdlMTUtZWM0Zi00YWNlLWFiNzktOWMxNWYxZGYwZWI4LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjExVDE1NTkyNVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTdlOThhYzQ3M2I1MmNkYjc2MmZiMmEwOTljMWNhNjFkMmYxM2RhMTJjNThiZWEwMGEwNmNkYjZkNDhlMGM5NDImWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.gU2azBSdOrKaDCS8TAtZsp-6lhYN3ENar9_MgSVsU-E)
![image](https://private-user-images.githubusercontent.com/38087747/400170130-fa2720fa-7113-4337-90d1-6b38e1e3853d.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MzkyODk4NjYsIm5iZiI6MTczOTI4OTU2NiwicGF0aCI6Ii8zODA4Nzc0Ny80MDAxNzAxMzAtZmEyNzIwZmEtNzExMy00MzM3LTkwZDEtNmIzOGUxZTM4NTNkLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMTElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjExVDE1NTkyNlomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWRiOWVmMjNkMGQxNGUyYTY5NWQ5NGY3ZWJlYTdhMTQ2MjZmM2UzYWE0OWM0ODlmYmYwNjViOTZiOGMzMTE3NWEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.ENLI2EtcleHT2MWq426MKS6iF4g7Xcyhu5lYGbOJAIg)
(Using multiple dicts doesnt help)
Steps To Reproduce
import time
import numpy as np
from mealpy import FloatVar, GA, PSO, DE, AOA
Objective function
def objective_func(solution):
return np.sum(solution**2)
Problem definition
problem_dict = {
"obj_func": objective_func,
"bounds": FloatVar(lb=[-100] * 30, ub=[100] * 30),
"minmax": "min",
}
term_dict = {
"max_time": 10 # seconds to run this algorithm only
}
Iter=1500
Pop=50
Run Genetic Algorithm
start_time = time.time()
optimizer_ga = GA.BaseGA(epoch=Iter, pop_size=Pop, pc=0.85, pm=0.1)
optimizer_ga.solve(problem_dict, termination=term_dict)
ga_runtime = time.time() - start_time
print("\nGenetic Algorithm:")
print(f"Best Solution: {optimizer_ga.g_best.solution}")
print(f"Best Fitness: {optimizer_ga.g_best.target.fitness}")
print(f"Runtime: {ga_runtime:.4f} seconds")
Run Particle Swarm Optimization
start_time = time.time()
optimizer_pso = PSO.OriginalPSO(epoch=Iter, pop_size=Pop)
optimizer_pso.solve(problem_dict, termination=term_dict)
pso_runtime = time.time() - start_time
print("\nParticle Swarm Optimization:")
print(f"Best Solution: {optimizer_pso.g_best.solution}")
print(f"Best Fitness: {optimizer_pso.g_best.target.fitness}")
print(f"Runtime: {pso_runtime:.4f} seconds")
Run Differential Evolution
start_time = time.time()
optimizer_de = AOA.OriginalAOA(epoch=Iter, pop_size=Pop, wf=0.8, cr=0.9)
optimizer_de.solve(problem_dict, termination=term_dict)
de_runtime = time.time() - start_time
print("\nDifferential Evolution:")
print(f"Best Solution: {optimizer_de.g_best.solution}")
print(f"Best Fitness: {optimizer_de.g_best.target.fitness}")
print(f"Runtime: {de_runtime:.4f} seconds")
Additional Information
i use mealpy 3.0.1
The text was updated successfully, but these errors were encountered: