Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/DISCUSSION_TEMPLATE/q-a.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ body:
id: package-version
attributes:
label: Package and version
placeholder: "packvium 1.11.0 (Python)"
placeholder: "packvium 1.12.0 (Python)"
validations:
required: true
- type: textarea
Expand Down
2 changes: 1 addition & 1 deletion .github/DISCUSSION_TEMPLATE/show-and-tell.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ body:
id: package-version
attributes:
label: Package and version
placeholder: "packvium 1.11.0 (Python)"
placeholder: "packvium 1.12.0 (Python)"
validations:
required: false
- type: textarea
Expand Down
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ body:
id: version
attributes:
label: Package version
description: The exact version installed, for example 1.11.0.
placeholder: "1.11.0"
description: The exact version installed, for example 1.12.0.
placeholder: "1.12.0"
validations:
required: true
- type: input
Expand Down
2 changes: 1 addition & 1 deletion .github/ISSUE_TEMPLATE/feature_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ body:
id: version
attributes:
label: Package version
placeholder: "1.11.0"
placeholder: "1.12.0"
validations:
required: true
- type: textarea
Expand Down
21 changes: 21 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,27 @@ What changed in `packvium` on PyPI, release by release. The format follows
[Keep a Changelog](https://keepachangelog.com/1.1.0/) and this project adheres to
[Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.12.0]

The money ceiling covers sums, one order for unplaced items, and faster hull and unloading
checks.

### Changed

- **A request whose dearest openable containers cost more than 9007199254740991 minor units in
all,** or whose landed top brackets bill more than that in all, is `invalid_request` /
`above_maximum` at `/containers`.
- **A commerce input integer outside ±(2^53 − 1)** is refused at its path with `expected an
exact integer`. 1.11 computed with it exactly.
- **`unpacked_items` is listed in request order, then by instance number,** in the answer and
in every alternative, as in the other engines.

### Performance

- **Hull collision checks reuse each shape pair's separating axes and projections:** 0.211 s →
0.078 s CPU on the quality-beam wedge fixture.
- **`safe_removal_order`, route removal and their validation run in O(n² · d).**

## [1.11.0]

Bottom gussets and standing pouches, a certified bound for the shipping objectives, one money
Expand Down
2 changes: 1 addition & 1 deletion CITATION.cff
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ type: software
authors:
- name: "Packvium contributors"
website: "https://packvium.com"
version: "1.11.0"
version: "1.12.0"
license: MIT
url: "https://packvium.com"
repository-code: "https://github.com/packvium/packvium-python"
Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Use it to pick the smallest carton for an order, build a pallet, load a shipping
or load a truck within its axle ratings and delivery-stop order. Every answer comes back as
coordinates and rotations for each item, with a reason for anything that did not fit.

> **Version 1.11.0 — the public API is frozen.** Field names, status codes and the
> **Version 1.12.0 — the public API is frozen.** Field names, status codes and the
> objective vector do not change without a major version, so any `1.x` is a safe upgrade
> from any earlier `1.x`.
> Read [docs/GUARANTEES.md](https://github.com/packvium/packvium-python/blob/main/docs/GUARANTEES.md) before relying on a result.
Expand Down Expand Up @@ -333,7 +333,7 @@ Pick the package for your stack; mixing them in one system is safe.
| --- | --- | --- |
| Python — [`packvium`](https://pypi.org/project/packvium/) | `pip install packvium` | [packvium-python](https://github.com/packvium/packvium-python) |
| PHP — [`packvium/packvium`](https://packagist.org/packages/packvium/packvium) | `composer require packvium/packvium` | [packvium-php](https://github.com/packvium/packvium-php) |
| Rust — [`packvium`](https://crates.io/crates/packvium) | `packvium = "1.11"` | [packvium-rust](https://github.com/packvium/packvium-rust) |
| Rust — [`packvium`](https://crates.io/crates/packvium) | `packvium = "1.12"` | [packvium-rust](https://github.com/packvium/packvium-rust) |
| Node.js — [`@packvium/engine`](https://www.npmjs.com/package/@packvium/engine) | `npm install @packvium/engine` | [packvium-node](https://github.com/packvium/packvium-node) |
| Browser / WebAssembly — [`@packvium/browser`](https://www.npmjs.com/package/@packvium/browser) | `npm install @packvium/browser` | [packvium-wasm](https://github.com/packvium/packvium-wasm) |
| PHP FFI bridge — [`packvium/native-bridge`](https://packagist.org/packages/packvium/native-bridge) | `composer require packvium/native-bridge` | [packvium-php-bridge](https://github.com/packvium/packvium-php-bridge) |
Expand All @@ -355,7 +355,7 @@ CodeMeta form.
@software{packvium_python,
author = {{Packvium contributors}},
title = {Packvium for Python},
version = {1.11.0},
version = {1.12.0},
license = {MIT},
url = {https://packvium.com}
}
Expand Down
2 changes: 1 addition & 1 deletion codemeta.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"@type": "SoftwareSourceCode",
"name": "Packvium for Python",
"description": "Deterministic 3D bin-packing and cartonization engine for pallets, containers, trucks and shipping cartons. Exact integer geometry, reproducible results.",
"version": "1.11.0",
"version": "1.12.0",
"license": "https://spdx.org/licenses/MIT",
"author": [
{
Expand Down
16 changes: 8 additions & 8 deletions docs/COMMERCE-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,8 @@ are `null`. Boolean/integer equality follows the reference model (`true == 1`,
`false == 0`), including inside lists and objects. `in` and `not_in` test list
elements, string substrings, or object keys; object values are not members. A
non-string context value cannot be a substring or an object key. A missing context
field matches neither binary operator, including its negated form. Rust's rule priority
comparison handles the entire signed 64-bit range without negating its minimum;
portable JavaScript inputs remain limited by exact `Number` representation.
field matches neither binary operator, including its negated form. A rule priority is an
exact integer within `±(2^53 − 1)`, like every commerce integer.

### `catalog_version_info`

Expand Down Expand Up @@ -428,8 +427,9 @@ existing rule-pool storage.
Until 1.11 only JavaScript refused; Python answered without a ceiling, and Rust and PHP
answered up to `2^63 - 1`. The bound is far above any real tariff — nine quadrillion
minor currency units.
- JavaScript refuses an input integer above `2^53 - 1` with `expected an exact integer`:
`JSON.parse` has already rounded it, so no exact arithmetic after that can recover the
value the caller sent. Python computes from such an input exactly and PHP and Rust read it
up to `2^63 - 1`, so an engine may answer a quote JavaScript refuses; callers should not
send one. No fixture does.
- Every engine refuses an input integer outside `±(2^53 - 1)` at its path with
`expected an exact integer`: `JSON.parse` has already rounded it, so no exact arithmetic
after that can recover the value the caller sent, and the other engines hold the same
line so that none answers a quote JavaScript refuses. Until 1.12 Python
computed from such an input exactly and PHP and Rust read it up to `2^63 - 1`. Pinned by
`conformance/commerce/fixtures/input-integer-above-safe-ceiling.json`.
2 changes: 1 addition & 1 deletion docs/GUARANTEES.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ silently — if you need them, they belong in your own layer above this library.

## Status of this release

Version `1.11.0` freezes the public API. Field names, status codes, the objective
Version `1.12.0` freezes the public API. Field names, status codes, the objective
vector, the numeric policy and the validation rules do not change without a major
version, so any `1.x` is a safe upgrade from any earlier `1.x`. A caret or tilde
constraint on `1.0` is enough; an exact pin is no longer required.
Expand Down
6 changes: 5 additions & 1 deletion docs/PUBLIC-API.md
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,10 @@ is true exactly when `winning_start_truncated || global_deadline_reached`, and

## Rejection proof

`unpacked_items` lists the items in the order the request lists them, each item's instances
by number, in every engine and every alternative. Which of several interchangeable
instances a search leaves out is not part of the contract.

Every entry in `unpacked_items` carries the same evidence shape in Python, PHP, Rust
and JavaScript:

Expand Down Expand Up @@ -583,7 +587,7 @@ The four levels have deliberately different meanings:
| Level | Meaning |
| --- | --- |
| `proven` | A request-level bound proves rejection without relying on search completeness. Currently `no_compatible_container_dimensions`, `payload_exceeded`, `rotation_restricted` and `no_eligible_container` — each a pure geometry or tag check across every container, none dependent on how far the search got. |
| `observed` | The engine exhausted or rejected the candidates it actually examined; this is not a global impossibility proof. Currently `no_feasible_placement`, `search_exhausted`, `exact_search_incomplete` and `insufficient_support` — the last when replaying the finished layout finds a place the item fits once the support rules are set aside, and none with them, in every engine. |
| `observed` | The engine exhausted or rejected the candidates it actually examined; this is not a global impossibility proof. Currently `no_feasible_placement` and `insufficient_support` — the last when replaying the finished layout finds a place the item fits once the support rules are set aside, and none with them, in every engine. Every engine names an item no finer diagnosis explains `no_feasible_placement`; `search_exhausted` and `exact_search_incomplete` remain valid codes a result may carry, at the same level, and a validator still reads them. |
| `inferred` | The reason follows from solver state or a compound rule but has no complete certificate. |
| `unknown_due_to_limit` | A deadline stopped the search, so no negative conclusion is claimed. |

Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"

[project]
name = "packvium"
version = "1.11.0"
version = "1.12.0"
description = "Deterministic 3D bin-packing and cartonization engine for pallets, containers, trucks and shipping cartons. Exact integer geometry, reproducible results."
readme = "README.md"
requires-python = ">=3.9"
Expand Down
2 changes: 1 addition & 1 deletion src/packvium/artifacts.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
#: The suite version of this builder, the same string in all four engines of one release.
#: The engine's own name is deliberately not recorded: four correct builders naming themselves
#: would emit four different documents. `make version-set` rewrites this line.
SUITE_VERSION = "1.11.0"
SUITE_VERSION = "1.12.0"

#: The deterministic part of `result.algorithm`. `duration_ms` is wall-clock time and never
#: enters an artifact.
Expand Down
3 changes: 2 additions & 1 deletion src/packvium/commerce/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import json
from typing import Any, Dict, List, Mapping, Optional, Sequence, Tuple

from .._canonical_json import MAX_EXACT_MAGNITUDE
from .catalog import (
AmbiguousCatalogReferenceError,
CatalogVersionNotFoundError,
Expand Down Expand Up @@ -67,7 +68,7 @@ def _request(value: Any) -> Mapping[str, Any]:


def _integer(value: Any, path: str) -> int:
if isinstance(value, bool) or not isinstance(value, int):
if isinstance(value, bool) or not isinstance(value, int) or abs(value) > MAX_EXACT_MAGNITUDE:
_fail(path, "expected an exact integer")
return value

Expand Down
6 changes: 4 additions & 2 deletions src/packvium/commerce/document.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@

from typing import Any, Dict, Iterable, List, Mapping, Optional, Sequence, Tuple

from .._canonical_json import MAX_EXACT_MAGNITUDE
from .._compat import dataclass
from .catalog import (
CartonMaster,
Expand Down Expand Up @@ -63,8 +64,9 @@ def _sequence(value: Any, path: str) -> Sequence[Any]:

def _integer(value: Any, path: str) -> int:
# `bool` is a subclass of `int`; a boolean where an exact integer belongs is a
# caller mistake, not a zero or a one.
if isinstance(value, bool) or not isinstance(value, int):
# caller mistake, not a zero or a one. Past 2^53 - 1 JavaScript has already rounded
# the JSON number, so every implementation holds commerce integers to the safe ceiling.
if isinstance(value, bool) or not isinstance(value, int) or abs(value) > MAX_EXACT_MAGNITUDE:
_fail(path, "expected an exact integer")
return value

Expand Down
63 changes: 60 additions & 3 deletions src/packvium/hull.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
from functools import lru_cache
from itertools import combinations
from math import gcd
from threading import Lock
from typing import Iterable, Sequence, Tuple

from ._compat import dataclass
Expand Down Expand Up @@ -366,16 +367,72 @@ def separating_axes(left: HullShape, right: HullShape) -> Tuple[Axis, ...]:
return tuple(sorted(axes))


#: Ceilings on the pair memo below, in entries and in axes held across all entries. A request
#: meets at most (distinct hull items x orientations + distinct box sizes) squared ordered
#: pairs, and a pair of 32-vertex hulls carries at most a few thousand axes, so either bound is
#: generous for one request; what they stop is a long-lived process accumulating pairs forever.
#: The same two numbers as the JavaScript fallback's `PAIR_PLAN_ENTRIES` / `PAIR_PLAN_AXES`.
PAIR_PLAN_ENTRIES = 256
PAIR_PLAN_AXES = 60_000

#: An ordered pair's separating axes with each shape's projection interval on every one.
PairPlan = Tuple[Tuple[Axis, ...], Tuple[Tuple[int, int], ...], Tuple[Tuple[int, int], ...]]

_PAIR_PLANS: "dict[Tuple[HullShape, HullShape], PairPlan]" = {}
_PAIR_PLAN_LOCK = Lock()
_pair_plan_axes = 0


def pair_plan(left: HullShape, right: HullShape) -> PairPlan:
"""Memoise the ordered pair's axes and local projection intervals.

All three depend on the two rotated shapes and never on where they stand: a placement
only adds `origin . axis` to an interval. Rebuilding them per test made every collision
check pay the `O(e_a * e_b)` axis product plus `O(axes * (a + b))` projections -- 6636
builds on the quality-beam wedge fixture where 90 distinct pairs exist.

Keyed by the shapes themselves, whose equality is the whole of what determines the
plan, so a box rebuilt per call still hits. Emptied whole when either ceiling would be
passed, so the contents depend only on the call sequence; and a hit returns exactly what
a rebuild would, so no output can depend on whether it hit.
"""
global _pair_plan_axes
key = (left, right)
found = _PAIR_PLANS.get(key)
if found is not None:
return found
axes = separating_axes(left, right)
plan = (
axes,
tuple(left.projection(axis) for axis in axes),
tuple(right.projection(axis) for axis in axes),
)
# Build outside the lock. A concurrent miss may already have published this pair.
with _PAIR_PLAN_LOCK:
found = _PAIR_PLANS.get(key)
if found is not None:
return found
if len(axes) > PAIR_PLAN_AXES:
return plan
if len(_PAIR_PLANS) >= PAIR_PLAN_ENTRIES or _pair_plan_axes + len(axes) > PAIR_PLAN_AXES:
_PAIR_PLANS.clear()
_pair_plan_axes = 0
_PAIR_PLANS[key] = plan
_pair_plan_axes += len(axes)
return plan


def collide(left: HullShape, left_origin: Vertex, right: HullShape, right_origin: Vertex) -> bool:
"""Do two placed hulls overlap with positive volume?

Touching is contact, not collision: the comparison is `<=`, which keeps hulls consistent
with the half-open convention `AxisAlignedBox.intersects` already uses for cuboids, so a
hull resting exactly on a box is supported rather than colliding with it.
"""
for axis in separating_axes(left, right):
left_low, left_high = left.projection(axis)
right_low, right_high = right.projection(axis)
axes, left_spans, right_spans = pair_plan(left, right)
for axis, (left_low, left_high), (right_low, right_high) in zip(
axes, left_spans, right_spans
):
left_shift = _dot(left_origin, axis)
right_shift = _dot(right_origin, axis)
if (left_high + left_shift <= right_low + right_shift
Expand Down
11 changes: 10 additions & 1 deletion src/packvium/packer.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ def _pack_checked(self, items: tuple, containers: tuple, fixed_placements: tuple
portfolio = orchestrator.solve(fixed.free, request.containers, self.config, deadline,
fixed.containers)
raw_solutions = portfolio.solutions
request_order = {item.id: index for index, item in enumerate(items)}
ranked = []
validator = IndependentSolutionValidator()
scorer = self.solution_scorer or resolve_objective_scorer(self.config.objective, self.config)
Expand Down Expand Up @@ -170,7 +171,7 @@ def _pack_checked(self, items: tuple, containers: tuple, fixed_placements: tuple
ranked.append(PackingResult(
status,
raw.containers,
raw.unpacked,
in_request_order(raw.unpacked, request_order),
AlgorithmReport(
self.config.profile.value,
raw.solver_name,
Expand Down Expand Up @@ -235,6 +236,14 @@ def _pack_checked(self, items: tuple, containers: tuple, fixed_placements: tuple
)


def in_request_order(unpacked: tuple, request_order: dict[str, int]) -> tuple:
"""`unpacked` in the order the request listed the items, each item's instances by number
. Every engine reports this order, whichever search left the items out and in
whichever order it gave up on them. O(u log u) for u unpacked instances."""
return tuple(sorted(unpacked, key=lambda entry: (request_order[entry.instance.item.id],
entry.instance.sequence)))


def _stated_optimality(
status: PackingStatus,
score: "tuple[int, ...]",
Expand Down
Loading
Loading