技术测试-路径生成

思路

在我们的程序模拟中,路径生成时非常重要的一环。路径保存在每一个place对象中,人通过访问所在地点中通往其他地点的路径集合决定移动的方向。为了提高人移动的真实性,每两个地点中间都有多条可供选择的路径。
为了确保路径初始化不出差错,我们进行了技术测试,在本次测试中,我们选择了hm1(home对象的标识)、hm8,以不同颜色绘制了它们到其他各个地点的路径。

代码

def draw_road():
    place_info=write_json("./Place_info/city2.xlsx","./JSON_file/city2_placeinfo.json")

    fig = plt.figure()
    rect = [0.1, 0.1, 0.8, 0.8]
    ax0=fig.add_axes(rect,label='ax0')
    img_back=plt.imread("back.png")

    #home:
    roads_tol=place_info['hm8']

    roads_work_index=roads_tol["roads_otherplace"]["work"]
    for roads_tmp in roads_work_index:
        road_list=[]
        for road in roads_tmp:
            road_list.append(map(place_info[road]["position"]))
        print(road_list)
        for i in range(len(road_list)-1):
            ax0.scatter(road_list[i][0],road_list[i][1],color='r',alpha=0.5)
            ax0.plot([road_list[i][0],road_list[i+1][0]],[road_list[i][1],road_list[i+1][1]],color='r',alpha=0.5)

    roads_work_index = roads_tol["roads_otherplace"]["station"]
    for roads_tmp in roads_work_index:
        road_list=[]
        for road in roads_tmp:
            road_list.append(map(place_info[road]["position"]))
        print(road_list)
        for i in range(len(road_list)-1):
            ax0.scatter(road_list[i][0],road_list[i][1],color='b',alpha=0.5)
            ax0.plot([road_list[i][0],road_list[i+1][0]],[road_list[i][1],road_list[i+1][1]],color='b',alpha=0.5)
    #
    roads_work_index = roads_tol["roads_otherplace"]["hospital"]
    for roads_tmp in roads_work_index:
        road_list = []
        for road in roads_tmp:
            road_list.append(map(place_info[road]["position"]))
        print(road_list)
        for i in range(len(road_list) - 1):
            ax0.scatter(road_list[i][0], road_list[i][1], color='g',alpha=0.5)
            ax0.plot([road_list[i][0], road_list[i + 1][0]], [road_list[i][1], road_list[i + 1][1]], color='g',alpha=0.5)

    roads_work_index = roads_tol["roads_otherplace"]["market"]
    for roads_tmp in roads_work_index:
        road_list = []
        for road in roads_tmp:
            road_list.append(map(place_info[road]["position"]))
        print(road_list)
        for i in range(len(road_list) - 1):
            ax0.scatter(road_list[i][0], road_list[i][1], color='w', alpha=0.5)
            ax0.plot([road_list[i][0], road_list[i + 1][0]], [road_list[i][1], road_list[i + 1][1]], color='w',
                     alpha=0.5)


    ax0.imshow(img_back)

    # ax1=fig.add_axes(rect,label='ax1',frameon=False)
    # # plt.xlim((0,1920))
    # # plt.ylim((0, 1080))
    # ax1.plot([1000,200],[50,50])
    # ax1.scatter([1000,200],[50,50])

    plt.show()

测试结果

hm1-station

在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述

hm1-work

在这里插入图片描述

hm1-all

在这里插入图片描述

hm8-all

在这里插入图片描述

ho5

在这里插入图片描述

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值