代码拉取完成,页面将自动刷新
同步操作将从 朱洪君/monte-carlo-AGV 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
from model import model
from initial import initial_map,initial_agvplan
from change import switch_to_location,switch_to_xy
from f1score import F1score
import numpy as np
import openpyxl
def singleControl():
Special_structure = [[[[2, 8], 1, 1, 1], [[2, 11], 1, 1, 1], [[2, 14], 1, 1, 1]], [], [[[2, 1], 3, 2, 3]],
[[[10, 9], 9, 9, 4], [[10, 11], 9, 1, 0, 3, 3, 0], [[12, 9], 1, 9, 3, 0, 2, 0]],
[[[6, 6], 1, 3, 5], [[6, 12], 2, 2, 5], [[8, 19], 2, 1, 5], [[11, 4], 1, 3, 5],
[[11, 4], 4, 1, 5],
[[15, 19], 1, 2, 5]]] # 设置了6个白值,分别对应车道,出口卸货台,入口装货台,AGV停止区,货架,障碍物,通过2维矩阵和色块着色来绘制地图
MAP = initial_map(Special_structure)
AGV_PLAN = initial_agvplan(5, MAP,seed=5)
theory_total = 0
for key in AGV_PLAN.keys():
for i in range(len(AGV_PLAN[key]) - 1):
[des_x, des_y] = switch_to_xy(AGV_PLAN[key][i + 1])
[x, y] = switch_to_xy(AGV_PLAN[key][i])
if (x != des_x) & (y != des_y):
theory_total += abs(des_x - x) + abs(des_y - y) + 1
else:
theory_total += abs(des_x - x) + abs(des_y - y)
print("理论距离", theory_total)
for key in AGV_PLAN.keys():
print("AGV", key)
for j in AGV_PLAN[key]:
print(switch_to_xy(j))
safedistance=13
MAX_ITERATION=2
kwargs = {
'SAFEDISTANCE': safedistance,
'MAX_BACK_TIMES': 10,
'im_step': 5,
'im_self2other': 10,
'MAX_ITER': [30, 30, 50],
'DISPLAY': [0, 0],
'version': 1,
}
total_step = 0
total_cut = 0
total_avoid = 0
total_invalid=0
total_time = 0
total_finish = MAX_ITERATION
item_step_set = []
item_time_set = []
for i in range(MAX_ITERATION):
item_step, item_cut, item_avoid,item_invalid, finish = model(MAP, AGV_PLAN, **kwargs)
if finish[0] == 0:
item_time_set.append(finish[1])
item_step_set.append(item_step)
total_time += finish[1]
total_step += item_step
total_cut += item_cut
total_avoid += item_avoid
total_invalid+=item_invalid
else:
total_finish -= 1
variance_step = 0
for i in range(len(item_step_set)):
variance_step += pow((item_step_set[i] - total_step / total_finish), 2)
variance_time = 0
for i in range(len(item_time_set)):
variance_time += pow((item_time_set[i] - total_time / total_finish), 2)
print('-------------------------------')
print("安全距离", kwargs['SAFEDISTANCE'])
print("求解速度", total_time / total_finish)
print("解集质量", int(total_step / total_finish))
print("每轮实验平均无效选择次数",total_invalid/total_finish)
print("所有AGV平均干扰次数", total_cut / total_finish)
print("所有AGV平均避让次数", total_avoid / total_finish)
print("求解速度标准差", pow(variance_time / total_finish, 0.5))
print("解集质量标准差", pow(variance_step / total_finish, 0.5))
print("实验次数", total_finish)
print('-------------------------------')
def MainControl():
Special_structure = [[[[2, 8], 1, 1, 1], [[2, 11], 1, 1, 1], [[2, 14], 1, 1, 1]], [], [[[2, 1], 3, 2, 3]],
[[[10, 9], 9, 9, 4], [[10, 11], 9, 1, 0, 3, 3, 0], [[12, 9], 1, 9, 3, 0, 2, 0]],
[[[6, 6], 1, 3, 5], [[6, 12], 2, 2, 5], [[8, 19], 2, 1, 5], [[11, 4], 1, 3, 5], [[11, 4], 4, 1, 5],
[[15, 19], 1, 2, 5]]] # 设置了6个白值,分别对应车道,出口卸货台,入口装货台,AGV停止区,货架,障碍物,通过2维矩阵和色块着色来绘制地图
MAP=initial_map(Special_structure)
AGV_PLAN = initial_agvplan(5, MAP,seed=3)
theory_total=0
for key in AGV_PLAN.keys():
for i in range(len(AGV_PLAN[key])-1):
[des_x,des_y]=switch_to_xy(AGV_PLAN[key][i+1])
[x,y]=switch_to_xy(AGV_PLAN[key][i])
if (x!=des_x)&(y!=des_y):
theory_total+=abs(des_x - x) + abs(des_y - y)+1
else:
theory_total+=abs(des_x - x) + abs(des_y - y)
print("理论距离",theory_total)
MAX_ITERATION=5
print("--------------------新版本----------------------")
experiment_time=[]
experiment_step=[]
for m in range(11):
if m==0:
safedistance=0
elif 0<m<9:
safedistance=1+(m-1)*4
elif m==9:
safedistance=1+(m-2)*4+8
else:
safedistance=40
# safedistance=m
kwargs = {
'SAFEDISTANCE': safedistance,
'MAX_BACK_TIMES': 10,
'im_step': 5,
'im_self2other': 10,
'MAX_ITER': [30, 30, 50],
'DISPLAY': [0, 0],
'version': 1,
}
total_step=0
total_cut=0
total_avoid=0
total_invalid=0
total_time=0
total_finish=MAX_ITERATION
item_step_set=[]
item_time_set=[]
for i in range(MAX_ITERATION):
item_step, item_cut, item_avoid, item_invalid, finish = model(MAP, AGV_PLAN, **kwargs)
if finish[0]==0:
item_time_set.append(finish[1])
item_step_set.append(item_step)
total_time+=finish[1]
total_step+=item_step
total_cut+=item_cut
total_avoid+=item_avoid
total_invalid+=item_invalid
else:
total_finish-=1
variance_step = 0
for i in range(len(item_step_set)):
variance_step += pow((item_step_set[i] - total_step / total_finish), 2)
variance_time = 0
for i in range(len(item_time_set)):
variance_time += pow((item_time_set[i] - total_time / total_finish), 2)
experiment_step.append(int(total_step/total_finish))
experiment_time.append(total_time/total_finish)
print('-------------------------------')
print("安全距离",kwargs['SAFEDISTANCE'])
print("求解速度",total_time/total_finish)
print("解集质量",int(total_step/total_finish))
print("每轮实验平均无效选择次数", total_invalid / total_finish)
print("所有AGV平均干扰次数", total_cut / total_finish)
print("所有AGV平均避让次数", total_avoid / total_finish)
print("求解速度标准差", pow(variance_time/total_finish, 0.5))
print("解集质量标准差", pow(variance_step/total_finish, 0.5))
print("实验次数",total_finish)
print('-------------------------------')
wb=openpyxl.load_workbook('ex.xlsx')
sh=wb['ex1']
sh.cell(row=m+1,column=1).value=total_invalid / total_finish
sh.cell(row=m + 1, column=2).value = total_avoid / total_finish
sh.cell(row=m + 1, column=3).value=total_invalid / total_finish+total_avoid / total_finish
sh.cell(row=m + 1, column=4).value = int(total_step/total_finish)
wb.save('ex.xlsx')
max_step=max(experiment_step)
min_step=min(experiment_step)
max_time=max(experiment_time)
min_time=min(experiment_time)
experiment_step=np.array(experiment_step)
experiment_time=np.array(experiment_time)
epsilon=pow(10,-8)
experiment_step=np.ones(experiment_step.shape)-(experiment_step-min_step)/(max_step-min_step)+epsilon
experiment_time = np.ones(experiment_time.shape) - (experiment_time - min_time) / (max_time - min_time) + epsilon
for m in range(11):
if m==0:
safedistance=0
elif 0<m<9:
safedistance=1+(m-1)*4
elif m==9:
safedistance=1+(m-2)*4+8
else:
safedistance=40
print("实验编号",m,'-----安全距离-----',safedistance,"-----综合评分-----",F1score(experiment_step[m],experiment_time[m]))
MainControl()
# singleControl()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。