如何创建现有路径的许多子集?

问题描述 投票:0回答:1

在 OpenstreetMapX 中我们可以通过以下方式创建随机路径:

using OpenStreetMapX

map_file_path = joinpath(dirname(pathof(OpenStreetMapX)),"..","test/data/reno_east3.osm")
mx = get_map_data(map_file_path, use_cache=false);
using Random 
Random.seed!(0)
node_ids = collect(keys(mx.nodes)) 
routes = Vector{Vector{Int}}()
visits = Dict{Int,Int}()
for i in 1:10
    a,b = [point_to_nodes(generate_point_in_bounds(mx), mx) for _ in 1:2]
    route, route_time = OpenStreetMapX.shortest_route(mx,a,b)
    if route_time < Inf # when we select points neaer edges no route might be found
        push!(routes, route)
        for n in route
            visits[n] = get(visits, n,0)+1
        end 
    end
end                                   
println("We have generated ",length(routes)," non-empty routes")

现在我们有 10 条不同的路径,我想知道如何随机生成 100 个大小为 p 的子路径(其中 p 介于实际路径的 3 到一半之间)?也就是说,随机有 100 条不同的路径,它们是上述 10 条路径之一的子集? 就像如果路径 1 是 ABCDEFGHIJ 那么它的三个子集是 BCDE、CDEF、DEFG

我不知道 OpenStreetMapX 中是否有任何直接命令,但我认为因为输出是

0-element Vector{Vector{Int64}}
可能有办法用 julia list 来做到这一点?

10-element Vector{Vector{Int64}}:
[
  [1793, 1038, 1286, 3086, 2631, 4205, 4205, 3086, 4205, 3086, 2468, 2985, 5674, 5674, 2985, 2985, 2985, 8894, 2985, 2985],
  [1031, 1031, 1031, 1031, 1031, 4402, 1031, 1031, 1032, 1032, 2987, 2987, 2987, 4205, 4250, 4250, 4246, 4247, 4247, 8318],
  [2465, 4242, 3874, 4872, 2465, 4207, 4243, 4243, 4242, 4243, 7495, 2774, 5676, 5871, 2774, 7319, 2774, 2774, 2774, 1006]
]
....
julia openstreetmap
1个回答
0
投票

你有这样的想法吗?

l, s, p = rand(1:length(out)), rand(1:length(out[1])), rand(length(out[1])÷3:length(out[1])÷2)
out[l][s:s+p-1]
out = [
  [1793, 1038, 1286, 3086, 2631, 4205, 4205, 3086, 4205, 3086, 2468, 2985, 5674, 5674, 2985, 2985, 2985, 8894, 2985, 2985],
  [1031, 1031, 1031, 1031, 1031, 4402, 1031, 1031, 1032, 1032, 2987, 2987, 2987, 4205, 4250, 4250, 4246, 4247, 4247, 8318],
  [2465, 4242, 3874, 4872, 2465, 4207, 4243, 4243, 4242, 4243, 7495, 2774, 5676, 5871, 2774, 7319, 2774, 2774, 2774, 1006]
]
© www.soinside.com 2019 - 2024. All rights reserved.