Skip to content

Euclidean generator and tsp enhancements#467

Open
megyhazy wants to merge 25 commits intoboostorg:developfrom
megyhazy:euclidean_generator_and_tsp_enhancements
Open

Euclidean generator and tsp enhancements#467
megyhazy wants to merge 25 commits intoboostorg:developfrom
megyhazy:euclidean_generator_and_tsp_enhancements

Conversation

@megyhazy
Copy link
Copy Markdown

@megyhazy megyhazy commented Apr 4, 2026

Thoughts:

  • Generates complete graph. Does this need to be in the prototype name?
  • There is an example that prints graphs and executes an MST algorithm. Maybe unnecessarily complex and can be removed.
  • This is the beginning of refactoring the TSP heuristics to be more modular and have re-usable components vs the way it is now. I intend to refactor metric_tsp and then add nearest_neighbor
  • This is related to issue Euclidian Random Graphs Utilities #452

Addressed earlier comments:

  1. Added test and example to Jamfiles
  2. To euclidean_graph_generator.hpp: Added BOOST_CONCEPT_ASSERT((MutableGraphConcept < VertexListGraph >));
  3. To euclidean_graph_generator.hpp: Removed unused type declarations, PointType / CoordType
  4. To euclidean_graph_generator.hpp: Added assert to compare size of points and graph.

@megyhazy megyhazy marked this pull request as ready for review April 4, 2026 22:18
@jeremy-murphy
Copy link
Copy Markdown
Collaborator

jeremy-murphy commented Apr 14, 2026

Hey, thank you, this looks great!

I'm just wondering about how generic to make it now or later. I'm thinking along two separate lines:

  • the difference between a euclidean and non-euclidean graph is entirely in the distance calculation, meaning most of the code for generating a random graph is the same
  • Boost.Geometry is an obvious choice for representing geometry in the first place, so I want their users to easily be able to provide data without converting their types.

The Boost.Geometry syntax is distance(a, b), so I'm more inclined to make our code do the same thing, such that a Boost.Geometry point type will just work, which I guess means that we define distance(boost::simple_point, boost::simple_point) to use std::hypot and use distance(a, b) in our code. This actually solves both problems at once, because euclidean and non-euclidean points in Boost.Geometry have the same interface. I guess it means that these functions would no longer be specific to euclidean geometry and so they would be better named make_geometric_graph, etc.

What do you think? I don't want to hold up your work for too long but I think this should actually be a fairly small change for a big flexibility.

Edit: Removed my stupid comment before anyone noticed. :)

@jeremy-murphy jeremy-murphy self-assigned this Apr 14, 2026
@megyhazy
Copy link
Copy Markdown
Author

megyhazy commented Apr 15, 2026 via email

…s euclidean - and compatible with boost.geometry
…s euclidean - and compatible with boost.geometry
…s euclidean - and compatible with boost.geometry
@megyhazy
Copy link
Copy Markdown
Author

megyhazy commented Apr 18, 2026 via email

…s euclidean - and compatible with boost.geometry
…s euclidean - and compatible with boost.geometry
…s euclidean - and compatible with boost.geometry
…s euclidean - and compatible with boost.geometry
@jeremy-murphy
Copy link
Copy Markdown
Collaborator

Hmm ok, thanks for giving it a go. I'll take a closer look on Monday or Tuesday.

Comment thread test/geometric_graph_generator_test.cpp Outdated
boost::generate_random_points(
num_points, 10000, std::back_inserter(points));

std::set< std::pair< double, double > > unique_points;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Although performance doesn't matter here, it's a good habit to get into using boost::unordered_flat_(set|map) in preference to std::(set|map) or std::unordered_(set|map) when the requirements are equivalent (such as here).

Comment thread test/geometric_graph_generator_test.cpp Outdated
std::set< std::pair< double, double > > unique_points;
for (const auto& p : points)
{
unique_points.insert(std::make_pair(p.x, p.y));
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

If you assert on the result of this insertion then the test will fail as soon as the first duplicate is hit rather than waiting until the end. (Admittedly, not a big deal when n = 100.) It might not be so useful for random graphs, but for non-random graphs it is then straightforward to print which value it failed on, which is more useful than only knowing that size() != num_points.

#include <boost/unordered/unordered_flat_set.hpp>
#include <boost/concept/assert.hpp>
#include <boost/graph/graph_concepts.hpp>
#include <boost/geometry.hpp>
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Ah, so just quickly, this file shouldn't refer to Boost Geometry at all, only an example file should. We're going to copy the Boost Geometry interface here without referring to it directly.
If that doesn't make sense, don't worry, I'll have a go at getting it to work next week.

@megyhazy
Copy link
Copy Markdown
Author

megyhazy commented Apr 18, 2026 via email

@megyhazy
Copy link
Copy Markdown
Author

megyhazy commented Apr 18, 2026 via email

@jeremy-murphy
Copy link
Copy Markdown
Collaborator

Ahh, yeah, std::distance exists and will cause problems if it is found via ADL. We might have to offer two overloads: one that uses distance found via ADL and one that allows the user to pass the distance function in.

@megyhazy
Copy link
Copy Markdown
Author

megyhazy commented Apr 20, 2026 via email

@jeremy-murphy
Copy link
Copy Markdown
Collaborator

Using distance is more problematic than I expected, after I experimented with it a bit.
Boost also has boost::distance which is the same as std::distance. The Boost Geometry library always qualifies their use of algorithms with boost::geometry::, but we don't even have a boost::graph:: namespace to disambiguate with. However, I do have one more trick to try tomorrow...

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