Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added changes for https://github.com/hjweide/pyastar2d/issues/29 #35

Merged
merged 17 commits into from
May 9, 2022
Merged

added changes for https://github.com/hjweide/pyastar2d/issues/29 #35

merged 17 commits into from
May 9, 2022

Conversation

peterchenadded
Copy link
Contributor

Changes as discussed at #29

@hjweide
Copy link
Owner

hjweide commented May 5, 2022

Thanks @peterchenadded for all this work! I'll try to take a look soon.

int dy1 = current_y - goal_y;
int dx2 = start_x - goal_x;
int dy2 = start_y - goal_y;
return std::abs(dx1*dy2 - dx2*dy1);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This value could be arbitrarily large based on the size of the grid, right? Does this break the admissibility of the heuristic?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

According to http://theory.stanford.edu/~amitp/GameProgramming/Heuristics.html, the tie breaker logic is still optimal.

Not sure how one could prove otherwise, the very small coefficient number suggests it may not be optimal for all coefficient numbers.

// add tiebreaker cost
if (tiebreaker_coefficient > 0) {
heuristic_cost = heuristic_cost +
tiebreaker_coefficient/1000.0f * tie_breaker_func(nbrs[i] / w, nbrs[i] % w,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why pass the tiebreaker_coefficient as an int and not just pass this scaled-down float directly?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, your right. Will change to float.

Didn't want to pass a new type to c at the time.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update it to float. So now it is just

if (tiebreaker_coefficient > 0.0f) {
    heuristic_cost = heuristic_cost + 
                tiebreaker_coefficient * tie_breaker_func(nbrs[i] / w, nbrs[i] % w,

Comment on lines 31 to 33
allow_diagonal: bool = False,
heuristic_override: int = 0,
tiebreaker_coefficient: int = 0) -> Optional[np.ndarray]:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm wondering if we should instead define a new function for uniform grids with these tiebreaking arguments to make it clear that the solution is no longer strictly a shortest path depending on the choice of arguments.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

By default it is shortest path, if users are overriding the heuristic or tiebreaker they better know what they are doing

Maybe we can just add a comment in the docstring? That shortest path guarantee and maybe others are out of the door when using the two new parameters?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added below to docstring:

    param float tiebreaker_coefficient: Add tiebreaker to heuristic cost, 0=disable, positive enables it by that amount
    
    Important: Please take care when using heuristic_override and tiebreaker_coefficient, they may not take the shortest path.

@peterchenadded
Copy link
Contributor Author

peterchenadded commented May 6, 2022

Let's hold on with this, i've worked out what heuristic i actually need which works a-lot better than the orthogonal_x and orthogonal_y that is there at the moment.

The complex tie breaker func will also be removed for just the coefficient as i have seem other algorithms using that.

Will update the PR and let you know when ready.

@peterchenadded
Copy link
Contributor Author

@hjweide, can you please review?

Looking to use it on monday with my application.

Fixed issue where there were bumps
Copy link
Owner

@hjweide hjweide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @peterchenadded for doing all this work! I left some feedback. My biggest concern is the tiebreak_coefficient.

src/cpp/astar.cpp Outdated Show resolved Hide resolved
src/cpp/astar.cpp Outdated Show resolved Hide resolved
src/cpp/astar.cpp Outdated Show resolved Hide resolved
src/cpp/astar.cpp Outdated Show resolved Hide resolved
src/cpp/astar.cpp Outdated Show resolved Hide resolved
src/pyastar2d/astar_wrapper.py Outdated Show resolved Hide resolved
tests/test_astar.py Outdated Show resolved Hide resolved
src/cpp/astar.cpp Outdated Show resolved Hide resolved
src/cpp/astar.cpp Outdated Show resolved Hide resolved
src/cpp/astar.cpp Outdated Show resolved Hide resolved
@peterchenadded
Copy link
Contributor Author

peterchenadded commented May 7, 2022

Hi @hjweide, i believe i have completed every recommendation you suggested.

Can you check and let me know.

In summary it is just support for two new heuristics and nothing more. The tiebreaker_coefficient stuff is completely removed.

Chen, Peter and others added 6 commits May 7, 2022 22:54
Removed magical numbers
Added heuristic
Fix compiling error on linux
Moved heuristic override to its own method as per suggestion
Copy link
Owner

@hjweide hjweide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for making these changes, it's looking pretty good. I took a quick look and still have some concerns that I pointed out.

Also, could you please re-run the benchmarking to ensure performance remains the same for the existing implementation?

I did this here the last time I made substantial changes for performance:
Eurecat/astar-gridmap-2d#9

This code should still work for benchmarking:
https://gist.github.com/hjweide/1586715f5a2762e80a917bfc2c827dd1

You can get the files from the repo I linked above.

src/cpp/astar.cpp Outdated Show resolved Hide resolved
src/pyastar2d/astar_wrapper.py Outdated Show resolved Hide resolved
src/cpp/astar.cpp Outdated Show resolved Hide resolved
src/cpp/astar.cpp Outdated Show resolved Hide resolved
@peterchenadded
Copy link
Contributor Author

Sure no worries, will run the benchmarking. It has one less conditional to check what heuristic, so I suspect it is very slightly faster but than we are passing more args...

Will also make the other changes and get back.

@peterchenadded
Copy link
Contributor Author

peterchenadded commented May 8, 2022

Code changes are made, please review once.

Seems it is alittle faster on my pc:

Your one:

=========================================================================================== 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 ============================================================================================

My one:

============================= test session starts =============================
platform win32 -- Python 3.8.6, pytest-7.1.2, pluggy-1.0.0
benchmark: 3.4.1 (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: C:\Users\peter.chen\workspace\repos
plugins: benchmark-3.4.1
collected 3 items

test_benchmarks.py ...                                                   [100%]

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.8854 (1.0)        8.2541 (1.0)        6.1346 (1.0)      0.3329 (1.0)        6.0710 (1.0)      0.1308 (1.0)          9;14  163.0092 (1.0)         168           1
test_smooth_1000       58.2058 (9.89)      66.9125 (8.11)      61.7065 (10.06)    2.7294 (8.20)      61.4749 (10.13)    4.1582 (31.79)         5;0   16.2057 (0.10)         17           1
test_large            126.4101 (21.48)    133.0430 (16.12)    129.6350 (21.13)    2.4050 (7.23)     129.4184 (21.32)    4.1853 (32.00)         4;0    7.7140 (0.05)          8           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, 4 warnings in 4.97s ========================

Below is existing master code without any of my changes

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.4124 (1.0)        8.1858 (1.0)        5.6893 (1.0)      0.3284 (1.0)        5.6246 (1.0)      0.1182 (1.0)          8;18  175.7683 (1.0)         177           1
test_smooth_1000       55.6468 (10.28)     63.7333 (7.79)      57.1190 (10.04)    2.0044 (6.10)      56.5953 (10.06)    0.9219 (7.80)          2;2   17.5073 (0.10)         18           1
test_large            119.7480 (22.12)    130.6702 (15.96)    123.4715 (21.70)    3.7442 (11.40)    123.0284 (21.87)    5.1455 (43.52)         1;0    8.0990 (0.05)          8           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

@peterchenadded
Copy link
Contributor Author

peterchenadded commented May 8, 2022

Ran a few times and the result was always more than what you had.

Made below two additional changes:

  1. Reverted to using direct function calls for the two default heuristics
  2. Calculated goal_i and goal_j once instead of every call

Straight after the change noticed the benchmarks were consistently better than before.

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.1677 (1.0)        8.0508 (1.0)        5.4448 (1.0)      0.4015 (1.0)        5.3642 (1.0)      0.1450 (1.0)          9;12  183.6611 (1.0)         184           1
test_smooth_1000       53.8462 (10.42)     58.7154 (7.29)      55.4607 (10.19)    1.5040 (3.75)      54.9058 (10.24)    1.7728 (12.23)         5;0   18.0308 (0.10)         19           1
test_large            113.9760 (22.06)    123.4863 (15.34)    116.6987 (21.43)    2.8707 (7.15)     115.7903 (21.59)    2.4267 (16.74)         1;1    8.5691 (0.05)          9           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

@peterchenadded
Copy link
Contributor Author

Also below are the results for orthogonal x and y

x:

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.9934 (1.0)        8.7435 (1.0)        6.4926 (1.0)      0.6759 (1.0)        6.2597 (1.0)      0.1944 (1.0)         13;17  154.0208 (1.0)         120           1
test_large            130.4186 (21.76)    147.1419 (16.83)    134.7627 (20.76)    6.0778 (8.99)     131.4681 (21.00)    6.9806 (35.90)         1;0    7.4205 (0.05)          8           1
test_smooth_1000      246.1046 (41.06)    250.3633 (28.63)    247.6769 (38.15)    2.0077 (2.97)     246.3962 (39.36)    3.3839 (17.40)         1;0    4.0375 (0.03)          5           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

y:

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.3225 (1.0)        7.8012 (1.0)        5.6007 (1.0)      0.4463 (1.0)        5.4763 (1.0)      0.1172 (1.0)         10;19  178.5493 (1.0)         184           1
test_smooth_1000       57.9232 (10.88)     64.8103 (8.31)      60.2252 (10.75)    2.2575 (5.06)      59.1165 (10.79)    2.5011 (21.34)         4;0   16.6043 (0.09)         18           1
test_large            124.1422 (23.32)    139.4562 (17.88)    128.1577 (22.88)    5.4054 (12.11)    125.2997 (22.88)    5.9423 (50.70)         1;0    7.8029 (0.04)          8           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

@hjweide
Copy link
Owner

hjweide commented May 8, 2022 via email

@peterchenadded
Copy link
Contributor Author

peterchenadded commented May 8, 2022

Seems both helps.

Definitely the precalculating goal deltas over the function pointers

with both:

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.1659 (1.0)        7.7619 (1.0)        5.4514 (1.0)      0.4500 (1.0)        5.3438 (1.0)      0.1336 (1.0)         11;15  183.4380 (1.0)         185           1
test_smooth_1000       54.3569 (10.52)     62.1874 (8.01)      56.5098 (10.37)    2.3960 (5.32)      55.4338 (10.37)    1.3078 (9.79)          3;3   17.6961 (0.10)         18           1
test_large            115.3720 (22.33)    123.0041 (15.85)    118.9431 (21.82)    2.7721 (6.16)     119.1008 (22.29)    3.9875 (29.84)         4;0    8.4074 (0.05)          9           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.1504 (1.0)        8.0328 (1.0)        5.4460 (1.0)      0.3805 (1.0)        5.3559 (1.0)      0.1316 (1.0)         10;13  183.6215 (1.0)         166           1
test_smooth_1000       54.2731 (10.54)     70.8643 (8.82)      56.7845 (10.43)    3.7559 (9.87)      55.2920 (10.32)    2.8248 (21.47)         1;1   17.6104 (0.10)         19           1
test_large            114.9896 (22.33)    127.3179 (15.85)    118.5583 (21.77)    4.2322 (11.12)    116.3882 (21.73)    5.0964 (38.73)         2;0    8.4347 (0.05)          9           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.1298 (1.0)        8.0131 (1.0)        5.4894 (1.0)      0.4758 (1.0)        5.3652 (1.0)      0.1567 (1.0)         11;16  182.1691 (1.0)         186           1
test_smooth_1000       53.6664 (10.46)     60.0655 (7.50)      54.9017 (10.00)    1.5784 (3.32)      54.3138 (10.12)    0.4844 (3.09)          3;3   18.2144 (0.10)         18           1
test_large            114.3577 (22.29)    120.0654 (14.98)    116.7578 (21.27)    1.8245 (3.83)     116.8020 (21.77)    2.4911 (15.90)         2;0    8.5647 (0.05)          9           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

with function pointer only:

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.7212 (1.0)        8.4865 (1.0)        6.0382 (1.0)      0.5761 (1.0)        5.8524 (1.0)      0.1055 (1.0)         14;24  165.6124 (1.0)         168           1
test_smooth_1000       58.3274 (10.19)     63.8385 (7.52)      59.6706 (9.88)     1.5500 (2.69)      59.4623 (10.16)    1.4873 (14.10)         2;2   16.7587 (0.10)         17           1
test_large            124.6931 (21.79)    147.9069 (17.43)    133.8467 (22.17)    7.5272 (13.06)    132.8201 (22.69)    9.1848 (87.06)         2;0    7.4712 (0.05)          8           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.7105 (1.0)        8.4234 (1.0)        5.9926 (1.0)      0.4197 (1.0)        5.8860 (1.0)      0.1787 (1.0)          9;10  166.8712 (1.0)         164           1
test_smooth_1000       58.2282 (10.20)     60.3983 (7.17)      58.9299 (9.83)     0.6237 (1.49)      58.7581 (9.98)     0.4376 (2.45)          4;3   16.9693 (0.10)         18           1
test_large            126.0590 (22.07)    136.4693 (16.20)    129.9317 (21.68)    3.4211 (8.15)     129.0170 (21.92)    4.3795 (24.51)         2;0    7.6963 (0.05)          8           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.6879 (1.0)        8.5461 (1.0)        5.9924 (1.0)      0.5962 (1.0)        5.8087 (1.0)      0.1380 (1.0)         13;19  166.8775 (1.0)         174           1
test_smooth_1000       57.0532 (10.03)     65.2776 (7.64)      58.8558 (9.82)     2.3761 (3.99)      57.8030 (9.95)     1.2745 (9.24)          3;4   16.9907 (0.10)         18           1
test_large            122.6169 (21.56)    129.8333 (15.19)    125.4221 (20.93)    3.1031 (5.20)     123.7489 (21.30)    5.9722 (43.28)         3;0    7.9731 (0.05)          9           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

with pre-calculate goal/start delta i and delta j only:

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.2402 (1.0)       11.5591 (1.0)        5.6731 (1.0)      0.7608 (1.0)        5.4289 (1.0)      0.1686 (1.0)         17;24  176.2712 (1.0)         183           1
test_smooth_1000       54.2958 (10.36)     61.1196 (5.29)      55.7989 (9.84)     1.6654 (2.19)      55.3063 (10.19)    1.2530 (7.43)          3;2   17.9215 (0.10)         19           1
test_large            116.0891 (22.15)    125.4237 (10.85)    120.6145 (21.26)    3.7262 (4.90)     120.4579 (22.19)    7.1284 (42.27)         4;0    8.2909 (0.05)          9           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.3136 (1.0)        8.0385 (1.0)        5.5438 (1.0)      0.3450 (1.0)        5.4638 (1.0)      0.1196 (1.0)         10;13  180.3803 (1.0)         186           1
test_smooth_1000       54.6955 (10.29)     64.3042 (8.00)      56.9807 (10.28)    2.3665 (6.86)      56.2971 (10.30)    0.8197 (6.85)          4;4   17.5498 (0.10)         19           1
test_large            115.9916 (21.83)    124.5178 (15.49)    119.7613 (21.60)    2.2823 (6.61)     119.6810 (21.90)    1.4780 (12.36)         2;2    8.3499 (0.05)          9           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.2650 (1.0)        7.9246 (1.0)        5.6144 (1.0)      0.5258 (1.0)        5.4538 (1.0)      0.1206 (1.0)         18;22  178.1133 (1.0)         184           1
test_smooth_1000       54.8954 (10.43)     76.7697 (9.69)      59.5302 (10.60)    6.2188 (11.83)     56.2246 (10.31)    5.0532 (41.88)         2;2   16.7982 (0.09)         19           1
test_large            116.4537 (22.12)    124.8979 (15.76)    119.2338 (21.24)    2.9463 (5.60)     118.1728 (21.67)    3.7796 (31.33)         2;0    8.3869 (0.05)          9           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

with neither:

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.4425 (1.0)        6.7559 (1.0)        5.6393 (1.0)      0.1416 (1.0)        5.6276 (1.0)      0.1399 (1.0)          18;3  177.3283 (1.0)         128           1
test_smooth_1000       56.3577 (10.36)     63.9939 (9.47)      57.7287 (10.24)    2.1282 (15.03)     56.9742 (10.12)    0.6298 (4.50)          3;3   17.3224 (0.10)         19           1
test_large            119.8886 (22.03)    133.9554 (19.83)    123.9875 (21.99)    4.9546 (35.00)    121.2350 (21.54)    7.5361 (53.89)         1;0    8.0653 (0.05)          9           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.4352 (1.0)        9.0725 (1.0)        5.7428 (1.0)      0.5040 (1.0)        5.6285 (1.0)      0.1272 (1.0)         11;17  174.1298 (1.0)         176           1
test_smooth_1000       56.8626 (10.46)     66.9089 (7.37)      59.1053 (10.29)    2.6998 (5.36)      58.1462 (10.33)    2.0299 (15.96)         3;2   16.9190 (0.10)         18           1
test_large            121.8163 (22.41)    126.2700 (13.92)    123.8259 (21.56)    1.6125 (3.20)     123.3154 (21.91)    2.6493 (20.83)         4;0    8.0759 (0.05)          8           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.4567 (1.0)        8.1104 (1.0)        5.7436 (1.0)      0.3453 (1.0)        5.6651 (1.0)      0.1388 (1.0)         10;15  174.1080 (1.0)         176           1
test_smooth_1000       56.1536 (10.29)     63.9768 (7.89)      58.0492 (10.11)    2.3206 (6.72)      57.1155 (10.08)    1.4056 (10.13)         3;3   17.2268 (0.10)         18           1
test_large            121.0098 (22.18)    125.5965 (15.49)    122.6731 (21.36)    1.6574 (4.80)     122.2579 (21.58)    1.3816 (9.95)          3;2    8.1517 (0.05)          9           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

Copy link
Owner

@hjweide hjweide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking great, just left a few final minor comments. After these I think we should be good to merge.

src/cpp/astar.cpp Outdated Show resolved Hide resolved
src/cpp/astar.cpp Outdated Show resolved Hide resolved
src/cpp/astar.cpp Outdated Show resolved Hide resolved
@peterchenadded
Copy link
Contributor Author

Pushed up below branches, you if you want to see the code

$ git branch -a
  master <- both changes
  test/function_pointer
  test/goal-precalculation

@peterchenadded
Copy link
Contributor Author

peterchenadded commented May 8, 2022

@hjweide done, please check and let me know if you would like anything else changed. thanks for supporting this.

Also benchmarked the code and no difference whether in another file or not.

Copy link
Owner

@hjweide hjweide left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@hjweide hjweide merged commit d263f8b into hjweide:master May 9, 2022
@peterchenadded
Copy link
Contributor Author

Let me know if you also want below changes:

image

modulus is considered expensive, so we remove them using existing calculation we already did.

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.0094 (1.0)        7.4816 (1.0)        5.3191 (1.0)      0.3314 (1.0)        5.2602 (1.0)      0.1653 (1.0)           8;9  188.0013 (1.0)         191           1
test_smooth_1000       52.8989 (10.56)     59.5790 (7.96)      54.3368 (10.22)    1.7066 (5.15)      53.6480 (10.20)    1.1022 (6.67)          2;2   18.4037 (0.10)         16           1
test_large            112.4638 (22.45)    120.6921 (16.13)    116.3287 (21.87)    2.9104 (8.78)     116.3253 (22.11)    5.0715 (30.69)         4;0    8.5963 (0.05)          9           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.1134 (1.0)        7.5196 (1.0)        5.3400 (1.0)      0.2995 (1.0)        5.2774 (1.0)      0.1251 (1.0)          7;10  187.2676 (1.0)         187           1
test_smooth_1000       53.7028 (10.50)     58.3828 (7.76)      55.1907 (10.34)    1.5705 (5.24)      54.4994 (10.33)    1.1452 (9.15)          4;4   18.1190 (0.10)         19           1
test_large            113.6079 (22.22)    122.6846 (16.32)    116.3847 (21.80)    3.6097 (12.05)    114.6583 (21.73)    4.1340 (33.04)         2;0    8.5922 (0.05)          9           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

----------------------------------------------------------------------------------- benchmark: 3 tests -----------------------------------------------------------------------------------
Name (time in ms)          Min                 Max                Mean            StdDev              Median               IQR            Outliers       OPS            Rounds  Iterations
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
test_small              5.0263 (1.0)        7.4791 (1.0)        5.2821 (1.0)      0.2391 (1.0)        5.2491 (1.0)      0.1043 (1.0)         10;12  189.3175 (1.0)         190           1
test_smooth_1000       53.2688 (10.60)     61.0834 (8.17)      54.6131 (10.34)    1.7800 (7.44)      54.0731 (10.30)    1.2326 (11.82)         2;1   18.3106 (0.10)         19           1
test_large            113.3363 (22.55)    115.6210 (15.46)    114.3397 (21.65)    0.7581 (3.17)     114.3845 (21.79)    1.0992 (10.54)         4;0    8.7459 (0.05)          9           1
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------


@hjweide
Copy link
Owner

hjweide commented May 9, 2022

Nice idea. Feel free to put up a new PR for this if you like. It looks like the improvement is small but still worth including. I've already merged and published this one because I figured you want to use this tomorrow (Monday).

@peterchenadded
Copy link
Contributor Author

Yeah improvement is too small, will cancel the PR.

@peterchenadded
Copy link
Contributor Author

Thanks for all the awesome help and patience, we finally got there!

@hjweide
Copy link
Owner

hjweide commented May 9, 2022

Happy to help! Thanks for seeing this through. And thanks for your work to get the package published automatically -- that was a big help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants