Coder Social home page Coder Social logo

fzehracetin / a-star-and-best-first-search Goto Github PK

View Code? Open in Web Editor NEW
3.0 1.0 0.0 941 KB

This is the implementation of A* and Best First Search Algorithms in python language. The project comprimise two data structures: stack and heap.

License: Apache License 2.0

Python 100.00%
a-star-algorithm a-star-search a-star-path-finding best-first-search search-algorithms heap-sort heap heap-tree stack

a-star-and-best-first-search's Introduction

A Star and Best First Search Algorithm

This is the implementation of A* and Best First Search Algorithms in python language. The project comprimise two data structures: stack and heap. So there is four options in this project.

Search algorithms run on the images between start and end pixels. I added R value from RGB value to the h(n) and g(n) functions. Thus, algorithms tend to move from the red areas. Red areas have the lower cost value. The fuctions are listed below.

For Best First Search, we use f(n) = h(n), the heuristic function. It can be shortest line distance for path finding between cities or districts. In this project:

f(n) = h(n) = euclideanDistance(point1, point2) * (256 - R)

Computed Euclidean Distance is between the point1 is the point that we add to our stack or heap and point2 is the end point. So we can predict which point is closer to the end point then we can choose it.

For A* Algorithm we add another function to our f(n). This time f(n) = h(n) + g(n) where g(n) is the computed cost between the starting point and the current point. In A* algorithm we can choose the closer point with the lower cost. A* is an optimum algorithm. In this project f(n) is:

f(n) = h(n) + g(n) = euclideanDistance(point1, point2) * (256 - R) + point1.parent.g + 256 - R

In this formula point1.parent.g stands for the cost between starting point and the parent point. 256 - R term gives the cost value for that point, from its parent.

With heap, both algorithm works much more faster. (30 times faster)

Best First Search and A* implementation

Both algorithm tends to move from the white areas (R = 255). A* chose the shorter path.

a-star-and-best-first-search's People

Contributors

fzehracetin avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.