Giter Club home page Giter Club logo

astar-gridmap-2d's Introduction

A* for 2D grids

This is an implementation of the A* path planning algorithm, specifically tailored for 2D grids.

It is inspired by other two open source implementations:

Nevertheless, this implementation is 20% faster.

You might want to take a look to astar-algorithm-cpp, but that implementation is more generic and it is not specifically optimized for 2D gridmaps.

To improve speed, the library uses a fairly large amount of RAM to perform many operations in O(1). The number of memory allocations is reduced to the very minimum.

It requires at least 8 bytes for each cell in the grid, in other words, more than 8 Mb of memory for a 1000x1000 gridmap.

How fast is it?

Even if a fair amount of work was spent (mostly for fun) to optimize this software, it is still an A* algorithm, that will be outperformed by other, more advanced, algorithms.

If you are looking for state-of-the-art path finders, you might be interested to www.movingai.com

This particularly implementation is efficient but also easy to read and understand.

Usage

You must pass the image using the method setWorldData().

Note that the the image data must be row-major and monochromatic.

A value of 0 (black) represents an obstacle, whilst 255 (white) is a free cell.

    // You don't need to use this image parser, you can use your own.   
    Image image;
    image.readFromPGM("./data/maze_big.pgm");

    AStar::PathFinder generator;

    generator.setWorldData( image.width(),
                            image.height(),
                            image.data() );
                
    AStar::Coord2D startPos (image.width()/2, 0);
    AStar::Coord2D targetPos(image.width()/2, image.height()/2 -1);
               
    auto path = generator.findPath(startPos, targetPos);

In the following example, the algorithm required about 200 milliseconds and 25 Mb of RAM to find the solution in a 1586x1586 maze.

The pink pixels represent the cells of the grid visited by the algorithm.

Large map

License

Copyright 2018-2019 Eurecat

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

References

Introduction to A*

astar-gridmap-2d's People

Contributors

chataign avatar facontidavide avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

astar-gridmap-2d's Issues

Rerunning benchmarks against pyastar

Nice job beating my implementation! Congratulations :)

I made some optimizations recently (mostly better data marshalling from C++ back to Python) and observed a considerable speedup. I want to re-run the benchmarks to see how our implementations compare and if I need to squeeze out more performance.

I was able to build your code with

cmake -DCMAKE_BUILD_TYPE=Release -DCMAKE_INSTALL_PREFIX ~/work/astar-gridmap-2d/ ..

I then ran the benchmarks:

2020-07-31T21:40:45-04:00
Running ./benchmark-astar
Run on (8 X 2900 MHz CPU s)
CPU Caches:
  L1 Data 32 KiB (x4)
  L1 Instruction 32 KiB (x4)
  L2 Unified 256 KiB (x4)
  L3 Unified 6144 KiB (x1)
Load Average: 0.31, 0.68, 0.63
***WARNING*** CPU scaling is enabled, the benchmark real time measurements may be noisy and will incur extra overhead.
***WARNING*** Library was built as DEBUG. Timings may be affected.
---------------------------------------------------------------
Benchmark                     Time             CPU   Iterations
---------------------------------------------------------------
BM_AStar_Big          168256142 ns    166915840 ns            4
BM_AStar_Smooth_1000  121107850 ns    120236169 ns            5
BM_AStar_Small          7450731 ns      7423740 ns           92

Does that seem correct? I haven't used Google Benchmark before. My computer is pretty old and I'm not sure which library the "DEBUG" message refers to because I did specify a release build.

I also benchmarked my own using pytest-benchmark using this benchmarking code. All times are in milliseconds:

=========================================================================================== test session starts ===========================================================================================
platform linux -- Python 3.8.2, pytest-5.4.1, py-1.8.1, pluggy-0.13.1
benchmark: 3.2.3 (defaults: timer=time.perf_counter disable_gc=False min_rounds=5 min_time=0.000005 max_time=1.0 calibration_precision=10 warmup=False warmup_iterations=100000)
rootdir: /home/hendrik/work/pyastar
plugins: benchmark-3.2.3
collected 3 items                                                                                                                                                                                         

benchmarks.py ...                                                                                                                                                                                   [100%]


----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              7.6008 (1.0)        9.6488 (1.0)        7.9288 (1.0)      0.2942 (1.0)        7.8666 (1.0)      0.3759 (1.0)          15;3  126.1225 (1.0)         122           1
test_smooth_1000       74.0145 (9.74)      75.8684 (7.86)      74.6225 (9.41)     0.5267 (1.79)      74.5610 (9.48)     0.7518 (2.00)          4;0   13.4008 (0.11)         14           1
test_large            165.6195 (21.79)    170.2154 (17.64)    166.9610 (21.06)    1.7071 (5.80)     166.2985 (21.14)    1.4694 (3.91)          1;1    5.9894 (0.05)          6           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Legend:
  Outliers: 1 Standard Deviation from Mean; 1.5 IQR (InterQuartile Range) from 1st Quartile and 3rd Quartile.
  OPS: Operations Per Second, computed as 1 / Mean
============================================================================================ 3 passed in 4.75s ============================================================================================

So taking the "Time" column from Google Benchmark and the "Mean" column from pytest-benchmark and putting it all together in milliseconds:

Input astar-gridmap-2d pyastar
maze_250.pgm 7.45 7.93
maze_1000_smooth.pgm 121.11 74.62
maze_large.pgm 168.26 166.96

I'm curious to hear how you did the benchmarks and if you have time to rerun your benchmarks, I'd love to see the comparison with my new implementation.

These numbers are close enough that I'm not willing to make any claims either way :)

Benchamark is not working

Commit 3154725 introduced an error in Benchmark...

Basically, it doesn't work anymore.... that is probably the symptom of an hidden problem.

I think you should revert the changes and move to another branch until the problem is fixed.

Commit c4a1428 makes code slower, not faster

This change makes the code run slightly slower, not faster, in release mode.

So, it is using more RAM without any actual benefit. These are my benchmarks:

BEFORE:

BM_AStar_Big          112757675 ns    112767742 ns           25
BM_AStar_Smooth_1000   87412129 ns     87419778 ns           32
BM_AStar_Small          5009150 ns      5009642 ns          567

AFTER

BM_AStar_Big          113887220 ns    113840285 ns           24
BM_AStar_Smooth_1000   92206363 ns     92214387 ns           30
BM_AStar_Small          5060795 ns      5061211 ns          557

Code optimization

Dear Davide:

Sorry to bother. I am doing some research on comparing the searching time on the shortest path problem base on grid map. I downloaded your codes and it can run without any problem. May I know that anything that I can do in order to optimize the code even more? And do you know that what is the fastest searching algorithm so far? So that I can test.

Thanks & B. Regards
Patrick

Source files do not compile indepdently

Thank you very much for your work. When I tried to use your files from the src directory, they did not compile in my project.
Adding
#include <stdint.h>
#include
to AStar2.h solved the problem for me.

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.