Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Benchmarks

Measurements include the speed of the native core against the Python implementation, and the solution quality of ILS and memetic with complete and optional matching, plus comparisons with proven optima and LAP backend timings.

The tables identify the measured source revision. They precede the later LAP integer-overflow safeguards, which add arithmetic checks; they do not measure that subsequent implementation.

Native core against the Python implementation

kap.k_assignment with the native core (backend="kap", the default) against the Python implementation of the same algorithms (kap._reference.k_assignment, which runs the multiple Hungarian methods in Python but calls the same native LAP solver). kap 0.2.x used other LAP backends, which are not measured here.

Setup: 4 × Intel Xeon E7-8860 v4 at 2.20 GHz (72 cores, 144 threads), 503 GB RAM, kap 0.3.0a1 from d1877e0 with the explicit-float threshold validation change, Python 3.12.16, and NumPy 2.5.4. Eight workers ran concurrently, each pinned to one physical core, with RAYON_NUM_THREADS=1. Other users were active. Costs are independent uniform integers in [0, 100) plus uniform noise (float64), in n × n pair matrices; max_iter=100, n_trials=1, and no threshold. Each cell reports the median time across three seeds; short calls use the minimum of up to five repeats within each seed. Costs are means across those seeds.

AlgoknNativePythonSpeedupCost, native / Python
Am6100.104 ms1.73 ms16.59×=
Am61001.81 ms7.22 ms4.00×=
Am650062.8 ms82.2 ms1.31×=
Dm8100.558 ms29.9 ms53.64×=
Dm810024.4 ms149 ms6.12×=
Dm8500882 ms2.23 s2.52×=
Bm41008.39 ms56 ms6.68×=
Bm61010.5 ms1.2 s114.48×=
Bm6100679 ms8.69 s12.79×=
Bm62002.89 s20.4 s7.04×=
Cm410019.5 ms158 ms8.13×1.005
Cm5105.37 ms242 ms45.13×0.990
Cm5100296 ms1.64 s5.53×0.997
Em410019.6 ms113 ms5.76×0.999
Em5100238 ms1.75 s7.36×0.997
Fm31004.45 ms46.7 ms10.49×0.931
Fm4100620 ms151 ms0.24×0.950
Fm51007.71 s2.3 s0.30×0.988

= denotes equal mean objective costs. Am, Bm, and Dm had equal native/reference mean costs at every measured size and dtype. Cm, Em, and Fm can differ because the native implementation follows different search rules from the Python reference.

  • Removing Python quotient-graph construction has the largest effect on small n and larger k: the displayed Bm k=6,n=10 speedup is about 114×. For Am at n=500, LAP work dominates and the displayed speedup is 1.31×.
  • Native Bm also avoids repeated merges by memoizing equivalent merge forests; see algorithm costs.
  • Native Fm runs all 100 tabu iterations, while the Python reference can stop at a plateau. At k=4/5 it is slower here and returns lower mean costs.
  • Separate int64 workloads, without the uniform noise, ran up to 2.50× faster than the float64 workloads for n≥50. This comparison changes both the dtype and the cost structure, so it does not isolate an arithmetic-only speedup.
  • Bm, Cm, Em, and Fm can use parallel execution, but each run here used one thread.

Solution quality of the search methods

This reruns the retained laptop comparison grid on 4 × Intel Xeon E7-8860 v4 at 2.20 GHz (72 cores, 144 threads), with Python 3.12.16, NumPy 2.5.4, and kap 0.3.0a1 from d1877e0 with the explicit-float threshold validation change. Each instance used 16 physical cores on one socket (RAYON_NUM_THREADS=16), with four instances on disjoint core groups. Other users were active; the machine was not reserved exclusively for these measurements.

Part sizes are equal and threshold=None. Random costs are independent uniform integers in 1..100. Geometric costs are rounded Euclidean distances between uniform points in [0, 1000]². Matrices use int64. There are three seeds per random setting and one per geometric setting: 23 instances and 350 measured calls.

Values are mean percentages above the lowest cost observed for that instance across all measured methods and budgets. These are not gaps to a known optimum. The reference includes Shift, 1DV, Shift+sDV, Cm, Em with 16 trials, Fm, and ILS/memetic with both 1DV and sDV at 1 s and 10 s. The table shows a subset: ILS and memetic use 1DV; ILS × 16 uses 16 independent chains. Cm/Fm use their default iteration limits; their parentheses report mean elapsed milliseconds. Cm, Em, and Fm were omitted for k≥6.

KindknSeedsCmFmILS, 1 sILS × 16, 1 smemetic, 1 sILS, 10 sILS × 16, 10 smemetic, 10 s
random340315.88 (0.6 ms)15.88 (0.5 ms)0.000.000.000.000.000.00
random3100323.03 (2.6 ms)23.03 (2.5 ms)4.690.715.131.290.003.54
random430315.17 (2.3 ms)4.51 (20.4 ms)0.630.010.160.000.000.18
random450324.47 (3.1 ms)17.24 (45.0 ms)3.101.724.050.840.420.67
random525314.16 (8.7 ms)11.01 (107.9 ms)0.810.090.110.300.000.00
random6183——0.570.070.070.120.000.00
random8103——0.030.000.000.000.000.00
geometric37010.20 (1.9 ms)0.20 (1.9 ms)0.000.000.000.000.000.00
geometric45010.09 (3.8 ms)0.09 (85.6 ms)0.000.000.000.000.000.00

At 10 s, 16-chain ILS had mean excess at most 0.42% in this grid. Memetic’s largest mean excess was 3.54% at random k=3,n=100. All displayed ILS/memetic configurations reached the same cost on the two geometric settings. These complete-matching results do not predict the optional-matching results below.

Time limits are checked between operations, so elapsed time can exceed the requested budget. The raw measurements retain elapsed time for each call.

Optional matching: ILS and memetic

Measured on 4 × Intel Xeon E7-8860 v4 at 2.20 GHz (72 cores, 144 threads), Python 3.12.16, NumPy 2.5.4, and kap 0.3.0a1 from commit d1877e0 with the explicit-float threshold validation change. Each run used 16 physical cores on one socket and RAYON_NUM_THREADS=16; four instances ran concurrently on disjoint core groups. Other users were active, so cache and memory bandwidth were shared.

These synthetic instances test unequal part sizes, forbidden pairs, and optional matching. The base size n gives part sizes 0.8n, n, 1.2n, repeated in that order. All methods used 1DV, minimization, and float64 matrices so forbidden pairs could be represented by +inf.

  • Random: independent uniform integer costs in 1..100, threshold 30, and 20% of pairs forbidden independently.
  • Geometric: rounded Euclidean distances between uniform points in [0, 1000]², threshold 150. Distances above 250 and 5% of the remaining pairs selected independently are forbidden; about 85% of all pairs are forbidden.

There are three seeds per setting, except n=1000 with one seed per family: 32 instances and 192 method/budget calls. Every output was checked for vertex coverage, uniqueness, part membership, forbidden pairs, reported original costs, and a shifted objective no worse than the all-singleton partition.

Let J be the shifted objective, the sum of (cost − threshold) within cliques. The table reports mean 100 × (J − J_best) / abs(J_best), where J_best is the lowest objective any measured method found at either budget on that instance. All J_best values here are negative. Zero denotes the best observed value; these are not gaps to a proven optimum. Original costs alone would omit the threshold’s dependence on the number of matched pairs.

KindknSeedsILS, 1 sILS × 16, 1 smemetic, 1 sILS, 10 sILS × 16, 10 smemetic, 10 s
geometric310030.000.000.000.000.000.00
geometric330030.050.010.030.000.000.00
geometric3100010.020.020.030.000.000.00
geometric510030.180.020.030.020.000.00
geometric530030.440.390.260.150.110.00
geometric810030.840.490.790.210.070.01
random310030.650.230.230.160.040.00
random330030.870.780.730.290.210.14
random3100010.370.430.540.000.210.01
random510034.553.002.392.601.200.00
random530033.493.703.902.071.540.39
random810038.976.806.405.343.330.00

At 10 s, memetic had a lower shifted objective than 16-chain ILS on 18 instances, tied it on 9, and had a higher objective on 5. This differs from the complete-matching comparison above; method selection depends on the instance family and objective.

Actual elapsed time includes initial construction and the final in-progress operation. The next table reports the maximum elapsed seconds across seeds for each method and requested budget. In particular, the 1 s request for 16-chain ILS took up to 3.83 s on the largest random instance.

KindknILS, 1 sILS × 16, 1 smemetic, 1 sILS, 10 sILS × 16, 10 smemetic, 10 s
geometric31001.001.011.0310.0010.0110.07
geometric33001.061.061.0610.0410.0510.08
geometric310001.842.321.0710.7111.5710.21
geometric51001.021.031.0310.0110.0110.06
geometric53001.131.181.0810.1710.1810.08
geometric81001.051.051.0110.0810.0510.07
random31001.011.011.0210.0110.0110.03
random33001.121.131.0610.1010.1110.04
random310001.733.831.5510.8512.4010.73
random51001.041.021.0210.0210.0210.04
random53001.201.221.1010.2010.2110.08
random81001.091.071.0410.0710.0610.03

ILS and the lower bound against the proven optimum

The same 33 instances previously measured on an AMD Ryzen 7 7840H were rerun on 4 × Intel Xeon E7-8860 v4 at 2.20 GHz (72 cores, 144 threads), using Python 3.12.16, NumPy 2.5.4, SciPy 1.18.1 (HiGHS through scipy.optimize.milp), and kap 0.3.0a1 from d1877e0 with the explicit-float threshold validation change. There are three seeds per size. Random and geometric costs follow the definitions above, with int64 matrices, equal sizes, minimization, and no threshold.

Four instances ran concurrently on disjoint 16-physical-core groups, one per socket. Rayon used 16 threads. The benchmark explicitly forwarded threads=1 to HiGHS for exact solving; ILS used one or eight chains as shown. Other users were active. Exact elapsed time includes model construction and solving but excludes the initial SciPy import. The solve limit was 300 s.

All 33 exact solves proved optimality, and every optimum agreed with the retained laptop result. ILS columns show mean percentage above the optimum, followed by optimum hits / seeds. The lower-bound column shows mean percentage below the optimum. Exact time is the maximum across the three seeds, in seconds.

KindknExact time max (s)ILS, 100 iterationsILS, 1 s, 1 chainILS, 1 s, 8 chainslower_bound
random3100.090.00 (3/3)0.00 (3/3)0.00 (3/3)0.88
random3201.391.84 (0/3)0.00 (3/3)0.00 (3/3)1.00
random3309.272.29 (0/3)0.00 (3/3)0.00 (3/3)1.82
random34040.501.91 (0/3)0.00 (3/3)0.00 (3/3)2.39
random480.820.00 (3/3)0.00 (3/3)0.00 (3/3)13.71
random41214.540.76 (2/3)0.00 (3/3)0.00 (3/3)16.50
random41664.331.94 (0/3)0.00 (3/3)0.00 (3/3)20.30
random5824.510.43 (1/3)0.00 (3/3)0.00 (3/3)19.79
random6671.350.00 (3/3)0.00 (3/3)0.00 (3/3)18.78
geometric3303.420.00 (3/3)0.00 (3/3)0.00 (3/3)0.01
geometric41628.640.00 (3/3)0.00 (3/3)0.00 (3/3)0.59

Both 1 s ILS configurations reached the proven optimum on all 33 instances. The default 100 iterations reached it on 18. The bound was within 2.39% for these k=3 cases and within 0.59% for the geometric cases; the largest mean random-instance gap was 20.30% at k=4.

An initial run with HiGHS’s default thread count created 72 solver threads per worker despite the 16-core affinity limit. It was stopped and retained separately; its partial results are excluded from this table. The table uses the explicit single-thread HiGHS configuration described above.

A separate one-seed prototype run at k=6,n=8 (262,144 variables) returned no incumbent after 626 s despite a requested 120 s limit. That size exceeds the public kap.exact default guard of 150,000 variables and is not included in the table. The result illustrates why the guard and time-limit caveat remain.

LAP backends

BackendAlgorithmRectangularNotes
kapJonker-Volgenant initialization (square) + shortest augmenting path (Crouse 2016)yesdefault; native, built in; optimal like scipy (ties may differ on square input)
scipymodified Jonker-Volgenantyes
lapJonker-Volgenantyes
lapjvJonker-Volgenantnosee measurements below
munkresHungarianyespure Python, slower in these measurements

Measured time per call in µs on 4 × Intel Xeon E7-8860 v4 at 2.20 GHz (72 cores, 144 threads), Python 3.12.16, NumPy 2.5.4, kap 0.3.0a1 from d1877e0 with the explicit-float threshold validation change, SciPy 1.18.1, lap 0.5.14, and lapjv 1.3.29. Each worker was pinned to one physical core; four input cells ran concurrently on separate sockets. Other users were active.

Uniform inputs are float64 values in [0, 1). int100 contains integer-valued float64 costs in [0, 100), with many ties. Here the input labeled geometric is the structured cost i*j + uniform noise; it differs from the Euclidean instances used in the search sections. The full grid also includes integer-valued costs in [0, 10⁶), and both n × n and n × 2n shapes.

Each solver is warmed up, then timing uses the minimum of five repeated samples, with repetition counts calibrated to about 0.3 s total for short calls. Before timing, assignments are checked for cardinality, uniqueness, index range, and objective agreement with SciPy (rtol=1e-12, atol=1e-8). Inputs are generated from a separate deterministic seed for each distribution/size/shape cell.

InputnkapSciPy 1.18.1lap 0.5.14lapjv 1.3.29
uniform101.832.132.482.24
uniform10084.68299.1893.9252.91
uniform3002 166.933 835.162 614.571 663.76
uniform5004 546.0511 694.464 330.732 631.76
uniform100020 851.8054 183.0147 246.0434 966.02
uniform200087 057.39288 626.79339 781.58253 528.86
int10010007 788.4726 058.695 476.265 780.74
geometric1000657 132.46773 656.642 321 726.41cost mismatch
uniform, n × 2n100020 078.8019 147.3329 458.68—

Kap is about 2.6–3.3 times faster than SciPy on the displayed uniform square inputs at n=1000 and n=2000. At n=1000 with tied costs, kap is about 1.35–1.42 times slower than lap/lapjv. For the displayed uniform rectangular case, kap takes about 1.05 times SciPy’s time. These ratios describe these inputs and versions.

cost mismatch means a feasible assignment had a higher cost than SciPy’s and failed the objective-agreement check. With lapjv 1.3.29, the difference was 0.02962184 at structured n=1000 and 2.5415404 at n=2000. Kap and lap agreed with SciPy on those inputs. These lapjv timings are omitted from equivalent-solution comparisons. The discrepancy was reproduced in the second run at n=1000.

The benchmark runner was also checked on identical serial and four-worker grids (84 solver/input cells, n=10,100,300). Input hashes and returned objectives matched exactly. The median parallel/serial timing ratio was 1.00, with a range of 0.85–1.06; timing equality is not expected on shared hardware.