CP-SAT: incompatible-linear implication counts grow across presolve iterations with unchanged model size (9.15)
Maintainers usually reply within 1 day
@lperron is already working on this.
Since Nov 3, 2026.
Assessment
- Difficulty
- 5/5
- Estimated time
- Over a week
- Newbie friendliness
- 18/100
Research direction
Start by running the reproduce.py script from the issue and comparing the presolve-1/2/3 logs. The relevant code is DetectDifferentVariables() in ortools/sat/cp_model_presolve.cc, PresolveContext::AddImplication() in ortools/sat/presolve_context.cc, the duplicate-removal rule counter, and the outer presolve iteration loop. Any fix needs to avoid re-emitting existing implications without changing presolve strength, and the maintainers must agree on the approach first.
Written by the indexing model from the issue text.
Description
Version and environment
- Official Python wheel: OR-Tools 9.15.6755, CP-SAT.
- Standalone reproduction below: Python 3.10.20, macOS/arm64.
- No OR-Tools source modifications. I have not built or tested the current development branch.
Observed behavior
A small synthetic model repeatedly triggers incompatible linear: add implication and subsequent duplicate-constraint removal when the maximum presolve iteration count increases. The final reported variable, constraint, and term counts remain unchanged.
| Maximum iterations | Actual iterations | incompatible linear: add implication |
duplicate: removed constraint |
Presolved variables | Constraints | Terms |
|---|---|---|---|---|---|---|
| 1 | 1 | 15 | 0 | 36 | 60 | 150 |
| 2 | 2 | 30 | 15 | 36 | 60 | 150 |
| 3 | 3 | 45 | 30 | 36 | 60 | 150 |
With the limit set to 3, DetectDuplicateConstraints reports #duplicates=15 at the start of both later iterations. The model starts with 51 variables, 15 exactly-one constraints, and 30 enforced linear constraints. Each of its 15 unordered pairs has two incompatible guarded time inequalities and a third skip choice.
The script intentionally uses stop_after_presolve=True: UNKNOWN is expected here, and search is not performed. Each solve has a one-second limit. This tiny example demonstrates the counter pattern, not a meaningful wall-time regression.
Standalone reproducer
Install ortools==9.15.6755, save the following as reproduce.py, and run python reproduce.py. It writes the three full logs in the current directory and prints the table fields above.
"""Small CP-SAT presolve-only reproducer; no application code or input data."""
import itertools
import json
import platform
import re
from pathlib import Path
import ortools
from ortools.sat.python import cp_model
def build_model():
model = cp_model.CpModel()
times = [model.new_int_var(0, 100, f"t{i}") for i in range(6)]
skips = []
for i, j in itertools.combinations(range(6), 2):
before = model.new_bool_var(f"before_{i}_{j}")
after = model.new_bool_var(f"before_{j}_{i}")
skip = model.new_bool_var(f"skip_{i}_{j}")
model.add_exactly_one(before, after, skip)
model.add(times[i] + 3 <= times[j]).only_enforce_if(before)
model.add(times[j] + 3 <= times[i]).only_enforce_if(after)
skips.append(skip)
model.minimize(sum(skips))
return model
def count_rule(log, name):
match = re.search(
r"rule '" + re.escape(name) + r"' was applied ([\d']+) time", log
)
return int(match[1].replace("'", "")) if match else 0
def main():
print(json.dumps({"python": platform.python_version(),
"ortools": ortools.__version__,
"os": platform.system(), "arch": platform.machine()}))
for limit in (1, 2, 3):
model = build_model()
solver = cp_model.CpSolver()
solver.parameters.cp_model_presolve = True
solver.parameters.max_presolve_iterations = limit
solver.parameters.stop_after_presolve = True
solver.parameters.max_time_in_seconds = 1.0
solver.parameters.num_search_workers = 1
solver.parameters.random_seed = 0
solver.parameters.log_search_progress = True
solver.parameters.log_to_stdout = False
messages = []
solver.log_callback = messages.append
status = solver.solve(model)
log = "\n".join(messages)
Path(f"presolve-{limit}.log").write_text(log)
print(json.dumps({
"max_iterations": limit,
"status": solver.status_name(status),
"actual_iterations": count_rule(log, "presolve: iteration"),
"add_implication": count_rule(log, "incompatible linear: add implication"),
"remove_duplicate": count_rule(log, "duplicate: removed constraint"),
"presolved": dict(re.findall(r"(PresolvedNum\w+): (\d+)", log)),
}))
if __name__ == "__main__":
main()
Suspected source-level mechanism
In the v9.15 sources:
DetectDifferentVariables()updates theincompatible linear: add implicationrule counter and callsAddImplication(lit1, NegatedRef(lit2))for incompatible guarded linear constraints.PresolveContext::AddImplication()appends an enforcedBoolAndconstraint, with no existing-implication lookup on this path apart from skippinga == b.- Duplicate removal also updates a rule counter.
- The outer loop breaks on zero additional presolve operations. Thus repeated insertion/removal can contribute a nonzero continuation signal even without net size reduction. The nearby TODO and the counter documentation already acknowledge that this is an imperfect progress measure.
The counter pattern is consistent with regenerated implications being removed and regenerated again. I have not instrumented individual literal identities or constraint lifetimes, so this is a suspected mechanism rather than a proof that every insertion is the same relationship. Equal aggregate sizes also do not establish identical models, domains, or propagation strength.
Question / expected behavior
Is the repeated implication-generation/removal pattern intentional, or is there an opportunity to avoid re-emitting already represented relationships and counting that work as progress toward another expensive presolve iteration?
I am not suggesting globally limiting presolve to one iteration or removing useful implications. I would appreciate guidance on whether a targeted deduplication or progress-accounting fix is appropriate, and what additional trace would help establish the exact mechanism.
Related general discussion: SAT Presolve time limit #4280; this report focuses on a specific implication/duplicate-removal pattern rather than a global time cap.
- Dominant language
- C++
- Stars
- 14.5k
- Forks
- 2.6k
- Avg merge
- 9h 43m
- Merged PRs (30d)
- 53
Getting set up
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from google/or-tools
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
Maintainers usually reply within 1 day
-
Difficulty 5/5 Over a week Newbie friendliness 42/100
Maintainers usually reply within 1 day
-
CP-SAT: TimeTableEdgeFinding can report false INFEASIBLE for large cumulative scheduling modelsPossibly taken @lperron claimed this today. OpenBug Solver: CP-SAT Solver
google/or-tools#5672 · 2 comments · 1 assignee ·
Maintainers usually reply within 1 day
-
Python (v10.0-rc.1): Model.restore_assignment() and Assignment.objective() take ownership of C++-owned objects (segfault)Possibly taken @Mizux claimed this today. OpenLang: Python Solver: Routing & CP Solver
google/or-tools#5670 · 1 assignee ·
Maintainers usually reply within 1 day
-
[CP-SAT] Duplicate timer registration in StartDirectSolver when UserTimer aliases WallTimerPossibly taken @lperron claimed this 1 day ago. OpenSolver: CP-SAT Solver
Difficulty 3/5 Half a day Newbie friendliness 85/100
google/or-tools#5659 · 5 comments · 1 assignee ·
Maintainers usually reply within 1 day
Similar issues
-
enhancement
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
ionut-mihalache/aqua#31 · 1 comment ·
-
LWG
Difficulty 2/5 1-3 hours Newbie friendliness 65/100
Maintainers usually reply within 2 days
-
needs-kind
Difficulty 2/5 1-3 hours Newbie friendliness 63/100
villagesql/villagesql-server#1702 · 1 comment ·
Maintainers usually reply within 2 days
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
microsoft/vcpkg-tool#2191 · 1 reaction ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
harfbuzz/harfbuzz#6966 · 1 comment ·
Maintainers usually reply within 1 day