Skip to content

Conversation

@LoveLow-Global
Copy link

Implement iFUB algorithm for diameter calculation of unweighted graphs, SimpleGraph and SimpleDiGraph

Below is a comparison with the original diameter calculation logic, ran on my desktop.

using Graphs

g = erdos_renyi(10000, 0.005) # 10k nodes, sparse

# New implentation
@time d = diameter(g) # 0.910222 seconds (372.05 k allocations: 6.602 MiB)

# Original Method
original_diameter(g) = maximum(eccentricity(g)) 
@time original_diameter(g) # 41.471079 seconds (650.01 k allocations: 13.515 GiB, 3.59% gc time)

Implement iFUB algorithm for unweighted diameter.
@codecov
Copy link

codecov bot commented Dec 20, 2025

Codecov Report

❌ Patch coverage is 98.52941% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 97.17%. Comparing base (4176651) to head (67d7344).

Files with missing lines Patch % Lines
src/distance.jl 98.52% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master     #482      +/-   ##
==========================================
+ Coverage   97.16%   97.17%   +0.01%     
==========================================
  Files         121      121              
  Lines        7020     7088      +68     
==========================================
+ Hits         6821     6888      +67     
- Misses        199      200       +1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Krastanov
Copy link
Member

Thank you! On first look this looks great, but it will take a bit to get a proper review.

In the meantime, we should probably have some more rigorous tests for it added. (1) Tests comparing against large graphs with known diameters (e.g. by construction); and (2) tests comparing against the old slow implementation for random graphs. Could you add such tests, maybe something that adds an additional 60 seconds to the tests, but with a "number of random samples" parameter that I can change locally and run for a few hours on my machine?

Added some more rigorous tests
@LoveLow-Global
Copy link
Author

LoveLow-Global commented Dec 21, 2025

Hello Krastanov, thanks for the comment. I have added (1) comparison against graphs with known diameters and the (2) comparison with old slow implementation for random graphs, under test/distance.jl. You can change NUM_SAMPLES there. Also, please note that it is my first time contributing to an existing Julia package, so please tell me if there is any changes to be done.

@Krastanov
Copy link
Member

Thanks, this looks great! I will try to review this in the next few days.

One other thing that I need to check lately -- if you used an LLM-like tool, could you disclose that, which tool, and what the prompt was? I do not see anything in your PR that makes me think that was the case, and it is not like LLM tools are bad (they help a lot), but they do require approaching the review differently and having this extra info helps.

@LoveLow-Global
Copy link
Author

Thanks for the feedback! I have used Gemini 3.0 for code generation. This optimization method was originally used in one of my researches, but I needed to change the style of the code to be similar to Graphs.jl. Therefore, I used Gemini to first change the code into a "Graphs.jl" format. Then I manually edited the codes again.

@Krastanov
Copy link
Member

Do you happen to have a reference of where this algorithm was introduced first / who named it iFUB, etc? Or a textbook about it?

@Krastanov
Copy link
Member

Pardon the formatter error -- it seems it is due to an incorrect security configuration on our end, not due to your code.

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.

2 participants