chocoteam / chocoteam/choco-solver

[BUG] Choco does not check for timeout during initialization phase

Open
#1,062 2 comments 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
779
Forks
159
Avg merge
6d 9h
Merged PRs (30d)
10

Description

**Describe the bug**
The timeout has no effect with specific conditions, which make loop in PropagationEngine.propagate() run long. The Solver is stuck in initialize() method.

**To Reproduce**
The example will have no solutions:
```
import org.chocosolver.solver.Model;
import org.chocosolver.solver.Solver;
import org.chocosolver.solver.constraints.Constraint;
import org.chocosolver.solver.variables.IntVar;

public class ChocoTimeout
{
@SuppressWarnings("nls")
public static void main(String [] args)
{
Model model = new Model();

IntVar v7 = model.intVar("@v7", IntVar.MIN_INT_BOUND, IntVar.MAX_INT_BOUND, true);
IntVar v7mi2 = model.sum("v7-2", v7, model.intVar(-2));

Constraint arithm1 = model.arithm(v7, ">", v7);
Constraint arithm2 = model.arithm(v7, "<", v7);
Constraint arithm3 = model.arithm(v7, ">=", v7mi2);
Constraint arithm4 = model.arithm(v7, "!=", model.intVar(5));
model.post(arithm1, arithm2, arithm3, arithm4);

Solver solver = model.getSolver();
solver.limitTime(250);

long start = System.currentTimeMillis();
boolean solved = solver.solve();
long took = System.currentTimeMillis() - start;

System.out.println("Solved: " + solved);
System.out.println("Time in measures: " + (solver.getMeasures().getTimeCount() * 1000));
System.out.println("Time in solve(): " + took);
}
}
```
the loop runs ~3 seconds on my machine with time limitation of 250 millis:
```
Solved: false
Time in measures: 3741.5261
Time in solve(): 3743
```
For more complicated models, it would run up to eternity.

**Expected behavior**
Timeout works for all phases of solver.solve().

**Environment:**
- Choco-solver version: [4.10.13](https://github.com/chocoteam/choco-solver/releases/tag/v4.10.13)

Contributor guide

Open the contributing guide

Research direction

Start with Solver.solve() and follow its initialize() path into PropagationEngine.propagate(), using the supplied ChocoTimeout Java example as the reproducer. Check how the 250 ms limit is observed during initialization and compare the measured time with solve() duration. Done means the example respects the timeout across all solver phases.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.