Allow specifing a weight for routing that is independent of duration

This commit is contained in:
Patrick Niklaus
2016-05-12 18:50:10 +02:00
committed by Patrick Niklaus
parent e463733138
commit 279f8aabfb
85 changed files with 2100 additions and 853 deletions
+15 -8
View File
@@ -1,4 +1,4 @@
api_version = 0
api_version = 1
-- Rasterbot profile
-- Minimalist node_ and way_functions in order to test source_ and segment_functions
@@ -37,18 +37,25 @@ function source_function ()
)
end
function segment_function (source, target, distance, weight)
local sourceData = sources:interpolate(raster_source, source.lon, source.lat)
local targetData = sources:interpolate(raster_source, target.lon, target.lat)
function segment_function (segment)
local sourceData = sources:interpolate(raster_source, segment.source.lon, segment.source.lat)
local targetData = sources:interpolate(raster_source, segment.target.lon, segment.target.lat)
io.write("evaluating segment: " .. sourceData.datum .. " " .. targetData.datum .. "\n")
local invalid = sourceData.invalid_data()
local scaled_weight = segment.weight
local scaled_duration = segment.duration
if sourceData.datum ~= invalid and targetData.datum ~= invalid then
local slope = math.abs(sourceData.datum - targetData.datum) / distance
local slope = math.abs(sourceData.datum - targetData.datum) / segment.distance
io.write(" slope: " .. slope .. "\n")
io.write(" was speed: " .. weight.speed .. "\n")
io.write(" was weight: " .. segment.weight .. "\n")
io.write(" was speed: " .. segment.duration .. "\n")
weight.speed = weight.speed * (1 - (slope * 5))
io.write(" new speed: " .. weight.speed .. "\n")
scaled_weight = scaled_weight / (1 - (slope * 5))
io.write(" new weight: " .. scaled_weight .. "\n")
scaled_duration = scaled_duration / (1 - (slope * 5))
io.write(" new speed: " .. scaled_duration .. "\n")
end
segment.weight = scaled_weight
segment.duration = scaled_duration
end