terraproof 0.0.0-stage → 0.4.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (182) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +356 -2
  3. package/bin/terraproof.js +4 -0
  4. package/dist/router/apply.js +147 -0
  5. package/dist/router/classify.js +111 -0
  6. package/dist/router/explain.js +9 -0
  7. package/dist/router/index.js +272 -0
  8. package/dist/router/resolve.js +239 -0
  9. package/dist/router/score.js +60 -0
  10. package/dist/router/types.js +1 -0
  11. package/dist/router/validate.js +81 -0
  12. package/instructions/engineering.md +14 -0
  13. package/instructions/security.md +14 -0
  14. package/instructions/simplicity.md +13 -0
  15. package/package.json +65 -4
  16. package/routing/DOMAIN_ROUTING.md +161 -0
  17. package/routing/ROUTER_DESIGN.md +173 -0
  18. package/routing/SKILL_MANIFEST.md +86 -0
  19. package/routing/checks.json +121 -0
  20. package/routing/collections.json +47 -0
  21. package/routing/registry.json +2211 -0
  22. package/routing/rules.json +64 -0
  23. package/skills/accuracy-assessment/SKILL.md +213 -0
  24. package/skills/accuracy-assessment/UPSTREAM.md +7 -0
  25. package/skills/accuracy-assessment/references/stratified-estimator.md +127 -0
  26. package/skills/accuracy-assessment/skill.json +103 -0
  27. package/skills/brainstorming/SKILL.md +250 -0
  28. package/skills/brainstorming/UPSTREAM.md +29 -0
  29. package/skills/brainstorming/scripts/frame-template.html +213 -0
  30. package/skills/brainstorming/scripts/helper.js +167 -0
  31. package/skills/brainstorming/scripts/server.cjs +723 -0
  32. package/skills/brainstorming/scripts/start-server.sh +209 -0
  33. package/skills/brainstorming/scripts/stop-server.sh +120 -0
  34. package/skills/brainstorming/skill.json +73 -0
  35. package/skills/brainstorming/spec-document-reviewer-prompt.md +49 -0
  36. package/skills/brainstorming/visual-companion.md +299 -0
  37. package/skills/crs-and-units/SKILL.md +200 -0
  38. package/skills/crs-and-units/UPSTREAM.md +7 -0
  39. package/skills/crs-and-units/skill.json +74 -0
  40. package/skills/design-postgis-tables/SKILL.md +494 -0
  41. package/skills/design-postgis-tables/UPSTREAM.md +21 -0
  42. package/skills/design-postgis-tables/skill.json +90 -0
  43. package/skills/gdal/SKILL.md +125 -0
  44. package/skills/gdal/UPSTREAM.md +22 -0
  45. package/skills/gdal/references/gdal-recipes.md +103 -0
  46. package/skills/gdal/skill.json +66 -0
  47. package/skills/geomaster/README.md +105 -0
  48. package/skills/geomaster/SKILL.md +366 -0
  49. package/skills/geomaster/UPSTREAM.md +21 -0
  50. package/skills/geomaster/references/advanced-gis.md +376 -0
  51. package/skills/geomaster/references/big-data.md +363 -0
  52. package/skills/geomaster/references/code-examples.md +531 -0
  53. package/skills/geomaster/references/coordinate-systems.md +364 -0
  54. package/skills/geomaster/references/core-libraries.md +273 -0
  55. package/skills/geomaster/references/data-sources.md +330 -0
  56. package/skills/geomaster/references/gis-software.md +369 -0
  57. package/skills/geomaster/references/industry-applications.md +420 -0
  58. package/skills/geomaster/references/machine-learning.md +462 -0
  59. package/skills/geomaster/references/programming-languages.md +456 -0
  60. package/skills/geomaster/references/remote-sensing.md +370 -0
  61. package/skills/geomaster/references/scientific-domains.md +416 -0
  62. package/skills/geomaster/references/specialized-topics.md +428 -0
  63. package/skills/geomaster/references/troubleshooting.md +439 -0
  64. package/skills/geomaster/skill.json +157 -0
  65. package/skills/geopandas/SKILL.md +250 -0
  66. package/skills/geopandas/UPSTREAM.md +22 -0
  67. package/skills/geopandas/references/crs-management.md +231 -0
  68. package/skills/geopandas/references/data-io.md +323 -0
  69. package/skills/geopandas/references/data-structures.md +207 -0
  70. package/skills/geopandas/references/geometric-operations.md +262 -0
  71. package/skills/geopandas/references/spatial-analysis.md +294 -0
  72. package/skills/geopandas/references/visualization.md +230 -0
  73. package/skills/geopandas/scripts/_common.py +605 -0
  74. package/skills/geopandas/scripts/crs_reprojection_plan.py +210 -0
  75. package/skills/geopandas/scripts/export_plan.py +305 -0
  76. package/skills/geopandas/scripts/geometry_validity_report.py +227 -0
  77. package/skills/geopandas/scripts/sensitive_coordinates_checklist.py +230 -0
  78. package/skills/geopandas/scripts/spatial_join_audit.py +368 -0
  79. package/skills/geopandas/scripts/vector_inventory.py +140 -0
  80. package/skills/geopandas/skill.json +116 -0
  81. package/skills/geoparquet-validation/SKILL.md +125 -0
  82. package/skills/geoparquet-validation/UPSTREAM.md +24 -0
  83. package/skills/geoparquet-validation/references/distribution-best-practices.md +118 -0
  84. package/skills/geoparquet-validation/references/gpio-commands.md +264 -0
  85. package/skills/geoparquet-validation/references/tool-comparison.md +155 -0
  86. package/skills/geoparquet-validation/skill.json +71 -0
  87. package/skills/geospatial-data-discovery/SKILL.md +49 -0
  88. package/skills/geospatial-data-discovery/UPSTREAM.md +15 -0
  89. package/skills/geospatial-data-discovery/skill.json +51 -0
  90. package/skills/geospatial-frontend/SKILL.md +86 -0
  91. package/skills/geospatial-frontend/UPSTREAM.md +23 -0
  92. package/skills/geospatial-frontend/references/design-system.md +283 -0
  93. package/skills/geospatial-frontend/references/user-preferences.md +96 -0
  94. package/skills/geospatial-frontend/skill.json +87 -0
  95. package/skills/geozarr/SKILL.md +244 -0
  96. package/skills/geozarr/UPSTREAM.md +21 -0
  97. package/skills/geozarr/skill.json +97 -0
  98. package/skills/networkx/SKILL.md +440 -0
  99. package/skills/networkx/UPSTREAM.md +22 -0
  100. package/skills/networkx/references/algorithms.md +384 -0
  101. package/skills/networkx/references/generators.md +385 -0
  102. package/skills/networkx/references/graph-basics.md +284 -0
  103. package/skills/networkx/references/io.md +457 -0
  104. package/skills/networkx/references/visualization.md +531 -0
  105. package/skills/networkx/skill.json +93 -0
  106. package/skills/raster-processing/SKILL.md +222 -0
  107. package/skills/raster-processing/UPSTREAM.md +7 -0
  108. package/skills/raster-processing/skill.json +81 -0
  109. package/skills/sar-basics/SKILL.md +202 -0
  110. package/skills/sar-basics/UPSTREAM.md +7 -0
  111. package/skills/sar-basics/references/calibration-lut.md +98 -0
  112. package/skills/sar-basics/skill.json +97 -0
  113. package/skills/satellite-preprocessing/SKILL.md +241 -0
  114. package/skills/satellite-preprocessing/UPSTREAM.md +7 -0
  115. package/skills/satellite-preprocessing/skill.json +84 -0
  116. package/skills/scientific-visualization/SKILL.md +285 -0
  117. package/skills/scientific-visualization/UPSTREAM.md +25 -0
  118. package/skills/scientific-visualization/assets/color_palettes.py +263 -0
  119. package/skills/scientific-visualization/assets/nature.mplstyle +68 -0
  120. package/skills/scientific-visualization/assets/presentation.mplstyle +68 -0
  121. package/skills/scientific-visualization/assets/publication.mplstyle +77 -0
  122. package/skills/scientific-visualization/assets/publisher_profiles.json +269 -0
  123. package/skills/scientific-visualization/references/color_palettes.md +227 -0
  124. package/skills/scientific-visualization/references/journal_requirements.md +169 -0
  125. package/skills/scientific-visualization/references/matplotlib_examples.md +336 -0
  126. package/skills/scientific-visualization/references/publication_guidelines.md +196 -0
  127. package/skills/scientific-visualization/references/sources.md +76 -0
  128. package/skills/scientific-visualization/scripts/_common.py +136 -0
  129. package/skills/scientific-visualization/scripts/export_plan.py +493 -0
  130. package/skills/scientific-visualization/scripts/figure_export.py +642 -0
  131. package/skills/scientific-visualization/scripts/image_metadata.py +731 -0
  132. package/skills/scientific-visualization/scripts/palette_audit.py +327 -0
  133. package/skills/scientific-visualization/scripts/style_presets.py +501 -0
  134. package/skills/scientific-visualization/scripts/style_preview.py +232 -0
  135. package/skills/scientific-visualization/skill.json +95 -0
  136. package/skills/spectral-indices/SKILL.md +235 -0
  137. package/skills/spectral-indices/UPSTREAM.md +7 -0
  138. package/skills/spectral-indices/skill.json +88 -0
  139. package/skills/stac-and-cloud-access/SKILL.md +209 -0
  140. package/skills/stac-and-cloud-access/UPSTREAM.md +7 -0
  141. package/skills/stac-and-cloud-access/references/run-manifest.md +94 -0
  142. package/skills/stac-and-cloud-access/skill.json +98 -0
  143. package/skills/statistical-analysis/SKILL.md +446 -0
  144. package/skills/statistical-analysis/UPSTREAM.md +24 -0
  145. package/skills/statistical-analysis/references/assumptions_and_diagnostics.md +379 -0
  146. package/skills/statistical-analysis/references/bayesian_statistics.md +686 -0
  147. package/skills/statistical-analysis/references/effect_sizes_and_power.md +649 -0
  148. package/skills/statistical-analysis/references/reporting_standards.md +482 -0
  149. package/skills/statistical-analysis/references/test_selection_guide.md +129 -0
  150. package/skills/statistical-analysis/scripts/assumption_checks.py +652 -0
  151. package/skills/statistical-analysis/skill.json +127 -0
  152. package/skills/systematic-debugging/SKILL.md +283 -0
  153. package/skills/systematic-debugging/UPSTREAM.md +28 -0
  154. package/skills/systematic-debugging/condition-based-waiting-example.ts +158 -0
  155. package/skills/systematic-debugging/condition-based-waiting.md +115 -0
  156. package/skills/systematic-debugging/defense-in-depth.md +122 -0
  157. package/skills/systematic-debugging/find-polluter.sh +72 -0
  158. package/skills/systematic-debugging/root-cause-tracing.md +169 -0
  159. package/skills/systematic-debugging/skill.json +88 -0
  160. package/skills/time-series-and-change/SKILL.md +217 -0
  161. package/skills/time-series-and-change/UPSTREAM.md +7 -0
  162. package/skills/time-series-and-change/references/change-methods.md +42 -0
  163. package/skills/time-series-and-change/skill.json +116 -0
  164. package/skills/vector-quality/SKILL.md +204 -0
  165. package/skills/vector-quality/UPSTREAM.md +7 -0
  166. package/skills/vector-quality/skill.json +82 -0
  167. package/skills/verification/SKILL.md +120 -0
  168. package/skills/verification/UPSTREAM.md +31 -0
  169. package/skills/verification/skill.json +67 -0
  170. package/skills/writing-plans/SKILL.md +171 -0
  171. package/skills/writing-plans/UPSTREAM.md +23 -0
  172. package/skills/writing-plans/plan-document-reviewer-prompt.md +49 -0
  173. package/skills/writing-plans/skill.json +80 -0
  174. package/sources/SOURCES.md +374 -0
  175. package/third_party/isaaccorley-geospatial-skills/LICENSE +176 -0
  176. package/third_party/isaaccorley-geospatial-skills/NOTICE.md +17 -0
  177. package/third_party/kdense-scientific-agent-skills/LICENSE +21 -0
  178. package/third_party/kdense-scientific-agent-skills/NOTICE.md +19 -0
  179. package/third_party/superpowers/LICENSE +21 -0
  180. package/third_party/superpowers/NOTICE.md +17 -0
  181. package/third_party/timescale-pg-aiguide/LICENSE +176 -0
  182. package/third_party/timescale-pg-aiguide/NOTICE.md +14 -0
@@ -0,0 +1,384 @@
1
+ # NetworkX Graph Algorithms
2
+
3
+ ## Shortest Paths
4
+
5
+ ### Single Source Shortest Paths
6
+ ```python
7
+ # Dijkstra's algorithm (weighted graphs)
8
+ path = nx.shortest_path(G, source=1, target=5, weight='weight')
9
+ length = nx.shortest_path_length(G, source=1, target=5, weight='weight')
10
+
11
+ # All shortest paths from source
12
+ paths = nx.single_source_shortest_path(G, source=1)
13
+ lengths = nx.single_source_shortest_path_length(G, source=1)
14
+
15
+ # Bellman-Ford (handles negative weights)
16
+ path = nx.bellman_ford_path(G, source=1, target=5, weight='weight')
17
+ ```
18
+
19
+ ### All Pairs Shortest Paths
20
+ ```python
21
+ # All pairs (returns iterator)
22
+ for source, paths in nx.all_pairs_shortest_path(G):
23
+ print(f"From {source}: {paths}")
24
+
25
+ # Floyd-Warshall algorithm
26
+ lengths = dict(nx.all_pairs_shortest_path_length(G))
27
+ ```
28
+
29
+ ### Specialized Shortest Path Algorithms
30
+ ```python
31
+ # A* algorithm (with heuristic)
32
+ def heuristic(u, v):
33
+ # Custom heuristic function
34
+ return abs(u - v)
35
+
36
+ path = nx.astar_path(G, source=1, target=5, heuristic=heuristic, weight='weight')
37
+
38
+ # Average shortest path length
39
+ avg_length = nx.average_shortest_path_length(G)
40
+ ```
41
+
42
+ ## Connectivity
43
+
44
+ ### Connected Components (Undirected)
45
+ ```python
46
+ # Check if connected
47
+ is_connected = nx.is_connected(G)
48
+
49
+ # Number of components
50
+ num_components = nx.number_connected_components(G)
51
+
52
+ # Get all components (returns iterator of sets)
53
+ components = list(nx.connected_components(G))
54
+ largest_component = max(components, key=len)
55
+
56
+ # Get component containing specific node
57
+ component = nx.node_connected_component(G, node=1)
58
+ ```
59
+
60
+ ### Strong/Weak Connectivity (Directed)
61
+ ```python
62
+ # Strong connectivity (mutually reachable)
63
+ is_strongly_connected = nx.is_strongly_connected(G)
64
+ strong_components = list(nx.strongly_connected_components(G))
65
+ largest_scc = max(strong_components, key=len)
66
+
67
+ # Weak connectivity (ignoring direction)
68
+ is_weakly_connected = nx.is_weakly_connected(G)
69
+ weak_components = list(nx.weakly_connected_components(G))
70
+
71
+ # Condensation (DAG of strongly connected components)
72
+ condensed = nx.condensation(G)
73
+ ```
74
+
75
+ ### Cuts and Connectivity
76
+ ```python
77
+ # Minimum node/edge cut
78
+ min_node_cut = nx.minimum_node_cut(G, s=1, t=5)
79
+ min_edge_cut = nx.minimum_edge_cut(G, s=1, t=5)
80
+
81
+ # Node/edge connectivity
82
+ node_connectivity = nx.node_connectivity(G)
83
+ edge_connectivity = nx.edge_connectivity(G)
84
+ ```
85
+
86
+ ## Centrality Measures
87
+
88
+ ### Degree Centrality
89
+ ```python
90
+ # Fraction of nodes each node is connected to
91
+ degree_cent = nx.degree_centrality(G)
92
+
93
+ # For directed graphs
94
+ in_degree_cent = nx.in_degree_centrality(G)
95
+ out_degree_cent = nx.out_degree_centrality(G)
96
+ ```
97
+
98
+ ### Betweenness Centrality
99
+ ```python
100
+ # Fraction of shortest paths passing through node
101
+ betweenness = nx.betweenness_centrality(G, weight='weight')
102
+
103
+ # Edge betweenness
104
+ edge_betweenness = nx.edge_betweenness_centrality(G, weight='weight')
105
+
106
+ # Approximate for large graphs
107
+ approx_betweenness = nx.betweenness_centrality(G, k=100) # Sample 100 nodes
108
+ ```
109
+
110
+ ### Closeness Centrality
111
+ ```python
112
+ # Reciprocal of average shortest path length
113
+ closeness = nx.closeness_centrality(G)
114
+
115
+ # For disconnected graphs
116
+ closeness = nx.closeness_centrality(G, wf_improved=True)
117
+ ```
118
+
119
+ ### Eigenvector Centrality
120
+ ```python
121
+ # Centrality based on connections to high-centrality nodes
122
+ eigenvector = nx.eigenvector_centrality(G, max_iter=1000)
123
+
124
+ # Katz centrality (variant with attenuation factor)
125
+ katz = nx.katz_centrality(G, alpha=0.1, beta=1.0)
126
+ ```
127
+
128
+ ### PageRank
129
+ ```python
130
+ # Google's PageRank algorithm
131
+ pagerank = nx.pagerank(G, alpha=0.85)
132
+
133
+ # Personalized PageRank
134
+ personalization = {node: 1.0 if node in [1, 2] else 0.0 for node in G}
135
+ ppr = nx.pagerank(G, personalization=personalization)
136
+ ```
137
+
138
+ ## Clustering
139
+
140
+ ### Clustering Coefficients
141
+ ```python
142
+ # Clustering coefficient for each node
143
+ clustering = nx.clustering(G)
144
+
145
+ # Average clustering coefficient
146
+ avg_clustering = nx.average_clustering(G)
147
+
148
+ # Weighted clustering
149
+ weighted_clustering = nx.clustering(G, weight='weight')
150
+ ```
151
+
152
+ ### Transitivity
153
+ ```python
154
+ # Overall clustering (ratio of triangles to triads)
155
+ transitivity = nx.transitivity(G)
156
+ ```
157
+
158
+ ### Triangles
159
+ ```python
160
+ # Count triangles per node
161
+ triangles = nx.triangles(G)
162
+
163
+ # Total number of triangles
164
+ total_triangles = sum(triangles.values()) // 3
165
+ ```
166
+
167
+ ## Community Detection
168
+
169
+ ### Modularity-Based
170
+ ```python
171
+ from networkx.algorithms import community
172
+
173
+ # Greedy modularity maximization
174
+ communities = community.greedy_modularity_communities(G)
175
+
176
+ # Compute modularity
177
+ modularity = community.modularity(G, communities)
178
+ ```
179
+
180
+ ### Label Propagation
181
+ ```python
182
+ # Fast community detection
183
+ communities = community.label_propagation_communities(G)
184
+ ```
185
+
186
+ ### Girvan-Newman
187
+ ```python
188
+ # Hierarchical community detection via edge betweenness
189
+ comp = community.girvan_newman(G)
190
+ limited = itertools.takewhile(lambda c: len(c) <= 10, comp)
191
+ for communities in limited:
192
+ print(tuple(sorted(c) for c in communities))
193
+ ```
194
+
195
+ ## Matching and Covering
196
+
197
+ ### Maximum Matching
198
+ ```python
199
+ # Maximum cardinality matching
200
+ matching = nx.max_weight_matching(G)
201
+
202
+ # Check if matching is valid
203
+ is_matching = nx.is_matching(G, matching)
204
+ is_perfect = nx.is_perfect_matching(G, matching)
205
+ ```
206
+
207
+ ### Minimum Vertex/Edge Cover
208
+ ```python
209
+ # Minimum set of nodes covering all edges
210
+ min_vertex_cover = nx.approximation.min_weighted_vertex_cover(G)
211
+
212
+ # Minimum edge dominating set
213
+ min_edge_dom = nx.approximation.min_edge_dominating_set(G)
214
+ ```
215
+
216
+ ## Tree Algorithms
217
+
218
+ ### Minimum Spanning Tree
219
+ ```python
220
+ # Kruskal's or Prim's algorithm
221
+ mst = nx.minimum_spanning_tree(G, weight='weight')
222
+
223
+ # Maximum spanning tree
224
+ mst_max = nx.maximum_spanning_tree(G, weight='weight')
225
+
226
+ # Iterate over spanning trees in order of increasing total weight
227
+ for tree in nx.SpanningTreeIterator(G):
228
+ process(tree)
229
+ ```
230
+
231
+ ### Tree Properties
232
+ ```python
233
+ # Check if graph is tree
234
+ is_tree = nx.is_tree(G)
235
+ is_forest = nx.is_forest(G)
236
+
237
+ # For directed graphs
238
+ is_arborescence = nx.is_arborescence(G)
239
+ ```
240
+
241
+ ## Flow and Capacity
242
+
243
+ ### Maximum Flow
244
+ ```python
245
+ # Maximum flow value
246
+ flow_value = nx.maximum_flow_value(G, s=1, t=5, capacity='capacity')
247
+
248
+ # Maximum flow with flow dict
249
+ flow_value, flow_dict = nx.maximum_flow(G, s=1, t=5, capacity='capacity')
250
+
251
+ # Minimum cut
252
+ cut_value, partition = nx.minimum_cut(G, s=1, t=5, capacity='capacity')
253
+ ```
254
+
255
+ ### Cost Flow
256
+ ```python
257
+ # Minimum cost flow
258
+ flow_dict = nx.min_cost_flow(G, demand='demand', capacity='capacity', weight='weight')
259
+ cost = nx.cost_of_flow(G, flow_dict, weight='weight')
260
+ ```
261
+
262
+ ## Cycles
263
+
264
+ ### Finding Cycles
265
+ ```python
266
+ # Simple cycles (for directed graphs)
267
+ cycles = list(nx.simple_cycles(G))
268
+
269
+ # Cycle basis (for undirected graphs)
270
+ basis = nx.cycle_basis(G)
271
+
272
+ # Check if acyclic
273
+ is_dag = nx.is_directed_acyclic_graph(G)
274
+ ```
275
+
276
+ ### Topological Sorting
277
+ ```python
278
+ # Only for DAGs
279
+ try:
280
+ topo_order = list(nx.topological_sort(G))
281
+ except nx.NetworkXUnfeasible:
282
+ print("Graph has cycles")
283
+
284
+ # All topological sorts
285
+ all_topo = nx.all_topological_sorts(G)
286
+ ```
287
+
288
+ ## Cliques
289
+
290
+ ### Finding Cliques
291
+ ```python
292
+ # All maximal cliques
293
+ cliques = list(nx.find_cliques(G))
294
+
295
+ # Maximum clique (NP-complete, approximate)
296
+ max_clique = nx.approximation.max_clique(G)
297
+
298
+ # Clique number (nx.graph_clique_number was removed in NetworkX 3.0)
299
+ clique_number = max(len(c) for c in nx.find_cliques(G))
300
+
301
+ # Size of the largest maximal clique containing each node
302
+ clique_sizes = nx.node_clique_number(G)
303
+ ```
304
+
305
+ ## Graph Coloring
306
+
307
+ ### Node Coloring
308
+ ```python
309
+ # Greedy coloring
310
+ coloring = nx.greedy_color(G, strategy='largest_first')
311
+
312
+ # Different strategies: 'largest_first', 'smallest_last', 'random_sequential'
313
+ coloring = nx.greedy_color(G, strategy='smallest_last')
314
+ ```
315
+
316
+ ## Isomorphism
317
+
318
+ ### Graph Isomorphism
319
+ ```python
320
+ # Check if graphs are isomorphic
321
+ is_isomorphic = nx.is_isomorphic(G1, G2)
322
+
323
+ # Get isomorphism mapping
324
+ from networkx.algorithms import isomorphism
325
+ GM = isomorphism.GraphMatcher(G1, G2)
326
+ if GM.is_isomorphic():
327
+ mapping = GM.mapping
328
+ ```
329
+
330
+ ### Subgraph Isomorphism
331
+ ```python
332
+ # Check if G1 is subgraph isomorphic to G2
333
+ is_subgraph_iso = nx.is_isomorphic(G1, G2.subgraph(nodes))
334
+ ```
335
+
336
+ ## Traversal Algorithms
337
+
338
+ ### Depth-First Search (DFS)
339
+ ```python
340
+ # DFS edges
341
+ dfs_edges = list(nx.dfs_edges(G, source=1))
342
+
343
+ # DFS tree
344
+ dfs_tree = nx.dfs_tree(G, source=1)
345
+
346
+ # DFS predecessors
347
+ dfs_pred = nx.dfs_predecessors(G, source=1)
348
+
349
+ # Preorder and postorder
350
+ preorder = list(nx.dfs_preorder_nodes(G, source=1))
351
+ postorder = list(nx.dfs_postorder_nodes(G, source=1))
352
+ ```
353
+
354
+ ### Breadth-First Search (BFS)
355
+ ```python
356
+ # BFS edges
357
+ bfs_edges = list(nx.bfs_edges(G, source=1))
358
+
359
+ # BFS tree
360
+ bfs_tree = nx.bfs_tree(G, source=1)
361
+
362
+ # BFS predecessors and successors
363
+ bfs_pred = nx.bfs_predecessors(G, source=1)
364
+ bfs_succ = nx.bfs_successors(G, source=1)
365
+ ```
366
+
367
+ ## Efficiency Considerations
368
+
369
+ ### Algorithm Complexity
370
+ - Many algorithms have parameters to control computation time
371
+ - For large graphs, consider approximate algorithms
372
+ - Use `k` parameter to sample nodes in centrality calculations
373
+ - Set `max_iter` for iterative algorithms
374
+
375
+ ### Memory Usage
376
+ - Iterator-based functions (e.g., `nx.simple_cycles()`) save memory
377
+ - Convert to list only when necessary
378
+ - Use generators for large result sets
379
+
380
+ ### Numerical Precision
381
+ When using weighted algorithms with floating-point numbers, results are approximate. Consider:
382
+ - Using integer weights when possible
383
+ - Setting appropriate tolerance parameters
384
+ - Being aware of accumulated rounding errors in iterative algorithms