Commit 7fce8dc
committed
v0.3.0: Move g/F computation to C, eliminate Fd decision storage, overhaul visualization
C extension (_solver.c):
- Extract g-table and F-table computation from Python into C (fill_g_core,
fill_F_core), giving ~28% speedup on these phases
- Fix critical int32 overflow in 4D stride computation: for sheets larger
than ~180x180, the product (H0+1)*(W0+1)*(H0+1) exceeds INT_MAX.
All strides now use int64_t
- Add defect access macros (DEF_X, DEF_Y, etc.) replacing raw
defects[d*6+0] indexing
- Streamline defect-aligned cut loop with early x/y overlap skip
Fd memory reduction (3x):
Previously, three 4D arrays were stored for defected rectangles:
Fd_values (int32) — optimal value at each (w,h,x,y)
Fd_type (int32) — which decision was taken (cut_x, cut_y, fill, ...)
Fd_param (int32) — decision parameter (cut position or item index)
Total: 12 bytes per cell.
Now only Fd_values (4 bytes per cell) is stored. The decision type and
parameter are no longer needed at solve time — they are re-derived during
reconstruction by checking which candidate cut reproduces the stored
optimal value. This is cheap (only visited cells are reconstructed) and
eliminates 2/3 of the Fd memory.
For a 200x100 sheet: 201^2 * 101^2 ≈ 412M cells
Before: 412M * 12 bytes = 4.7 GB
After: 412M * 4 bytes = 1.6 GB
Python solver (dp_solver.py):
- All three DP phases (g, F, Fd) now call C with Python fallbacks
- Fd arrays allocated lazily (only when the sheet has defects)
- F_type array changed from int32 to int8 (decision codes fit in 3 bits)
- Reconstruction rewritten to work without stored Fd decisions:
re-checks candidate cuts against target value to find the optimal split
Visualization (visualize.py):
- Replace TABLEAU_COLORS with a 20-color vibrant palette for better contrast
- Depth-scaling cut line widths instead of uniform 1.5pt
- Smart tick label spacing with sparse labeling to prevent overlap
- Figure width increased from 8 to 12 inches
- Dual output: SVG (vector) + PNG (raster)4 files changed
Lines changed: 582 additions & 385 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | | - | |
| 7 | + | |
9 | 8 | | |
10 | 9 | | |
11 | | - | |
12 | | - | |
13 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
14 | 14 | | |
15 | 15 | | |
16 | 16 | | |
17 | | - | |
| 17 | + | |
0 commit comments