[BUG] set_cover Python: fix UB in vector transforms and swapped GuidedTabuSearch bindings by jg-codes · Pull Request #5121 · google/or-tools

@jg-codes jg-codes changed the title [BUG] Fix undefined behavior and swapped getter/setter in set_cover Python bindings [BUG] set_cover Python: fix UB in vector transforms and swapped GuidedTabuSearch bindings

Apr 3, 2026

@jg-codes jg-codes changed the base branch from stable to main

April 3, 2026 18:51

@jg-codes

Fix three bugs in ortools/set_cover/python/set_cover.cc:

1. VectorIntToVectorSubsetIndex: std::transform wrote to begin() of an
   empty vector (undefined behavior). Added reserve() + back_inserter().

2. all_subsets property: same empty-vector UB pattern. Same fix.

3. GuidedTabuSearch: set_lagrangian_factor was bound to GetLagrangianFactor
   and vice versa.

Added regression tests for all three code paths.

jg-codes added a commit to jg-codes/or-tools that referenced this pull request

Apr 3, 2026
Exposes the existing C++ SetCoverLagrangian class to Python via pybind11.
Resolves the TODO(user) at the end of set_cover.cc.

Bindings cover all public methods: multiplier initialization, reduced
costs, subgradient, Lagrangian value, multiplier updates, gap
computation, three-phase algorithm, lower bound computation, and
their parallel variants.

Also includes the bug fixes from google#5121 (UB in vector transforms,
swapped GuidedTabuSearch getter/setter) since this patch builds on
the corrected file.

Added BUILD dep on :set_cover_lagrangian and 6 regression tests.

jg-codes added a commit to jg-codes/or-tools that referenced this pull request

Apr 3, 2026
Exposes the existing C++ SetCoverLagrangian class to Python via pybind11.
Resolves the TODO(user) at the end of set_cover.cc.

Bindings cover all public methods: multiplier initialization, reduced
costs, subgradient, Lagrangian value, multiplier updates, gap
computation, three-phase algorithm, lower bound computation, and
their parallel variants.

Also includes the bug fixes from google#5121 (UB in vector transforms,
swapped GuidedTabuSearch getter/setter) since this patch builds on
the corrected file.

Added BUILD dep on :set_cover_lagrangian and 6 regression tests.