Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I propose a solution without the suggested library or the quadtree, I stay in basic prolog (I write in SWI).</p> <p>There is actually no need for <code>assert</code>/<code>retract</code>/<code>forall</code> if I understand your problem correctly. I assume that <code>point(P)</code> says that P is the uniquely-defined reference point from which we calculate distances, but it is a bit weird (I would use it as a parameter, to ensure it is unique).</p> <pre><code>point([0,0]). % The reference point % Entry point predicate % First parameter : a list of points % Second parameter (result) : the point closest to the reference point list_min([H|Tail], Min) :- point(Reference), distance(H, Reference, D), list_min(Tail, H, D, Min). % First parameter : the list remaining to consider % Second parameter : the closest point, at this point of the computation % Third parameter : the corresponding (minimum) distance, at this point of the computation % Fourth parameter : the result (one point, to be bound at the end of computation) list_min([], CurrentMin, _, CurrentMin). % Stop condition : list processed list_min([Candidate|Tail], CurrentMin, CurrentDist, Min) :- point(Reference), distance(Candidate, Reference, CandidateDist), ( % if the new candidate is not better, keep the current candidate CurrentDist &lt; CandidateDist -&gt; list_min(Tail, CurrentMin, CurrentDist, Min) ; % if the new candidate is better, take it as the current candidate list_min(Tail, Candidate, CandidateDist, Min) ). distance(A,B,D):- % copy-pasted from your version A = [A1,A2], B = [B1,B2], Y is B2 - A2, X is B1 - A1, D is sqrt(X*X + Y*Y). </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload