修改生成数据方式和网络训练方式

This commit is contained in:
2024-04-06 13:44:05 +08:00
parent bae7e4e2c3
commit 6fa1f53f69
8 changed files with 194 additions and 96 deletions

View File

@ -24,7 +24,7 @@ def optimizer(pcb_data, component_data, line_optimizer, machine_optimizer, machi
return
assignment_result_cpy = copy.deepcopy(assignment_result)
placement_points, placement_time = [], []
placement_points, assembly_info = [], []
partial_pcb_data, partial_component_data = defaultdict(pd.DataFrame), defaultdict(pd.DataFrame)
for machine_index in range(machine_number):
partial_pcb_data[machine_index] = pd.DataFrame(columns=pcb_data.columns)
@ -128,24 +128,33 @@ def optimizer(pcb_data, component_data, line_optimizer, machine_optimizer, machi
for info in part_info:
partial_component_data[machine_index].loc[info[0], 'feeder-limit'] = math.ceil(info[2] / max_avl_feeder)
placement_time.append(base_optimizer(machine_index + 1, data, partial_component_data[machine_index],
assembly_info.append(base_optimizer(machine_index + 1, data, partial_component_data[machine_index],
feeder_data=pd.DataFrame(columns=['slot', 'part', 'arg']),
method=machine_optimizer, hinter=True).placement_time)
method=machine_optimizer, hinter=True))
average_time, standard_deviation_time = sum(placement_time) / machine_number, 0
with open('model/lr_model.pkl', 'rb') as f:
lr = pickle.load(f)
average_time, standard_deviation_time = sum(
[assembly_info[m].placement_time for m in range(machine_number)]) / machine_number, 0
for machine_index in range(machine_number):
total_component_types = 0
for points in assignment_result_cpy[machine_index]:
if points:
total_component_types += 1
print('assembly time for machine ' + str(machine_index + 1) + ': ' + str(
placement_time[machine_index]) + ' s, ' + 'total placements: ' + str(placement_points[machine_index])
+ ', total component types: ' + str(total_component_types))
standard_deviation_time += pow(placement_time[machine_index] - average_time, 2)
total_component_types = sum(1 if pt else 0 for pt in assignment_result_cpy[machine_index])
placement_time = assembly_info[machine_index].placement_time
regression_time = lr.coef_[0][0] * assembly_info[machine_index].cycle_counter + lr.coef_[0][1] * assembly_info[
machine_index].nozzle_change_counter + lr.coef_[0][2] * assembly_info[machine_index].pickup_counter + \
lr.coef_[0][3] * assembly_info[machine_index].pickup_movement + lr.coef_[0][4] * \
placement_points[machine_index] + lr.intercept_[0]
print(f'assembly time for machine {machine_index + 1: d}: {placement_time: .3f} s, total placement: '
f'{placement_points[machine_index]}, total component types {total_component_types: d}', end=', ')
print(f'regression time: {regression_time: .3f} s')
standard_deviation_time += pow(placement_time - average_time, 2)
standard_deviation_time /= machine_number
standard_deviation_time = math.sqrt(standard_deviation_time)
print('finial assembly time: ' + str(max(placement_time)) + 's, standard deviation: ' + str(standard_deviation_time))
print(f'finial assembly time: {max(info.placement_time for info in assembly_info): .3f} s, '
f'standard deviation: {standard_deviation_time: .3f}')
@timer_wrapper
@ -169,6 +178,7 @@ def main():
# 加载PCB数据
pcb_data, component_data, _ = load_data(params.filename, default_feeder_limit=params.feeder_limit,
cp_auto_register=params.auto_register, load_feeder_data=False) # 加载PCB数据
optimizer(pcb_data, component_data, params.line_optimizer, params.machine_optimizer, params.machine_number)