How to pass the following pseudocode (Algorithm Top down Time Ratio) to R language (R-Project)

0

I am using a database in Postgresql of trajectories vehicles and I want to use the following algorithm in R to compress the trajectories.

#algoritmo top-down time-ratio

procedure TD_TR(s,dist_threshold)
if len(s) <= 2 then 
    return s 
else max dist threshold <- 0 
    found_index <- 0 
    ∆e <- s[len(s)]t - s[1]t 
    for i <- 2 until len(s) - 1 do
        ∆i <- s[i]t - s[1]t 
        (x'i,y'i) <- s[1]loc + (s[e]loc - s[1]loc)∆i/∆e
        if dist(s[i]loc,(x'i,y'i)) > max_dist_threshold then 
        max_dist_threshold <- dist(s[i]loc,(x'i,y'i)) 
        found index <- i
        endif 
    endfor 
        if max dist threshold > dist threshold then
        return TD_TR(s[1,found_index],dist_threshold) ++ TD_TR(s[found_index,len(s)],dist_threshold)
        else 
            return [s[1],s[len(s)]]
        endif 
endelse
    
asked by alexariel 08.01.2017 в 18:13
source

0 answers