代码拉取完成,页面将自动刷新
from Topology_zoo import get_source_nodes
import subprocess, sys
from concurrent.futures import ThreadPoolExecutor, as_completed
class Multi_scenario_simulation():
def __init__(self, 先验拥塞概率, n_samples, 进程数):
self.先验拥塞概率 = 先验拥塞概率
self.n_samples = n_samples
self.进程数 = 进程数
self.拓扑名称 = ['Japan']
self.label = ['DR', 'FPR', 'F1', 'F2']
self.prop = 0.01
def 获取各拓扑的源节点列表(self):
# 列举每个拓扑对应的源节点列表
源节点列表 = {}
for name in self.拓扑名称:
print(f"\r 正在获取{name} 的源节点列表 ", end="")
源节点列表[name] = get_source_nodes(name)
print(f"\r {name} 的源节点 共有 {len(源节点列表[name])} 个")
print(f"\r {源节点列表}")
return 源节点列表
def execute_command(prob, bias, key, value, seed_n):
for cnt in range(len(value)):
# 构建命令行参数
for seed_ in range(int(seed_n), int(seed_n)+30):
command = ["python3", 'mulitprocess_heu.py', str(prob), str(bias), str(seed_), key] + [str(i) for i in value[cnt]]
subprocess.run(command)
if __name__ == '__main__':
prob = sys.argv[1]
bias = sys.argv[2]
seed_n = sys.argv[3]
print("bias", bias, 'seed_n', seed_n)
Mss = Multi_scenario_simulation(0.1, 10, 1)
源节点列表 = Mss.获取各拓扑的源节点列表()
max_workers = 10 # 设置并发执行的最大任务数量
with ThreadPoolExecutor(max_workers=max_workers) as executor:
futures = {executor.submit(execute_command, prob, bias, key, value, seed_n): (key, value) for key, value in 源节点列表.items()}
for future in as_completed(futures):
key, value = futures[future]
try:
future.result()
except Exception as e:
print(f'An exception occurred: {e}')
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。