遗传算法

This commit is contained in:
Cricial
2026-03-15 17:15:30 +08:00
parent 03ac80715f
commit a69e272e43
27 changed files with 934 additions and 191 deletions

View File

@@ -3,26 +3,29 @@ from deap import creator, base, tools
from evaluate_func import fitness
def creating():
if "FitnessMax" not in creator.__dict__:
creator.create("FitnessMax", base.Fitness, weights=(1.0,))
if "FitnessMin" not in creator.__dict__:
creator.create("FitnessMin", base.Fitness, weights=(-1.0,))
if "Individual" not in creator.__dict__:
creator.create("Individual", list, fitness=creator.FitnessMax)
creator.create("Individual", list, fitness=creator.FitnessMin)
toolbox = base.Toolbox()
# 基因注册
toolbox.register("n_max_trial", random.randint, 1, 60)
toolbox.register("prf_size", random.uniform, 0.0, 1.0)
toolbox.register("prf_conn", random.uniform, 0.0, 1.0)
# ==============================
# 基因注册(修改后)
# ==============================
toolbox.register("n_max_trial", random.randint, 50, 200)
toolbox.register("prf_size", random.uniform, 0.05, 0.95)
toolbox.register("prf_conn", random.uniform, 0.05, 0.95)
toolbox.register("cap_limit_prob_type", random.randint, 0, 1)
toolbox.register("cap_limit_level", random.randint, 5, 80)
toolbox.register("diff_new_conn", random.uniform, 0.0, 1.0)
toolbox.register("netw_prf_n", random.randint, 1, 20)
toolbox.register("s_r", random.uniform, 0.01, 0.5)
toolbox.register("S_r", random.uniform, 0.5, 1.0)
toolbox.register("x", random.uniform, 0.0, 1)
toolbox.register("k", random.uniform, 0.1, 5.0)
toolbox.register("production_increase_ratio", random.uniform, 1, 5.0)
toolbox.register("cap_limit_level", random.randint, 10, 50)
toolbox.register("diff_new_conn", random.uniform, 0.05, 0.95)
toolbox.register("netw_prf_n", random.randint, 3, 15)
toolbox.register("s_r", random.uniform, 0.05, 0.4)
toolbox.register("S_r", random.uniform, 0.8, 2.5)
toolbox.register("x", random.uniform, 0.1, 0.9)
toolbox.register("k", random.uniform, 0.2, 4.0)
toolbox.register("production_increase_ratio", random.uniform, 0.3, 3.0)
# 个体与种群注册
toolbox.register(