From 4faf6aa208a19b085326b5c783c9c68494f9afb8 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Alexis=20Laferri=C3=A8re?= Date: Wed, 29 Oct 2014 09:36:38 -0400 Subject: [PATCH] lib/a_star: intro `find_closest` MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Alexis Laferrière --- lib/a_star.nit | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/a_star.nit b/lib/a_star.nit index 7b7ce02..cc0cba3 100644 --- a/lib/a_star.nit +++ b/lib/a_star.nit @@ -188,6 +188,14 @@ class Node end end + # Find the closest node accepted by `cond` under `max_cost` + fun find_closest(max_cost: Int, context: PathContext, cond: nullable TargetCondition[N]): nullable N + do + var path = path_to_alts(null, max_cost, context, cond) + if path == null then return null + return path.nodes.last + end + # We customize the serialization process to avoid problems with recursive # serialization engines. These engines, such as `JsonSerializer`, # are at danger to serialize the graph as a very deep tree. -- 1.7.9.5