增加了所有解的分布图
This commit is contained in:
parent
17da0c8d16
commit
8b740e2f04
36
main.py
36
main.py
|
|
@ -7,7 +7,6 @@ from GA import GA
|
||||||
from Instance import *
|
from Instance import *
|
||||||
from NSGA2 import NSGA2
|
from NSGA2 import NSGA2
|
||||||
|
|
||||||
|
|
||||||
# 绘制甘特图
|
# 绘制甘特图
|
||||||
def Gantt(Machines):
|
def Gantt(Machines):
|
||||||
M = ['red', 'blue', 'yellow', 'orange', 'green', 'palegoldenrod', 'purple', 'pink', 'Thistle', 'Magenta',
|
M = ['red', 'blue', 'yellow', 'orange', 'green', 'palegoldenrod', 'purple', 'pink', 'Thistle', 'Magenta',
|
||||||
|
|
@ -29,7 +28,6 @@ def Gantt(Machines):
|
||||||
plt.savefig('优化后排程方案的甘特图.png')
|
plt.savefig('优化后排程方案的甘特图.png')
|
||||||
plt.show()
|
plt.show()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
# 初始化参数
|
# 初始化参数
|
||||||
g = GA()
|
g = GA()
|
||||||
|
|
@ -44,10 +42,18 @@ if __name__ == '__main__':
|
||||||
Optimal_solutions = [] # 存储非支配解
|
Optimal_solutions = [] # 存储非支配解
|
||||||
Optimal_fit_values = [] # 存储非支配解的目标值
|
Optimal_fit_values = [] # 存储非支配解的目标值
|
||||||
|
|
||||||
|
# 新增:用于存储所有代的所有解
|
||||||
|
all_solutions = [] # 存储所有个体(染色体)
|
||||||
|
all_fitnesses = [] # 存储所有个体的目标值
|
||||||
|
|
||||||
for i in range(g.Max_Itertions):
|
for i in range(g.Max_Itertions):
|
||||||
print(f"iter_{i} start!")
|
print(f"iter_{i} start!")
|
||||||
Fit = g.fitness(C, J, Processing_time, M_num, O_num)
|
Fit = g.fitness(C, J, Processing_time, M_num, O_num)
|
||||||
|
|
||||||
|
# 记录当前代的所有解
|
||||||
|
all_solutions.extend(C)
|
||||||
|
all_fitnesses.extend(Fit)
|
||||||
|
|
||||||
# 非支配排序
|
# 非支配排序
|
||||||
rank = nsga2.fast_non_dominated_sort(Fit)
|
rank = nsga2.fast_non_dominated_sort(Fit)
|
||||||
current_non_dominated = [C[j] for j in range(len(C)) if rank[j] == 0]
|
current_non_dominated = [C[j] for j in range(len(C)) if rank[j] == 0]
|
||||||
|
|
@ -128,15 +134,23 @@ if __name__ == '__main__':
|
||||||
print(f"\n选中解的目标值: (最大完工时间: {final_fitness[0]}, 负载标准差: {final_fitness[1]:.2f})")
|
print(f"\n选中解的目标值: (最大完工时间: {final_fitness[0]}, 负载标准差: {final_fitness[1]:.2f})")
|
||||||
Gantt(d.Machines)
|
Gantt(d.Machines)
|
||||||
|
|
||||||
# 绘制帕累托前沿
|
# 绘制帕累托前沿(非支配解)
|
||||||
if Optimal_fit_values:
|
if Optimal_fit_values:
|
||||||
plt.figure()
|
plt.figure(figsize=(10, 6))
|
||||||
cmax = [fit[0] for fit in Optimal_fit_values]
|
cmax_nd = [fit[0] for fit in Optimal_fit_values]
|
||||||
load_std = [fit[1] for fit in Optimal_fit_values]
|
load_std_nd = [fit[1] for fit in Optimal_fit_values]
|
||||||
plt.scatter(cmax, load_std, color='red')
|
plt.scatter(cmax_nd, load_std_nd, color='red', label='Non-dominated solutions', zorder=5)
|
||||||
plt.title('ParetoFront')
|
|
||||||
plt.xlabel('maxtime')
|
# 绘制所有解的点图(所有代的所有个体)
|
||||||
plt.ylabel('standard deviation')
|
if all_fitnesses:
|
||||||
|
cmax_all = [fit[0] for fit in all_fitnesses]
|
||||||
|
load_std_all = [fit[1] for fit in all_fitnesses]
|
||||||
|
plt.scatter(cmax_all, load_std_all, color='blue', alpha=0.5, label='All solutions', zorder=1)
|
||||||
|
|
||||||
|
plt.title('All Solutions and Pareto Front')
|
||||||
|
plt.xlabel('Max Completion Time (Cmax)')
|
||||||
|
plt.ylabel('Load Standard Deviation')
|
||||||
|
plt.legend()
|
||||||
plt.grid(True)
|
plt.grid(True)
|
||||||
plt.savefig('pareto.png')
|
plt.savefig('all_solutions_pareto.png')
|
||||||
plt.show()
|
plt.show()
|
||||||
Loading…
Reference in New Issue