遗传算法001

This commit is contained in:
Cricial
2025-10-18 16:16:05 +08:00
parent 91f2122b65
commit dfd5c5b32d
49 changed files with 8473 additions and 1825 deletions

View File

@@ -32,7 +32,7 @@ class ControllerDB:
dct_para_in_test = dct_conf_experiment['test'] if self.is_test else dct_conf_experiment['not_test']
self.dct_parameter = {'meta_seed': dct_conf_experiment['meta_seed'], **dct_para_in_test}
print(self.dct_parameter)
# print(self.dct_parameter)
# 0, not reset; 1, reset self; 2, reset all
self.reset_flag = reset_flag
self.is_exist = False
@@ -328,7 +328,7 @@ class ControllerDB:
)).scalar()
# 控制 n_sample数量 作为后面的参数
n_sample = 0 if res is None else res
print(f'There are a total of {n_sample} samples.')
# print(f'There are a total of {n_sample} samples.')
# 查找 is_done_flag = -1 也就是没有运行的 样本 运行后会改为0
res = db_session.execute(
text(f"SELECT id FROM {self.db_name_prefix}_sample "
@@ -340,15 +340,18 @@ class ControllerDB:
@staticmethod
def select_random_sample(lst_s_id):
while 1:
if len(lst_s_id) == 0:
return None
s_id = random.choice(lst_s_id)
lst_s_id.remove(s_id)
res = db_session.query(Sample).filter(Sample.id == int(s_id),
Sample.is_done_flag == -1)
temp_lst = lst_s_id[:] # 复制列表
while temp_lst:
s_id = random.choice(temp_lst)
temp_lst.remove(s_id) # 从临时列表删除
res = db_session.query(Sample).filter(
Sample.id == int(s_id),
Sample.is_done_flag == -1
)
if res.count() == 1:
return res[0]
# 尝试完所有样本都没找到
return None
def fetch_a_sample(self, s_id=None):
# 由Computation 调用 返回 sample对象 同时给出 2中 指定访问模式 抓取特定的 样本 通过s_id