1. bergsoe
  2. papl

Commits

bergsoe  committed 340dd7b

Optional min_stride and max_stride arguments for steps_n.

  • Participants
  • Parent commits d0f4ee6
  • Branches master

Comments (0)

Files changed (2)

File src/PaplRRTExpand.ml

View file
  • Ignore whitespace
 
 let quot_rem a b = a / b, a mod b
 
-let shorten_n n path =
+let split_n ?min_stride ?max_stride n path =
   let len = List.length path in
-  if len <= n then path
-  else
-    let i, r = quot_rem (len - n) n in
-    let rec loop r path =
-      let skip = if r > 0 then i + 1 else i in
-        match BatList.drop skip path with
-            [q] -> [q]
-          | q :: path -> q :: loop (r - 1) path
-          | [] -> failwith "PaplRRTExpand.shorten_n: impossible"
-    in loop r path
+  let min_stride = BatOption.default 0 min_stride in
+  let max_stride = BatOption.default len max_stride in
+  let shorten_n n =
+    if len <= n then path
+    else
+      let i, r = quot_rem (len - n) n in
+      let rec loop r path =
+        let skip = if r > 0 then i + 1 else i in
+          match BatList.drop skip path with
+              [q] -> [q]
+            | q :: path -> q :: loop (r - 1) path
+            | [] -> failwith "PaplRRTExpand.split_n: impossible"
+      in loop r path
+  in
+    if len = 0 then []
+    else if min_stride >= len then [BatList.last path]
+    else
+      let i, r = quot_rem (len - n) n in
+      let n =
+        (* If too few elements are dropped: *)
+        if i + 1 < min_stride then
+          len / min_stride
+        (* If too many elements are dropped: *)
+        else if i + 1 > max_stride || r > 0 && i + 2 > max_stride then
+          len / max_stride + 1
+        else
+          n
+      in shorten_n n
 
-let steps_n constr intermediary n =
+let steps_n ?min_stride ?max_stride constr intermediary n =
   let () =
     if n <= 0 then
       let msg = Printf.sprintf
   let expand = by_intermediaries constr [intermediary] in
     fun start goal ->
       let (path, reached) = expand start goal in
-        shorten_n n path, reached
+        split_n ?min_stride ?max_stride n path, reached

File src/PaplRRTExpand.mli

View file
  • Ignore whitespace
   'a expand_t
 
 val steps_n :
+  ?min_stride:int ->
+  ?max_stride:int ->
   'a PaplEdgeConstraint.t ->
   'a PaplInterpolate.intermediary_t ->
   int ->
 (** Expansions with at most [n] steps.
 
     The expansion method [steps_n constr intermediary n] splits a segment into
-    steps using [intermediary] and verifies the steps by [constr]. If the number
-    of accepted steps was less than or equal to [n], the steps are returned.
-    Otherwise the method shortens the list of steps to produce a list with
-    exactly [n] elements. 
+    intermediary configurations using [intermediary] and verifies each step by
+    [constr]. If the path of accepted configurations is shorter or equal to [n],
+    then this path is returned. Otherwise the path is shortened by removing a
+    subset of the configurations to produce a path with exactly [n] elements.
+
+    The optional parameters [min_stride] and [max_stride] can be used to lower
+    or raise the number of elements [n] in the resulting path, depending on the
+    length [len] of the path. The length of the resulting path is at least [len
+    / min_stride] (for [len > min_stride]) and at most [len / max_stride + 1]
+    (assuming [min_stride < max_stride]).
 *)