• 大小: 29KB
    文件类型: .py
    金币: 2
    下载: 0 次
    发布日期: 2024-02-06
  • 语言: Python
  • 标签: 2019  PYTHON  

资源简介

此代码是本团队参加2019届华为软件精英挑战赛时所写代码,代码内容包括车辆行驶地图模型建立、路径选择A*算法实现

资源截图

代码片段和文件信息

import re
import numpy as np
import copy

def read_file(road_file_name):
    fi = open(“{}“.format(road_file_name) “r“ encoding=“utf-8“)
    information_txt = fi.read()
    p1 = r“(.+)“
    pattern1 = re.compile(p1)
    information = pattern1.findall(information_txt)
    information.pop(0)
    return information

def information_list_transform_dict(information_list):
    information_dict = {}
    for i in range(len(information_list)):
        information_dict[‘{}‘.format(eval(information_list[i])[0])] =list(eval(information_list[i]))
    return information_dict

def creat_dict_sideweight_oritation(road_information_dictcross_information_dict):
    cross_sideweight_dict={}
    cross_oritation_dict={}
    for key in cross_information_dict.keys():
        cross_sideweight_list = [0 0 0 0 0]
        cross_oritation_list = [0 0 0 0 0]
        cross_sideweight_list[0]=int(key)
        cross_oritation_list[0]=int(key)
        for i in range(15):
            cross_road_id = cross_information_dict[‘{}‘.format(key)][i]
            if cross_road_id != -1:
                cross_road_information = road_information_dict[‘{}‘.format(cross_road_id)]
                cross_road_information_length = cross_road_information[1]
                cross_road_information_isDuplex = cross_road_information[6]
                cross_road_information_from=cross_road_information[4]
                cross_road_information_to=cross_road_information[5]
                if cross_road_information_isDuplex == 1 :
                    cross_sideweight_list[i] = cross_road_information_length
                    if cross_road_information_from == int(key):
                        cross_oritation_list[i] =cross_road_information_to
                    else:
                        cross_oritation_list[i] = cross_road_information_from



                else:
                    if cross_road_information_from == int(key):
                        cross_sideweight_list[i] = cross_road_information_length
                        cross_oritation_list[i] = cross_road_information_to

        cross_sideweight_dict[‘{}‘.format(key)]=cross_sideweight_list
        cross_oritation_dict[‘{}‘.format(key)]=cross_oritation_list
    return cross_sideweight_dictcross_oritation_dict

def orientational_x_y_dict(road_information_dictcross_information_listcross_information_dict ):
    m = []
    point_site = {}
    flg_cross_information_dict = copy.deepcopy(cross_information_dict)
    close_flag_cross_information_dict = copy.deepcopy(cross_information_dict)
    first_cross =eval(cross_information_list[0])[0]
    point_site[‘{}‘.format(first_cross)] = (0 0)
    close_flag_cross_information_dict[‘{}‘.format(first_cross)][0] =0
    m.append(cross_information_dict[‘{}‘.format(first_cross)])

    while len(m) != 0:
        first_item = m.pop(0)
        flg_cross_information_dict[‘{}‘.format(first_item[0])][0] = 0
        for i in range(1 5)

评论

共有 条评论