32 cout <<
"=== Euclidean Graphs: Educational Examples ===\n\n";
38 cout <<
"--- Example 1: City Network (Automatic Distance Calculation) ---\n\n";
45 cout <<
"Building US East Coast city network...\n\n";
52 auto dc =
city_map.insert_node(
"Washington DC",
Point(38.9072, -77.0369));
54 cout <<
"Cities added:\n";
55 cout <<
" NYC: (40.71, -74.01)\n";
56 cout <<
" Boston: (42.36, -71.06)\n";
57 cout <<
" Philadelphia: (39.95, -75.17)\n";
58 cout <<
" Washington DC: (38.91, -77.04)\n\n";
61 cout <<
"Connecting cities (distances auto-calculated):\n";
68 cout <<
" NYC -> Boston: " <<
city_map.get_distance(arc1) <<
" degrees\n";
69 cout <<
" NYC -> Philadelphia: " <<
city_map.get_distance(arc2) <<
" degrees\n";
70 cout <<
" Philadelphia -> DC: " <<
city_map.get_distance(
arc3) <<
" degrees\n\n";
72 cout <<
"KEY INSIGHT: You provide positions, graph computes distances!\n";
73 cout <<
" Perfect for geographic applications\n\n";
80 cout <<
"--- Example 2: Finding Nearest City ---\n\n";
92 cout <<
"Cities in network: NYC, Boston, Philadelphia, Baltimore, DC\n\n";
97 cout <<
"Query: What city is nearest to point (40.5, -74.5)?\n";
98 cout <<
" (This is somewhere in New Jersey)\n\n";
107 auto city = it.get_curr();
111 cout <<
" Distance to " <<
city->get_info() <<
": " << dist <<
"\n";
124 cout <<
"APPLICATION: Location-based services, routing, facility placement\n\n";
131 cout <<
"--- Example 3: Minimum Spanning Tree (Optimal Road Network) ---\n\n";
143 cout <<
"5 cities positioned on a grid\n";
144 cout <<
"Goal: Connect all cities with minimum total road length\n\n";
151 cout <<
"All possible connections:\n";
155 for (
size_t i = 0; i <
nodes.size(); ++i)
156 for (
size_t j = i + 1; j <
nodes.size(); ++j)
159 auto dist =
cities.get_distance(arc);
163 cout <<
" " <<
nodes[i]->get_info() <<
" <-> "
164 <<
nodes[j]->get_info() <<
": " << dist <<
"\n";
167 cout <<
"\nTotal if we build ALL roads: " <<
total_all <<
"\n";
170 cout <<
"OPTIMIZATION PROBLEM:\n";
171 cout <<
" Minimum Spanning Tree finds minimum total length\n";
172 cout <<
" to connect all cities (n-1 = 4 roads needed)\n";
173 cout <<
" MST would use approximately 50% of total road length\n\n";
180 cout <<
"--- Example 4: Distance Matrix ---\n\n";
187 for (
int i = 0; i < 4; ++i)
190 int y = (i % 2) * 10;
195 cout <<
"Delivery network: 4 locations\n";
196 cout <<
"Computing all-pairs distances...\n\n";
199 cout <<
"Distance Matrix:\n";
202 cout <<
" [" << j <<
"] ";
207 cout <<
"[" << i <<
"] ";
212 auto dist = pi.distance_with(
pj);
213 cout <<
" " << dist <<
" ";
218 cout <<
"\nUSE CASE: Route optimization, delivery planning, TSP\n\n";
225 cout <<
"--- Example 5: 3D Space (Satellites/Drones) ---\n\n";
227 cout <<
"EXTENDING TO 3D:\n";
228 cout <<
" Same concepts apply to 3D coordinates (x, y, z)\n";
229 cout <<
" Distance formula: sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2)\n\n";
231 cout <<
"APPLICATIONS:\n";
232 cout <<
" * Satellite networks (3D positions in space)\n";
233 cout <<
" * Drone delivery routes (altitude matters)\n";
234 cout <<
" * 3D pathfinding in games\n";
235 cout <<
" * Molecular structures (atoms in 3D)\n\n";
237 cout <<
"IMPLEMENTATION:\n";
238 cout <<
" Use Point3D class or extend Point to 3D\n";
239 cout <<
" Distance calculation automatic for any dimension\n\n";
242 cout <<
"=== SUMMARY: Euclidean Graphs ===\n";
243 cout <<
"\n1. AUTOMATIC DISTANCE CALCULATION:\n";
244 cout <<
" * Set node positions\n";
245 cout <<
" * Distances computed from Euclidean formula\n";
246 cout <<
" * No manual weight assignment needed\n";
247 cout <<
"\n2. WHEN TO USE:\n";
248 cout <<
" ✓ Geographic networks (cities, roads)\n";
249 cout <<
" ✓ Facility location problems\n";
250 cout <<
" ✓ Robotics (motion planning)\n";
251 cout <<
" ✓ Wireless networks (signal range)\n";
252 cout <<
" ✓ Computer graphics (scene graphs)\n";
253 cout <<
"\n3. KEY OPERATIONS:\n";
254 cout <<
" - insert_node(info, Point(x,y))\n";
255 cout <<
" - get_distance(arc) → auto-computed\n";
256 cout <<
" - get_position(node) → Point\n";
257 cout <<
" - Nearest neighbor queries\n";
258 cout <<
"\n4. ADVANTAGES:\n";
259 cout <<
" * Consistency: distances always match positions\n";
260 cout <<
" * Convenience: no manual distance computation\n";
261 cout <<
" * Natural for spatial problems\n";
262 cout <<
"\n5. ALGORITHMS:\n";
263 cout <<
" All graph algorithms work:\n";
264 cout <<
" * Dijkstra (shortest paths)\n";
265 cout <<
" * MST (minimum spanning tree)\n";
266 cout <<
" * TSP (traveling salesman)\n";
267 cout <<
" Plus geometric-specific:\n";
268 cout <<
" * Nearest neighbor\n";
269 cout <<
" * Range queries\n";
270 cout <<
" * Voronoi diagrams\n";
271 cout <<
"\n6. DISTANCE FORMULA:\n";
272 cout <<
" 2D: sqrt((x2-x1)^2 + (y2-y1)^2)\n";
273 cout <<
" 3D: sqrt((x2-x1)^2 + (y2-y1)^2 + (z2-z1)^2)\n";
274 cout <<
" Time: O(1) per calculation\n";
Dynamic singly linked list with functional programming support.
T & append(const T &item)
Append a new item by copy.
void next()
Advances the iterator to the next filtered element.
size_t size() const noexcept
Count the number of elements of the list.
Filtered iterator on the nodes of a graph.
Rectangular point in the plane.
DynArray< Graph::Node * > nodes
Main namespace for Aleph-w library functions.
DynList< T > maps(const C &c, Op op)
Classic map operation.
2D point and geometric utilities.
Euclidean graph with 2D coordinates.