@nshiab/simple-data-analysis-core 2.1.7 → 2.1.9

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 (59) hide show
  1. package/esm/class/SimpleTable.d.ts +191 -108
  2. package/esm/class/SimpleTable.d.ts.map +1 -1
  3. package/esm/class/SimpleTable.js +188 -105
  4. package/esm/helpers/buildGraphTemporalCostStateSql.d.ts +1 -1
  5. package/esm/helpers/buildGraphTemporalCostStateSql.d.ts.map +1 -1
  6. package/esm/helpers/buildGraphTemporalCostStateSql.js +23 -9
  7. package/esm/helpers/graphRouteResultSchema.d.ts +1 -1
  8. package/esm/helpers/graphRouteResultSchema.d.ts.map +1 -1
  9. package/esm/helpers/graphRouteResultSchema.js +3 -3
  10. package/esm/helpers/graphRouteResultSelect.d.ts +1 -1
  11. package/esm/helpers/graphRouteResultSelect.d.ts.map +1 -1
  12. package/esm/helpers/graphRouteResultSelect.js +2 -2
  13. package/esm/helpers/prepareGraphMetricOptions.d.ts +2 -2
  14. package/esm/helpers/prepareGraphMetricOptions.d.ts.map +1 -1
  15. package/esm/helpers/prepareGraphMetricOptions.js +5 -4
  16. package/esm/helpers/prepareGraphRouteSql.d.ts +2 -2
  17. package/esm/helpers/prepareGraphRouteSql.d.ts.map +1 -1
  18. package/esm/helpers/prepareGraphRouteSql.js +4 -4
  19. package/esm/helpers/validateGraphRouteResultSchema.d.ts +1 -1
  20. package/esm/helpers/validateGraphRouteResultSchema.d.ts.map +1 -1
  21. package/esm/helpers/validateGraphRouteResultSchema.js +3 -1
  22. package/esm/methods/distances.d.ts +1 -1
  23. package/esm/methods/distances.d.ts.map +1 -1
  24. package/esm/methods/distances.js +235 -73
  25. package/esm/methods/shortestPath.d.ts +1 -1
  26. package/esm/methods/shortestPath.d.ts.map +1 -1
  27. package/esm/methods/shortestPath.js +44 -28
  28. package/esm/methods/similarityMahalanobis.js +3 -3
  29. package/llm.md +214 -119
  30. package/llms.txt +1 -1
  31. package/package.json +1 -1
  32. package/script/class/SimpleTable.d.ts +191 -108
  33. package/script/class/SimpleTable.d.ts.map +1 -1
  34. package/script/class/SimpleTable.js +188 -105
  35. package/script/helpers/buildGraphTemporalCostStateSql.d.ts +1 -1
  36. package/script/helpers/buildGraphTemporalCostStateSql.d.ts.map +1 -1
  37. package/script/helpers/buildGraphTemporalCostStateSql.js +23 -9
  38. package/script/helpers/graphRouteResultSchema.d.ts +1 -1
  39. package/script/helpers/graphRouteResultSchema.d.ts.map +1 -1
  40. package/script/helpers/graphRouteResultSchema.js +3 -3
  41. package/script/helpers/graphRouteResultSelect.d.ts +1 -1
  42. package/script/helpers/graphRouteResultSelect.d.ts.map +1 -1
  43. package/script/helpers/graphRouteResultSelect.js +2 -2
  44. package/script/helpers/prepareGraphMetricOptions.d.ts +2 -2
  45. package/script/helpers/prepareGraphMetricOptions.d.ts.map +1 -1
  46. package/script/helpers/prepareGraphMetricOptions.js +5 -4
  47. package/script/helpers/prepareGraphRouteSql.d.ts +2 -2
  48. package/script/helpers/prepareGraphRouteSql.d.ts.map +1 -1
  49. package/script/helpers/prepareGraphRouteSql.js +4 -4
  50. package/script/helpers/validateGraphRouteResultSchema.d.ts +1 -1
  51. package/script/helpers/validateGraphRouteResultSchema.d.ts.map +1 -1
  52. package/script/helpers/validateGraphRouteResultSchema.js +3 -1
  53. package/script/methods/distances.d.ts +1 -1
  54. package/script/methods/distances.d.ts.map +1 -1
  55. package/script/methods/distances.js +235 -73
  56. package/script/methods/shortestPath.d.ts +1 -1
  57. package/script/methods/shortestPath.d.ts.map +1 -1
  58. package/script/methods/shortestPath.js +44 -28
  59. package/script/methods/similarityMahalanobis.js +3 -3
@@ -2634,38 +2634,23 @@ export default class SimpleTable extends Simple {
2634
2634
  }): SimpleTable;
2635
2635
  /**
2636
2636
  * Finds the shortest routes from each starting node to every reachable
2637
- * node and reports their total costs. By default, each connection costs
2638
- * one. Use the `weight` option to sum values from a numeric column, such
2639
- * as travel time or price.
2637
+ * node. Without options, shortest means the fewest connections. Use `weight`
2638
+ * to report total cost and `elapsedTime` to report duration including waiting
2639
+ * between connections. Use `minimize` to choose which metric defines shortest.
2640
2640
  *
2641
- * The `direction` option lets you follow connections from source to target,
2642
- * from target to source, or in either direction. The result has `start`,
2643
- * `node`, and `total` columns.
2644
- *
2645
- * Each row gives the selected route's total cost from `start` to `node`.
2646
- * Intermediate steps along the route are not returned. To get the steps
2647
- * between two different nodes, use `shortestPath()` for the shortest routes
2648
- * or `paths()` for all routes without repeated nodes.
2649
- *
2650
- * A starting node appears in its own results only when a self-connection
2651
- * or a route leads back to it. Its total is the cost of the shortest actual
2652
- * return route, using at least one connection. With `direction: "both"`, this
2653
- * can mean following the same connection out and back.
2654
- *
2655
- * Unknown starting IDs and starts with no connections to follow produce
2656
- * no rows. Empty start arrays and duplicate starting IDs throw an error.
2657
- * Weights must be non-null, finite, and non-negative.
2641
+ * Each row contains `start`, `node`, and `steps`, plus `total` when `weight`
2642
+ * is supplied and `elapsedTimeMs` when enabled. Routes tied on the chosen
2643
+ * metric produce separate rows only when their reported summaries differ;
2644
+ * identical summaries appear once.
2658
2645
  *
2659
- * Use the `startTimeColumn` or `endTimeColumn` options to follow connections
2660
- * in chronological order. The `minGapMs` option sets the minimum gap between
2661
- * consecutive connections, in milliseconds. With both time columns, gaps are
2662
- * measured from one connection's end to the next connection's start; with one
2663
- * column, between their timestamps. The `strictOrdering` option defaults to
2664
- * `true`, rejecting zero-duration gaps. These options only work with
2665
- * `direction: "outgoing"` or `direction: "incoming"`.
2646
+ * Routes cannot repeat nodes except for a final return to the start. A start
2647
+ * appears in its own results only through an actual return or self-connection,
2648
+ * never with zero steps. With `direction: "both"`, a return can follow the
2649
+ * same connection out and back. Use `shortestPath()` to inspect individual
2650
+ * connections between two different nodes.
2666
2651
  *
2667
- * The minimum gap applies only between consecutive connections, not before
2668
- * the first connection.
2652
+ * Reporting weight or elapsed time can require substantial time and memory
2653
+ * on dense networks because many routes may need to be explored.
2669
2654
  *
2670
2655
  * The next five examples each start with this data:
2671
2656
  *
@@ -2685,7 +2670,7 @@ export default class SimpleTable extends Simple {
2685
2670
  * .log();
2686
2671
  * ```
2687
2672
  *
2688
- * | start | node | total |
2673
+ * | start | node | steps |
2689
2674
  * | --- | --- | ---: |
2690
2675
  * | A | B | 1 |
2691
2676
  * | A | C | 2 |
@@ -2699,10 +2684,10 @@ export default class SimpleTable extends Simple {
2699
2684
  * .log();
2700
2685
  * ```
2701
2686
  *
2702
- * | start | node | total |
2703
- * | --- | --- | ---: |
2704
- * | A | B | 4 |
2705
- * | A | C | 5 |
2687
+ * | start | node | steps | total |
2688
+ * | --- | --- | ---: | ---: |
2689
+ * | A | B | 1 | 4 |
2690
+ * | A | C | 2 | 5 |
2706
2691
  *
2707
2692
  * With `direction: "incoming"`, connections are followed from target to
2708
2693
  * source. Starting at C:
@@ -2714,7 +2699,7 @@ export default class SimpleTable extends Simple {
2714
2699
  * .log();
2715
2700
  * ```
2716
2701
  *
2717
- * | start | node | total |
2702
+ * | start | node | steps |
2718
2703
  * | --- | --- | ---: |
2719
2704
  * | C | B | 1 |
2720
2705
  * | C | A | 2 |
@@ -2730,14 +2715,14 @@ export default class SimpleTable extends Simple {
2730
2715
  * .log();
2731
2716
  * ```
2732
2717
  *
2733
- * | start | node | total |
2718
+ * | start | node | steps |
2734
2719
  * | --- | --- | ---: |
2735
2720
  * | A | B | 1 |
2736
2721
  * | A | A | 2 |
2737
2722
  * | A | C | 2 |
2738
2723
  * | A | D | 2 |
2739
2724
  *
2740
- * A appears with a total of 2 because A → B → A follows a connection out
2725
+ * A appears with 2 steps because A → B → A follows a connection out
2741
2726
  * and back.
2742
2727
  *
2743
2728
  * An array of starting nodes gives separate distances for each start:
@@ -2751,12 +2736,12 @@ export default class SimpleTable extends Simple {
2751
2736
  * .log();
2752
2737
  * ```
2753
2738
  *
2754
- * | start | node | total |
2755
- * | --- | --- | ---: |
2756
- * | A | B | 4 |
2757
- * | A | C | 5 |
2758
- * | D | B | 2 |
2759
- * | D | C | 3 |
2739
+ * | start | node | steps | total |
2740
+ * | --- | --- | ---: | ---: |
2741
+ * | A | B | 1 | 4 |
2742
+ * | A | C | 2 | 5 |
2743
+ * | D | B | 1 | 2 |
2744
+ * | D | C | 2 | 3 |
2760
2745
  *
2761
2746
  * A direct self-connection and a longer return route can both lead back
2762
2747
  * to the start. This example uses different data:
@@ -2777,13 +2762,13 @@ export default class SimpleTable extends Simple {
2777
2762
  * .log();
2778
2763
  * ```
2779
2764
  *
2780
- * | start | node | total |
2781
- * | --- | --- | ---: |
2782
- * | A | B | 2 |
2783
- * | A | A | 5 |
2765
+ * | start | node | steps | total |
2766
+ * | --- | --- | ---: | ---: |
2767
+ * | A | B | 1 | 2 |
2768
+ * | A | A | 2 | 5 |
2784
2769
  *
2785
2770
  * Chronological options can rule out a cheaper sequence that departs too
2786
- * early. For this example, F2 leaves before F1 arrives, while F3 meets the
2771
+ * early. Here, B → C leaves before A → B arrives, while B → D meets the
2787
2772
  * one-hour minimum exactly:
2788
2773
  *
2789
2774
  * | origin | destination | departureTime | arrivalTime | minutes |
@@ -2804,12 +2789,12 @@ export default class SimpleTable extends Simple {
2804
2789
  * .log();
2805
2790
  * ```
2806
2791
  *
2807
- * | start | node | total |
2808
- * | --- | --- | ---: |
2809
- * | A | B | 2 |
2810
- * | A | D | 5 |
2792
+ * | start | node | steps | total |
2793
+ * | --- | --- | ---: | ---: |
2794
+ * | A | B | 1 | 2 |
2795
+ * | A | D | 2 | 5 |
2811
2796
  *
2812
- * For the next two examples, `flights` contains these rows, with departure
2797
+ * For the next four examples, `flights` contains these rows, with departure
2813
2798
  * and arrival stored as timestamps on the same day:
2814
2799
  *
2815
2800
  * | flightId | origin | destination | departure | arrival | price |
@@ -2833,7 +2818,7 @@ export default class SimpleTable extends Simple {
2833
2818
  * .log();
2834
2819
  * ```
2835
2820
  *
2836
- * | start | node | total | elapsedTimeMs |
2821
+ * | start | node | steps | elapsedTimeMs |
2837
2822
  * | --- | --- | ---: | ---: |
2838
2823
  * | A | B | 1 | 3600000 |
2839
2824
  * | A | C | 1 | 10800000 |
@@ -2857,29 +2842,94 @@ export default class SimpleTable extends Simple {
2857
2842
  * .log();
2858
2843
  * ```
2859
2844
  *
2860
- * | start | node | total | elapsedTimeMs |
2861
- * | --- | --- | ---: | ---: |
2862
- * | A | B | 40 | 3600000 |
2863
- * | A | C | 120 | 10800000 |
2845
+ * | start | node | steps | total | elapsedTimeMs |
2846
+ * | --- | --- | ---: | ---: | ---: |
2847
+ * | A | B | 1 | 40 | 3600000 |
2848
+ * | A | C | 1 | 120 | 10800000 |
2864
2849
  *
2865
- * Use `minimize: "weight"` to find the cheapest journeys instead.
2866
- * Equally fast journeys are ranked by price; equally cheap journeys
2867
- * are ranked by elapsed time.
2850
+ * Use `minimize: "weight"` to find the cheapest journeys instead. The
2851
+ * selected route to C now takes two steps through B and costs 80:
2852
+ *
2853
+ * @example
2854
+ * ```ts
2855
+ * await flights
2856
+ * .distances("origin", "destination", "A", {
2857
+ * startTimeColumn: "departure",
2858
+ * endTimeColumn: "arrival",
2859
+ * minGapMs: 60 * 60 * 1000,
2860
+ * elapsedTime: true,
2861
+ * weight: "price",
2862
+ * minimize: "weight",
2863
+ * })
2864
+ * .log();
2865
+ * ```
2866
+ *
2867
+ * | start | node | steps | total | elapsedTimeMs |
2868
+ * | --- | --- | ---: | ---: | ---: |
2869
+ * | A | B | 1 | 40 | 3600000 |
2870
+ * | A | C | 2 | 80 | 14400000 |
2871
+ *
2872
+ * Choose the fewest connections while still reporting price and elapsed
2873
+ * time. The direct flight to C has one step, even though it costs more:
2874
+ *
2875
+ * @example
2876
+ * ```ts
2877
+ * await flights
2878
+ * .distances("origin", "destination", "A", {
2879
+ * startTimeColumn: "departure",
2880
+ * endTimeColumn: "arrival",
2881
+ * minGapMs: 60 * 60 * 1000,
2882
+ * elapsedTime: true,
2883
+ * weight: "price",
2884
+ * minimize: "steps",
2885
+ * })
2886
+ * .log();
2887
+ * ```
2888
+ *
2889
+ * | start | node | steps | total | elapsedTimeMs |
2890
+ * | --- | --- | ---: | ---: | ---: |
2891
+ * | A | B | 1 | 40 | 3600000 |
2892
+ * | A | C | 1 | 120 | 10800000 |
2893
+ *
2894
+ * When two routes to C both take two steps but have different prices,
2895
+ * minimizing steps while reporting price returns both summaries:
2896
+ *
2897
+ * @example
2898
+ * ```ts
2899
+ * await connections
2900
+ * .loadArray([
2901
+ * { origin: "A", destination: "B", price: 20 },
2902
+ * { origin: "B", destination: "C", price: 30 },
2903
+ * { origin: "A", destination: "D", price: 40 },
2904
+ * { origin: "D", destination: "C", price: 40 },
2905
+ * ])
2906
+ * .distances("origin", "destination", "A", {
2907
+ * weight: "price",
2908
+ * minimize: "steps",
2909
+ * })
2910
+ * .filter("node = 'C'")
2911
+ * .log();
2912
+ * ```
2913
+ *
2914
+ * | start | node | steps | total |
2915
+ * | --- | --- | ---: | ---: |
2916
+ * | A | C | 2 | 50 |
2917
+ * | A | C | 2 | 80 |
2868
2918
  *
2869
2919
  * @param sourceColumn - The name of the column containing each connection's source node ID.
2870
2920
  * @param targetColumn - The name of the column containing each connection's target node ID.
2871
- * @param startNodes - One starting node ID or an array of distinct starting node IDs.
2921
+ * @param startNodes - One starting node ID or a non-empty array of distinct IDs. Unknown IDs and starts with no connections to follow produce no rows. Empty arrays and duplicate IDs throw an error.
2872
2922
  * @param options - An optional object with direction, time, and result configuration.
2873
- * @param options.direction - The direction in which to follow connections. Defaults to `"outgoing"`.
2923
+ * @param options.direction - The direction in which to follow connections. Defaults to `"outgoing"`. Chronological traversal supports only `"outgoing"` and `"incoming"`.
2874
2924
  * @param options.startTimeColumn - The name of the column containing each connection's start time. Use this or `endTimeColumn` to follow connections in chronological order.
2875
2925
  * @param options.endTimeColumn - The name of the column containing each connection's end time. Use this or `startTimeColumn` to follow connections in chronological order.
2876
- * @param options.minGapMs - The minimum gap between consecutive connections, in milliseconds. Must be a non-negative integer. Defaults to `0`. Requires a time column.
2926
+ * @param options.minGapMs - The minimum gap between consecutive connections, in milliseconds; does not apply before the first connection. With both time columns, measured from one connection's end to the next's start; with one column, between timestamps. Must be a non-negative integer. Defaults to `0`. Requires a time column.
2877
2927
  * @param options.strictOrdering - Whether to reject zero-duration gaps between consecutive connections (equal timestamps). Defaults to `true`. Requires a time column.
2878
- * @param options.weight - The name of the numeric column used as the cost of each connection. If omitted, each connection costs one.
2879
- * @param options.elapsedTime - Whether to add cumulative `elapsedTimeMs` in milliseconds, including connection gaps. Defaults to `false`. Requires both time columns.
2880
- * @param options.minimize - The metric used to select optimal routes. Required when both `weight` and `elapsedTime` are enabled; otherwise inferred. The corresponding metric must be enabled.
2928
+ * @param options.weight - The name of the numeric column used as the cost of each connection. Values must be non-null, finite, and non-negative. Adds `total`, the cumulative sum of those costs. If omitted, no `total` column is generated.
2929
+ * @param options.elapsedTime - Whether to add cumulative `elapsedTimeMs` in milliseconds, including connection gaps. Defaults to `false`. Requires both time columns. Optimization compares native timestamp precision before conversion to milliseconds.
2930
+ * @param options.minimize - The metric used to select optimal routes: `"steps"`, `"weight"`, or `"elapsedTime"`. Defaults to `"weight"` when only `weight` is enabled, `"elapsedTime"` when only elapsed-time reporting is enabled, and `"steps"` when neither is enabled. Required when both are enabled. `"steps"` is always available; the other metrics require their corresponding options.
2881
2931
  * @param options.outputTable - If `true`, stores the result in a new table with a generated name. If a string, uses it as the new table's name. If `false` or omitted, overwrites the current table. Defaults to `false`.
2882
- * @returns The result table, so methods can be chained.
2932
+ * @returns The table of distinct optimal summaries with `start`, `node`, and `steps`, plus `total` when `weight` is supplied and `elapsedTimeMs` when enabled, so methods can be chained. Sorted by start, the chosen metric, node, then remaining metrics in the order steps, total, elapsed time.
2883
2933
  * @category Graph Operations
2884
2934
  */
2885
2935
  distances(sourceColumn: string, targetColumn: string, startNodes: string | number | bigint | (string | number | bigint)[], options?: {
@@ -2887,7 +2937,7 @@ export default class SimpleTable extends Simple {
2887
2937
  elapsedTime?: boolean;
2888
2938
  endTimeColumn?: string;
2889
2939
  minGapMs?: number;
2890
- minimize?: "weight" | "elapsedTime";
2940
+ minimize?: "steps" | "weight" | "elapsedTime";
2891
2941
  outputTable?: string | boolean;
2892
2942
  startTimeColumn?: string;
2893
2943
  strictOrdering?: boolean;
@@ -2908,15 +2958,17 @@ export default class SimpleTable extends Simple {
2908
2958
  * containing these IDs as the `edgeId` argument. If your table is missing
2909
2959
  * an ID column, you can easily create one with `addId()`.
2910
2960
  *
2911
- * The result starts with the `pathId`, `step`, `weight`, and `total`
2912
- * columns, followed by all original columns. Steps start at one and follow
2913
- * the search direction. The `weight` column is the connection cost, and
2914
- * `total` is the sum of those costs up to and including the current step.
2915
- * Without the `weight` option, each connection costs one.
2961
+ * The result starts with `pathId`, `step`, and `weight`, followed by the
2962
+ * optional metric columns and all original columns. Steps start at one and
2963
+ * follow the search direction. The `weight` column is the connection cost,
2964
+ * or one when no `weight` option is supplied. Supplying `weight` also adds
2965
+ * `total`, the sum of those costs up to and including the current step.
2966
+ * Enabling `elapsedTime` adds cumulative `elapsedTimeMs`, including gaps.
2916
2967
  *
2917
- * If an input column is already named `pathId`, `step`, `weight`, or `total`
2918
- * (regardless of capitalization), the method throws an error. Rename it
2919
- * with `renameColumns()` first.
2968
+ * If an input column conflicts with a generated result column (regardless
2969
+ * of capitalization), the method throws an error. Rename it with
2970
+ * `renameColumns()` first. `total` is reserved only when `weight` is supplied,
2971
+ * and `elapsedTimeMs` only when elapsed-time reporting is enabled.
2920
2972
  *
2921
2973
  * Each row is one connection along a route.
2922
2974
  *
@@ -2931,6 +2983,16 @@ export default class SimpleTable extends Simple {
2931
2983
  * The minimum gap applies only between consecutive connections, not before
2932
2984
  * the first connection.
2933
2985
  *
2986
+ * Use `minimize: "steps"` to choose the fewest connections even when weight
2987
+ * or elapsed-time reporting is enabled. Without an explicit `minimize`, the
2988
+ * method minimizes weight when only `weight` is enabled, elapsed time when
2989
+ * only `elapsedTime` is enabled, and steps when neither is enabled. With
2990
+ * both enabled, specify `"steps"`, `"weight"`, or `"elapsedTime"` explicitly.
2991
+ * Elapsed-time reporting requires both time columns.
2992
+ *
2993
+ * All routes tied on the selected metric are returned, even if their other
2994
+ * metrics differ. Each route reports its own weights and elapsed times.
2995
+ *
2934
2996
  * Routes are numbered from zero by comparing their sequences of connection
2935
2997
  * IDs, element by element. Rows are sorted by `pathId`, then `step`.
2936
2998
  *
@@ -2961,14 +3023,14 @@ export default class SimpleTable extends Simple {
2961
3023
  * .log();
2962
3024
  * ```
2963
3025
  *
2964
- * | pathId | step | weight | total | edgeId | source | target |
2965
- * | ---: | ---: | ---: | ---: | --- | --- | --- |
2966
- * | 0 | 1 | 1 | 1 | E1 | A | B |
2967
- * | 0 | 2 | 1 | 2 | E3 | B | D |
2968
- * | 0 | 3 | 1 | 3 | E5 | D | E |
2969
- * | 1 | 1 | 1 | 1 | E2 | A | C |
2970
- * | 1 | 2 | 1 | 2 | E4 | C | D |
2971
- * | 1 | 3 | 1 | 3 | E5 | D | E |
3026
+ * | pathId | step | weight | edgeId | source | target |
3027
+ * | ---: | ---: | ---: | --- | --- | --- |
3028
+ * | 0 | 1 | 1 | E1 | A | B |
3029
+ * | 0 | 2 | 1 | E3 | B | D |
3030
+ * | 0 | 3 | 1 | E5 | D | E |
3031
+ * | 1 | 1 | 1 | E2 | A | C |
3032
+ * | 1 | 2 | 1 | E4 | C | D |
3033
+ * | 1 | 3 | 1 | E5 | D | E |
2972
3034
  *
2973
3035
  * For an input without connection IDs, use `addId()` first:
2974
3036
  *
@@ -2987,10 +3049,10 @@ export default class SimpleTable extends Simple {
2987
3049
  * .log();
2988
3050
  * ```
2989
3051
  *
2990
- * | pathId | step | weight | total | source | target | edgeId |
2991
- * | ---: | ---: | ---: | ---: | --- | --- | --- |
2992
- * | 0 | 1 | 1 | 1 | A | B | edge-0 |
2993
- * | 0 | 2 | 1 | 2 | B | E | edge-1 |
3052
+ * | pathId | step | weight | source | target | edgeId |
3053
+ * | ---: | ---: | ---: | --- | --- | --- |
3054
+ * | 0 | 1 | 1 | A | B | edge-0 |
3055
+ * | 0 | 2 | 1 | B | E | edge-1 |
2994
3056
  *
2995
3057
  * The next two examples each start with these flights. The direct flight
2996
3058
  * takes ten minutes; the route through B and D takes three:
@@ -3030,9 +3092,9 @@ export default class SimpleTable extends Simple {
3030
3092
  * .log();
3031
3093
  * ```
3032
3094
  *
3033
- * | pathId | step | weight | total | flightId | origin | destination | minutes |
3034
- * | ---: | ---: | ---: | ---: | --- | --- | --- | ---: |
3035
- * | 0 | 1 | 1 | 1 | F1 | A | E | 10 |
3095
+ * | pathId | step | weight | flightId | origin | destination | minutes |
3096
+ * | ---: | ---: | ---: | --- | --- | --- | ---: |
3097
+ * | 0 | 1 | 1 | F1 | A | E | 10 |
3036
3098
  *
3037
3099
  * With time options, the cheaper route through B is ruled out because F2
3038
3100
  * leaves before F1 arrives. The route through C meets the one-hour minimum
@@ -3079,11 +3141,11 @@ export default class SimpleTable extends Simple {
3079
3141
  * .log();
3080
3142
  * ```
3081
3143
  *
3082
- * | pathId | step | weight | total | edgeId | source | target |
3083
- * | ---: | ---: | ---: | ---: | --- | --- | --- |
3084
- * | 0 | 1 | 1 | 1 | F1 | A | B |
3144
+ * | pathId | step | weight | edgeId | source | target |
3145
+ * | ---: | ---: | ---: | --- | --- | --- |
3146
+ * | 0 | 1 | 1 | F1 | A | B |
3085
3147
  *
3086
- * For the next two examples, `flights` contains these rows, with departure
3148
+ * For the next three examples, `flights` contains these rows, with departure
3087
3149
  * and arrival stored as timestamps on the same day:
3088
3150
  *
3089
3151
  * | flightId | origin | destination | departure | arrival | price |
@@ -3108,10 +3170,10 @@ export default class SimpleTable extends Simple {
3108
3170
  * .log();
3109
3171
  * ```
3110
3172
  *
3111
- * | pathId | step | weight | total | elapsedTimeMs | flightId | origin | destination | departure | arrival | price |
3112
- * | ---: | ---: | ---: | ---: | ---: | --- | --- | --- | --- | --- | ---: |
3113
- * | 0 | 1 | 1 | 1 | 1800000 | F4 | A | D | 2025-01-01 09:00:00 | 2025-01-01 09:30:00 | 60 |
3114
- * | 0 | 2 | 1 | 2 | 7200000 | F5 | D | C | 2025-01-01 10:30:00 | 2025-01-01 11:00:00 | 80 |
3173
+ * | pathId | step | weight | elapsedTimeMs | flightId | origin | destination | departure | arrival | price |
3174
+ * | ---: | ---: | ---: | ---: | --- | --- | --- | --- | --- | ---: |
3175
+ * | 0 | 1 | 1 | 1800000 | F4 | A | D | 2025-01-01 09:00:00 | 2025-01-01 09:30:00 | 60 |
3176
+ * | 0 | 2 | 1 | 7200000 | F5 | D | C | 2025-01-01 10:30:00 | 2025-01-01 11:00:00 | 80 |
3115
3177
  *
3116
3178
  * The route through D takes two hours (7,200,000 milliseconds), including
3117
3179
  * a one-hour layover. The direct flight takes three hours.
@@ -3140,6 +3202,27 @@ export default class SimpleTable extends Simple {
3140
3202
  * Use `minimize: "weight"` to find the cheapest journey instead.
3141
3203
  * All ties on the chosen metric are returned.
3142
3204
  *
3205
+ * Choose the fewest flights while still reporting price and elapsed time.
3206
+ * The direct flight takes one step, although the route through D is faster:
3207
+ *
3208
+ * @example
3209
+ * ```ts
3210
+ * await flights
3211
+ * .shortestPath("origin", "destination", "flightId", "A", "C", {
3212
+ * startTimeColumn: "departure",
3213
+ * endTimeColumn: "arrival",
3214
+ * minGapMs: 60 * 60 * 1000,
3215
+ * elapsedTime: true,
3216
+ * weight: "price",
3217
+ * minimize: "steps",
3218
+ * })
3219
+ * .log();
3220
+ * ```
3221
+ *
3222
+ * | pathId | step | weight | total | elapsedTimeMs | flightId | origin | destination | departure | arrival | price |
3223
+ * | ---: | ---: | ---: | ---: | ---: | --- | --- | --- | --- | --- | ---: |
3224
+ * | 0 | 1 | 120 | 120 | 10800000 | F3 | A | C | 2025-01-01 09:00:00 | 2025-01-01 12:00:00 | 120 |
3225
+ *
3143
3226
  * @param sourceColumn - The name of the column containing each connection's source node ID.
3144
3227
  * @param targetColumn - The name of the column containing each connection's target node ID.
3145
3228
  * @param edgeId - The name of the column uniquely identifying each connection (edge).
@@ -3151,11 +3234,11 @@ export default class SimpleTable extends Simple {
3151
3234
  * @param options.endTimeColumn - The name of the column containing each connection's end time. Use this or `startTimeColumn` to follow connections in chronological order.
3152
3235
  * @param options.minGapMs - The minimum gap between consecutive connections, in milliseconds. Must be a non-negative integer. Defaults to `0`. Requires a time column.
3153
3236
  * @param options.strictOrdering - Whether to reject zero-duration gaps between consecutive connections (equal timestamps). Defaults to `true`. Requires a time column.
3154
- * @param options.weight - The name of the numeric column used as the cost of each connection. If omitted, each connection costs one.
3237
+ * @param options.weight - The name of the numeric column used as the cost of each connection. Adds `total`, the cumulative sum of those costs. If omitted, no `total` column is generated.
3155
3238
  * @param options.elapsedTime - Whether to add cumulative `elapsedTimeMs` in milliseconds, including connection gaps. Defaults to `false`. Requires both time columns.
3156
- * @param options.minimize - The metric used to select optimal routes. Required when both `weight` and `elapsedTime` are enabled; otherwise inferred. The corresponding metric must be enabled.
3239
+ * @param options.minimize - The metric used to select optimal routes: `"steps"`, `"weight"`, or `"elapsedTime"`. Defaults to `"weight"` when only `weight` is enabled, `"elapsedTime"` when only elapsed-time reporting is enabled, and `"steps"` when neither is enabled. Required when both are enabled. `"steps"` is always available; the other metrics require their corresponding options.
3157
3240
  * @param options.outputTable - If `true`, stores the result in a new table with a generated name. If a string, uses it as the new table's name. If `false` or omitted, overwrites the current table. Defaults to `false`.
3158
- * @returns The result table, so methods can be chained.
3241
+ * @returns The table of route connections with optional cumulative `total` and `elapsedTimeMs` metrics, so methods can be chained.
3159
3242
  * @category Graph Operations
3160
3243
  */
3161
3244
  shortestPath(sourceColumn: string, targetColumn: string, edgeId: string, start: string | number | bigint, end: string | number | bigint, options?: {
@@ -3163,7 +3246,7 @@ export default class SimpleTable extends Simple {
3163
3246
  elapsedTime?: boolean;
3164
3247
  endTimeColumn?: string;
3165
3248
  minGapMs?: number;
3166
- minimize?: "weight" | "elapsedTime";
3249
+ minimize?: "steps" | "weight" | "elapsedTime";
3167
3250
  outputTable?: string | boolean;
3168
3251
  startTimeColumn?: string;
3169
3252
  strictOrdering?: boolean;
@@ -4496,7 +4579,7 @@ export default class SimpleTable extends Simple {
4496
4579
  * // Compare feature vectors and add a dataset-relative similarity score.
4497
4580
  * await table
4498
4581
  * .similarityMahalanobis("features", [175, 70], "distance", {
4499
- * similarityScoreColumn: "similarity",
4582
+ * similarityColumn: "similarity",
4500
4583
  * })
4501
4584
  * .log();
4502
4585
  * ```
@@ -4507,7 +4590,7 @@ export default class SimpleTable extends Simple {
4507
4590
  * const reference = await table.getRow("name === 'Alex'");
4508
4591
  * await table
4509
4592
  * .similarityMahalanobis(["height", "weight"], reference, "distance", {
4510
- * similarityScoreColumn: true,
4593
+ * similarityColumn: true,
4511
4594
  * })
4512
4595
  * .log();
4513
4596
  * ```
@@ -4515,7 +4598,7 @@ export default class SimpleTable extends Simple {
4515
4598
  * @param referencePoint - An array of finite numbers in feature order, or an object with an own finite numeric value for each scalar feature column; may be outside the dataset.
4516
4599
  * @param newColumn - The name of the new DOUBLE distance column.
4517
4600
  * @param options - Optional output settings.
4518
- * @param options.similarityScoreColumn - A custom name, or true for a new DOUBLE column named "similarity"; false or omitted adds no score. The dataset-relative
4601
+ * @param options.similarityColumn - A custom name, or true for a new DOUBLE column named "similarity"; false or omitted adds no score. The dataset-relative
4519
4602
  * score is `1 - distance / maxDistance`. Exact matches score 1 and the farthest
4520
4603
  * rows score 0; if all distances are zero, every score is 1.
4521
4604
  * @returns The table, so methods can be chained.
@@ -4524,7 +4607,7 @@ export default class SimpleTable extends Simple {
4524
4607
  similarityMahalanobis(columns: string | string[], referencePoint: number[] | {
4525
4608
  [key: string]: unknown;
4526
4609
  }, newColumn: string, options?: {
4527
- similarityScoreColumn?: string | boolean;
4610
+ similarityColumn?: string | boolean;
4528
4611
  }): this;
4529
4612
  /**
4530
4613
  * Unnests (expands) rows by splitting a column's string values into multiple rows based on a separator.