Skip to content

Instantly share code, notes, and snippets.

@NaeosPsy
Created March 5, 2020 07:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save NaeosPsy/d08824ed9fdd73bdb1090a6ca815cda0 to your computer and use it in GitHub Desktop.
Save NaeosPsy/d08824ed9fdd73bdb1090a6ca815cda0 to your computer and use it in GitHub Desktop.
#lang racket
(require racket/set)
(define (pq-inserts elems pq)
(sort (append elems pq) (lambda (a b)
((first a) . < . (first b)))))
(define (a-star estimate neighbors dist eps start)
(define (go visited pq)
(match pq
[(list* (list estimation distance path) rest-pq)
(let ((point (first path)))
(if ((estimate point) . <= . eps)
path
(let*
( (near
(filter
(compose not (curry set-member? visited))
(neighbors point)))
(paths
(for/list ([pt near])
(let ((distance1 (+ distance (dist point pt))))
(list
(+ distance1 (estimate pt))
distance1
(list* pt path))))))
(go
(set-add visited point)
(pq-inserts paths rest-pq)))) )]
[else
'()]))
(define initial
(list (list 0 0 (list start))))
(reverse
(go
(set)
initial)))
@RonBarakBackal
Copy link

Hi, Thank you so much for your post and code! I do wonder however how to run this code on some points to test it . how do I define the list with obstacles and path and see the result?? Thanks again

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment