8000 Integration 2026-11: logical-conversion fixes, start vectors, MP2NL and driver fixes by glebbelov · Pull Request #293 · ampl/mp · GitHub
[go: up one dir, main page]

Skip to content

Integration 2026-11: logical-conversion fixes, start vectors, MP2NL and driver fixes - #293

Closed
glebbelov wants to merge 168 commits into
masterfrom
integration/2026-11
Closed

glebbelov wants to merge 168 commits into
masterfrom
integration/2026-11

Conversation

@glebbelov
Copy link
Copy Markdown
Contributor

Summary

This pull request combines three topic branches that were developed and tested together,
plus one Gurobi 14 commit that is not yet on master:

  • task-041/nl-writer-long-temp-path: the NL writer and MP2NL on long temporary paths
    (Windows), and MP2NL error reporting;
  • task-043/start-vector-sizes: row and column vectors passed to and from the solvers
    (Xpress row order, driver audit), function bounds for exp/a^x/log,
    multi-objective messages;
  • task-045/logical-conversion-fixes: logical-constraint conversion, inlining of linear
    subexpressions, feasrelax, solution pools, and driver fixes from a systematic review;
    new randomly generated test models;
  • 7a43570f from task-007/gurobi-14-release, which was merged without it: a warning on a
    failed NL IIS query, and .funcnonlinear/.global on NL constraints.

It replaces the separate pull requests of these branches. The changelogs ("unreleased"
sections) describe every user-visible change; this description lists the main ones.

Main changes

Conversion of logical constructs, all solvers:

  • wrong results fixed:
    • a comparison shared by a disjunction and an if-then-else condition;
    • fractional fixed integers;
    • abs() of negative fixed variables;
    • comparisons outside a later-fixed domain;
    • contradictory auxiliary bounds;
    • domain holes (stack overflow);
  • an indicator whose flag becomes fixed later is folded (cvt:pre:indfixedflag, 0 restores
    the old behavior);
  • div/mod/floor/ceil/round/trunc result bounds are passed also without
    cvt:pre:boundsbest;
  • a warning when a divisor's domain contains 0;
  • contradictory equalities of an integer variable are reported infeasible.

Inlining. Linear and quadratic subexpressions are also inlined into the expressions
that define other variables:

  • new bit 32 of cvt:pre:unnest, default 63;
  • fill limits cvt:pre:linfill (default 10) and cvt:pre:quadfill;
  • cvt:pre:unnest=31 cvt:pre:linfill=-1 restores the old model.

With NL output, linear terms are no longer written as nonlinear, so CPLEX and Xpress through
MP2NL no longer reject such models as "not convex quadratic".

Bounds:

  • cvt:pre:roundintbnd rounds integer bounds inwards with a tolerance;
  • cvt:pre:infeasvarbnd=1 declares contradictory bounds infeasible; the default warns and
    passes them on;
  • the result bounds of exp, a^x, log and log_a follow from the argument; none for a
    base ≤ 0 or 1; cvt:pre:funcbndtol.

feasrelax (Gurobi, CPLEX, COPT, HiGHS):

  • constraints and variables added by the conversion are no longer relaxed for free;
  • CPLEX penalties were inverted.

Messages. Warnings and errors are wrapped at 60 characters; tech:msgwidth=0 restores
the old output.

Drivers:

  • Xpress:
    • row order with indicators;
    • IIS when none exists;
    • the legacy pool with best value 0;
    • MINLP solve messages;
  • SCIP:
    • the pool always contains the best solution;
    • unique indicator names;
  • MOSEK: the interrupt flag is reset per solve;
  • CPLEX: MIQCP duals of the fixed model;
  • BARON: skipped-element index;
  • Gurobi:
    • Gurobi 14 IIS and suffix warnings;
    • kappa_exact;
    • InfUnbdInfo only for continuous models;
  • MP2NL:
    • solve result codes;
    • temporary folders;
    • duals;
    • AMPLS error reporting;
  • AMPLS: a second AMPLSSolve() solves again (regression in 20261029).

Tests:

  • new end-to-end cases for each fix;
  • cases/categorized/fast_random: 4100 randomly generated logical models, with expected
    results from enumeration. It is not run by default;
  • test/end2end/generators/logical_models.py reproduces those models exactly;
  • fixed_sos2_pl (fixed model with SOS).

Compatibility

New defaults change models passed to solvers. The old behavior is restored by:

  • cvt:pre:unnest=31 cvt:pre:linfill=-1 (inlining);
  • cvt:pre:indfixedflag=0;
  • cvt:pre:roundintbnd=-1;
  • cvt:pre:funcbndtol=-1;
  • tech:msgwidth=0.

One instance of the INFORMS showcase (battery, Gurobi) became slower with the new inlining
in some seeds. With other seeds both formulations stop at the time limit. It is
equivalent, and is documented as variability.

Testing

Builds: Release, Debug and ASan/UBSan of the MP build and of the private driver build;
GCC 16 where the ABI allows it.

  • Unit tests: converter-flat, converter-mip, nl-solver, nl-reader and util pass
    on Release, Debug and ASan.
  • End-to-end fast set for every driver, including the ASL drivers through MP2NL: no new
    failures against the previous runs. Each failure that remains is known and listed in the
    task record.
  • Generated sets: 4119 cases. Remaining failures are vendor defects, reported separately.
  • INFORMS showcase: 216 cases. Results unchanged except the battery instance above.
  • Examples benchmark: Gurobi 14, Xpress and Knitro, 4 threads, 5 seeds; equal to the
    previous runs where compared.
  • colab.ampl.com notebooks with these builds: no failure attributable to MP.
  • Reviews: several rounds by two independent reviewers. Each finding was reproduced
    before the fix and re-tested after it.

The tree equals the tested merge of the three branches, apart from the order of changelog
entries, the master changelog date, and the new test models.

🤖 Generated with Claude Code

glebbelov and others added 30 commits November 13, 2026 10:57
A temporary directory whose path approaches or exceeds the 248-character
limit for directories made MP2NL terminate abnormally after the
conversion. The writer now keeps the directory as given when its
absolute form fits, otherwise uses the 8.3 form or the extended-length
form, and reports an error when the directory cannot be used.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
…NL subsolvers

Cases of the fast set run with a 5 s limit by default (--timeout overrides).
New solver entries '<driver>_mp2nl' run an MP driver through MP2NL.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
A convex QP objective became a rotated cone with the coefficient instead of its
square root; qcones2qc dropped the square of a fixed first variable; the
exponential-cone check ignored a constant term. Tests socp_14..18, expcones_08.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…e right direction

With a negative .objweight of the first objective the pass objective's nonlinear
part was relaxed the wrong way. Tests multiobj_NL_01, multiobj_QP_02.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…argument

Needed for big-M of logical constraints with such functions. New option
cvt:pre:funcbndtol (default 1e-12 relative margin; negative: old behavior).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…' for functions

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… Debug and ASan runs

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…tive multi-objective errors

Indicator, PWL and nonlinear constraints in the right groups; duals of the fixed
model; a clear error when several objectives are passed natively and one is not
linear (COPT dropped a quadratic one silently).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ong-path forms

The solver is run through std::system(), and the file stub went onto
that command line unquoted: a temporary directory with a space or another
shell character in its path broke the solver call. The stub is now
quoted (double quotes on Windows, single quotes elsewhere; on Windows a
stub with a double quote, which no file name can contain, is reported).
On Windows the whole command is also wrapped in one more pair of quotes,
which cmd.exe /c removes when the command has more than two. A quoted
solver path gets ".exe" before its closing quote.

The 8.3 and extended-length forms of a long temporary directory are
removed: Windows does not accept a TMP longer than MAX_PATH anyway, so
they only extended the usable length from about 225 to 259 characters,
and the extended-length form would reach third-party solvers. A
temporary directory that cannot be used still ends with a message
instead of an uncaught exception.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
nl-solver-test runs NLSolver with a stand-in solver (nlsol-fake-solver)
that checks its command line and writes back the stub it received:
QuoteCommandArg; a custom stub and an automatic one in a temporary
directory whose name has shell characters; a missing temporary
directory; on Windows, one too long for NLSolver's subdirectory. The
last two expect NLUtils::myexit() rather than an uncaught exception.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
DECLARE_SOLVER_API_FUNCTIONS(mp2nl) instead of (MP2NL): the library
now exports AMPLSClose_mp2nl and AMPLSGetModel_mp2nl, matching
AMPLSOpen_mp2nl and the other MP libraries (AMPLSOpen_gurobi /
AMPLSClose_gurobi, ...). AMPLSOpen_mp2nl, which released drivers look
up, is unchanged. Callers of the former AMPLSClose_MP2NL can look up
both names.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
NLSolver reports an unusable temporary directory via NLUtils::myexit(),
which exits by default; MP2NL then wrote no solution file. MP2NL now uses
an NLUtils whose myexit() throws, and Solve() catches it: the failure and
its message are reported to AMPL in the solution file. NLSolver forgets the
directory name before reporting, so a throwing myexit() cannot make the
destructor delete a directory it did not create.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ounds

Since the result of exp is bounded by its argument (z >= 0 gives 1) and
widened by cvt:pre:funcbndtol, the explicified exp result no longer has
lower bound 0 with best bounds: check for a value just below 1.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…obj=0 and cvt:nlobj=0

When several objectives are handled natively and one is quadratic or
nonlinear, the message now also names the options that move quadratic and
nonlinear objective terms into constraints (synonyms passquadobj, passnlobj):
all objectives are then linear and the native multi-objective optimization
works. New end2end case multiobj_QP_02 with cvt:quadobj=0 (Gurobi, Xpress,
COPT; CPLEX's native multi-objective optimization does not take the
quadratic constraint, its message is unchanged).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…in scipmp

The small-fixes commit had added a second "unreleased" section next to an
existing "Unreleased" one; merge them. scipmp: use the spelling of the other
files.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
… supported

The synonyms passquadobj and passnlobj are no longer named in the error
messages or changelogs. The Xpress changelog states only that Xpress 10 is
supported (customer-facing text: no Optimizer build numbers or older
versions).

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The quadratic form of a cone whose first variable is fixed by its bounds
used (c0*v)^2 as the right-hand side, which drops the cone's v >= 0:
sqrt(x^2+y^2) <= t with t fixed at -3 was solved (Gurobi, Xpress, CPLEX,
SCIP, BARON: objective 4.24). The right-hand side is now c0^2*v*|v|.
Found in the review of the merged branches (finding B-F1). Test
conic/socp_19_fixed_x0_negative; changelog entry for the fixed-head fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With cvt:pre:funcbndtol=0 the domain of a piecewise-linear approximation,
clipped by the function values, can end 1 ulp below an integer bound
(exp(log(5)) = 4.999...): the breakpoint x = 5 was lost and the solver
extrapolated there (log(x) - 0.27x over integer x in [1,5]: x = 5,
0.324 reported instead of x = 4, 0.306). ConsiderIntegrality() now
rounds the ends with a relative tolerance of 1e-9. The help of
cvt:pre:funcbndtol no longer calls 0 "exact bounds".
Review findings B-F2, B-F3. Test logical/funcbnd_log_02_int.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
MP2NLUtils::myexit() now throws its own type, NLSolverExit, and Solve()
catches only that: other exceptions (NL feeder errors, bad_alloc) keep
their handling by BackendApp, with their own exit code, as before
d062836. The changelog notes that on Windows '%' in the temporary
directory path is still expanded by the command interpreter.
Review findings D-F2, D-F1.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…nd cvt:nlobj=0

With Gurobi 14 the quadratic objective is passed as a nonlinear one, so both
options (as the error message says) are needed for native multi-objective
optimization; Gurobi 13, Xpress and COPT accept either.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ps integers

- Strict comparisons (<, >) that are true at the root now propagate the context
  into their arguments: a comparison shared by a disjunction and an
  if-then-else condition lost one of its implications (wrong optimum).
- An integer variable fixed at a fractional value stays integer (infeasible),
  instead of being made continuous; contradictory bounds keep the type.
- abs() of a variable fixed at a negative value: the constant result took a
  garbage variable index; use a fixed variable.
- Unary encoding: comparisons x==c with c outside the variable's domain (or
  fractional) are fixed to 0; their flags were left free and counted.
- MakeComplementVar accepts contradictory bounds (the model is infeasible).
- CP-SAT: cvt:pre:continuous_fixed_vars is off by default (new hook
  FixedVarsContinuousDefault()); contradictory or empty domains give
  infeasible instead of an error.
- Five regression cases in end2end fast/logical.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
ReportKappaExact() used the .kappa suffix definitions, so the exact condition
number overwrote the estimate and .kappa_exact was never set.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The sense 'F' was passed to CPXaddindconstr, which CPLEX 22.2 mishandled
(wrong results or violated indicators; the LP writer printed '?').

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…ted by the shell

NLSolver::Solve():
- remove <stub>.sol before the subsolver runs; a solve that wrote none fails
  instead of reporting the result of the previous solve (reused stub, passes
  of the multi-objective emulation);
- the subsolver's exit code (not the raw wait status) is reported, and a
  solution written before a nonzero exit is kept;
- solver options are split at white space (quotes group words) and quoted for
  the shell, one argument each: ';', '$' and quotes no longer act as commands.
Easy API: quadratic objectives with one or two terms were written as an NL sum
with fewer than three arguments (invalid); nonlinear variables were counted per
Hessian nonzero with only one index marked (CONOPT: wrong optimum).
MP2NL model API: logical constraints are not counted as nonlinear objectives;
after a solve, primal values, duals and suffixes that the subsolver did not
return are dropped (the previous values stay until then: they are the initial
guess of the next pass).
Tests for the exit code, the stale solution, the shell and the quoting.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…bounds reported as infeasible

- A domain hole of a variable made x == ub and x >= ub rewrite into each
  other endlessly (stack overflow): equality is no longer classified
  by IfPreprocessHole.
- Contradictory (lower > upper) hard bounds of a variable are reported as
  infeasible (exit code 200) instead of being passed to the solver, where
  Xpress and SCIP failed for an indicator flag: option cvt:pre:infeasvarbnd
  (default 1). The exit code now survives the three rethrowing wrappers
  in the constraint keeper.
- Bounds of integer variables are rounded inwards: option
  cvt:pre:roundintbnd (default 1).
- Regression cases holes_eq_bound_loop_01 and indicator_contradict_bounds_01.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…overs implied-integer variables

- cvt:pre:roundintbnd is the tolerance of rounding the bounds of integer
  and implied-integer variables inwards (default 1e-9, negative: off).
- Integral constants (shared fixed variables) are marked implied-integer;
  best-known bounds are rounded too, so [1, 1/6] becomes [1, 0].

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
The mark changed the count of auxiliary integer variables that
auxint_01 checks through MP2NL. The rounding of integer bounds
(cvt:pre:roundintbnd) still covers integer and implied-integer variables.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
…asibility

Best-known bounds are deduced from the model's constraints, so their
contradiction (beyond pre:eps / pre:epsrel) proves infeasibility as well.
Before, only a warning was issued and the contradictory bounds reached the
solver; Xpress then stopped with "Non binary variable used as an indicator
binary" instead of reporting infeasibility. Controlled by
cvt:pre:infeasvarbnd, as for hard bounds.

Test: end2end logical/indicator_contradict_bounds_02 (generated example).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The static presolve folded an indicator only if its binary was fixed
when the indicator was added. A binary fixed later (e.g., by a root
logical constraint flattened afterwards) reached the solver as a
constant, made continuous by PrepareVariables(); Xpress and SCIP then
stopped with "Non binary variable used as an indicator binary".

Now the indicator converters (le/ge/eq/quad, new base
BasicIndicatorConverter_MIP) fold such an item: the subconstraint is
added if the binary has the indicator's value, otherwise the item is
dropped. IfNeedsConversion() makes accepted indicators convert, and
ConvertDelayedItems() revisits indicators behind the conversion cursor
(ConstraintKeeper::ConvertNeededBehindCursor()). No big-M rows on the
constant binary when indicators are linearized.

Option cvt:pre:indfixedflag (0/1*), subject to cvt:pre:all;
0 restores the old behavior.

Tests: end2end logical/fixed_indicator_flag_* (objective on all
solvers; final-model structure with Gurobi, accepted and linearized
indicators, with and without folding, cvt:pre:all=0).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add headers missing from the add_prefix() lists (ampls-ccallbacks.h,
expr-linear.h, constr_nonlinear.h, eexpr_hashed.h, var_bnd_impl.h,
redef/MIP: cond_literal.h, disj2ind.h, indicator_fixed_flag.h,
int_div.h, rounding.h) and src/wrap_xml.h to parse-xpress-options,
so that IDEs such as Qt Creator show them in the project tree.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Each pass runs the subsolver, which prints its banner. When the
previous pass left both banners alone on the line, the next banner
followed them, and the line read "MP2NL 0.2: MINOS 5.51: MINOS 5.51:
optimal solution found." MP2NL now ends that line and prints its
banner again first.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mapgccv
mapgccv commented Nov 26, 2026
Copy link
Copy Markdown
Contributor

Windows check: Ctrl-C with Xpress mip:basis

Reply to the request in the last update: on Windows the driver neither crashes nor hangs. Two issues found on the way are fixed in a814c42bd and 1e7fed24d.

Setup. Windows 11, MSVC 2026 Release, Xpress 10.0.0, AMPL 20261117, branch at 1e7fed24d. A scratch harness ran xpress.exe (directly and through AMPL) in a console of its own and sent real console Ctrl-C events (GenerateConsoleCtrlEvent) at set times or after given output. Models were chosen so that the Ctrl-C lands in each phase: model input, the MIP, the fixed LP, the report, and the end of a MIP stopped by a limit. More than 100 timed runs, some with several Ctrl-C events in a row.

Results.

Ctrl-C during Result
the MIP <BREAK>, "Fixed MIP for mip:basis skipped: the solve was interrupted.", the MIP's incumbent; exit 0 within ~0.2 s
the fixed LP the same skip message and the MIP's results
after the fixed LP normal results with duals
model input, before the solve "interrupted before the solve" (solve result 471) instead of a full solve (see fix 2)
through AMPL <BREAK>, the skip message, solve_result "limit"

No access violation, no hang, no exit code other than 0 or the console's own Ctrl-C exit (below). Your step 5 (lim:time=5, no Ctrl-C) solves the fixed LP as before.

Fixed on the way.

  1. a814c42bd: after a MIP stopped at a time, node or solution limit, XPRSloadmipsol() on the copy failed with ?902 (the copy is still presolved), so the report had no basis or duals. The copy is now postsolved first. New end-to-end case mip_basis/fixed_mip_limit (lim:mipsol=1) fails without the fix.
  2. 1e7fed24d: a Ctrl-C while the model was read and converted printed <BREAK>, but Solve() cleared the flag and Xpress ignores an interrupt before an optimization starts, so the full solve ran. The flag is now cleared once, when the handler is installed (picking up an earlier Ctrl-C via Interrupter::Stop()), and Solve() then skips the solve. Also: a Ctrl-C during the fixed LP was reported as "Fixed model status: Unfinished ... failed"; it now gives the skip message, and the interrupt check is directly before XPRSlpoptimize/XPRSoptimize on the copy.

Not covered / known.

  • A Ctrl-C in the first ~1 s of startup, while the driver loads Xpress and checks the license, ends the process with 0xC000013A and no .sol file: MP installs its handler only once the backend exists. This predates the PR and applies to every MP driver.
  • A Ctrl-C before AMPL has started the solver is taken by AMPL, which then runs the solve.
  • "A second Ctrl-C ends the driver" could not be exercised: the driver exits within ~0.6 s of the first one.

Checks on the final build: AMPLS fixed-model test passes; Xpress mip_basis (32 cases) and multi_sol have no failures; suf_std (2) and multi_obj (5) fail the same cases without these commits. Not run: Linux/macOS with these commits, CI.

Tested and written with Claude Code.

1e7fed2 cleared the interrupt flag only when the handler was set, once
per run, so with the multi-objective emulation a Ctrl-C in one pass
skipped every later pass: the emulator continues after an interrupted
pass with a feasible point, and the result became "interrupted before
the solve" although a solve ran. Now only a Ctrl-C before the first
Solve() skips it; later passes run as before 1e7fed2.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@mapgccv mapgccv left a comment
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's of course a review made 99.99% by AI, since it is impossible to keep up with this: 148 commits and counting.
For what is worth:
Reviewed at f3a5304c3.

Built and tested on Windows 11, MSVC 2026 Release (HiGHS 1.16.0, Xpress 10.0.0, AM 2360 PL 20261117):

  • AMPLS tests ampls-solve-error-test.py (HiGHS) and ampls-fixed-model-test.py (Xpress, including the linear MIP) pass.
  • Xpress end-to-end mip_basis (32 cases) and multi_sol pass. suf_std (2) and multi_obj (5) fail the same cases at the base.
  • Ctrl-C on Windows, in every solve phase and through AMPL: no crash and no hang. Details are in the earlier comment.
  • Solver banners checked through AMPL: a plain HiGHS solve, and MP2NL with MINOS and multi-objective emulation.
  • The CI failures come from the infrastructure, not from this PR. The PR #292 build fails the same way. The errors are:
    • "No image label found to route agent pool" on the Linux jobs;
    • pip failing to download the Python 3.7 wheels on Windows;
    • std::to_chars being unavailable before macOS 13.3, in nl-writer2.cc, which this PR doesn't change.

Fixed during this review:

  • f3a5304c3: with multi-objective emulation, a Ctrl-C during one pass made the later passes skip their solve (introduced in 1e7fed24d).
  • 6a1d0e45b: AMPLS wrote backspaces into the .sol message for a banner that was never printed.
  • 9aca8c66f: MP2NL with multi-objective emulation printed the subsolver's name twice.

Follow-ups (not blocking)

  • From Filipe's review: item 4 (the divisor warning on solvers with native division) and items 7–9 (repeated scans, the second presolve pass, duplicated multi-objective code), as agreed.
  • Xpress:
    • Predating the PR: with multi-objective emulation, a pass that stops early (time limit or Ctrl-C) leaves the problem presolved. The next pass then fails to change the objective (?902 now, ?268 in driver 20260624), and the solve result is 500. Postsolving before the next pass should fix it.
    • Check the interrupt again right before XPRSoptimize (after tuning).
    • SetHandler stores the handler before its data (src/solver.cc:592). A Ctrl-C between the two stores calls the handler with null data.
    • A .bas file is still written after a skipped or failed fixed solve.
    • The return code of XPRSpostsolve on the copy is ignored.
    • fixed_mip_limit doesn't check that a limit was actually reached.
  • Gurobi:
    • The MIP gap is computed against the MIP's objective, while the reported objective is the fixed model's.
    • Predating the PR: a Ctrl-C doesn't stop the fixed-model solve.
  • SCIP: the fixed LP may fail outright with an LP solver other than SoPlex (SCIP_LPPAR_PRESOLVING). Unverified.
  • MP2NL:
    • After a failed subsolver run, the start of the error text can be taken for the subsolver's banner.
    • subsolver_banner_ isn't reset between solves (AMPLS after AMPLSReportError).
    • With verbose output, there's an extra blank line between passes.
  • Stochastic-programming adapter, predating the PR (src/sp.h, DoAddTerm): a random variable inside a coefficient is indexed with a negative index.
    • The shape is real: AMPL writes 2*xi*x as o2(o2(n2,xi),x).
    • Only the old random() encoding can reach it, because MP doesn't read the R segment.
  • Tests: there's no unit test for the version and banner logic in solver-test.cc, and no automated Ctrl-C test.
  • Predating the PR: a Ctrl-C in the first second of startup ends any driver with no .sol file.

glebbelov and others added 6 commits November 26, 2026 16:33
…port what they pass

A primal-dual start was passed only when AMPL sent both primal and dual
initial values, so a plain primal start (let x := ...) was ignored, e.g.
by Gurobi's NL barrier, BARON and Knitro.

Core (backend-mip.h):
- PartialStartApplies(): models without unfixed integer variables (after
  reformulation; not IsMIP(), which Gurobi 13 reports for continuous models
  with nonlinear general constraints), and drivers without MIP starts.
- There, primal or dual values alone make a start, as allowed by the new
  option alg:startpartial (bitmask, default 3; 0 restores the old behavior).
- AddPrimalDualStart() returns bits: 1 primal values passed to the solver,
  2 dual values passed. Debug suffixes .test_ini_pri/.test_ini_dua follow
  them. Warnings alg:start:primal / alg:start:dual report incoming values
  not passed (dual values only if no primal values were passed, so that
  re-solves do not warn).
- alg:start value 0: the text says that an incoming LP basis is still used.

Drivers: value presolve fills a missing vector with zeros, so each driver
passes a vector only if it came from AMPL, and returns the bits. COPT takes
an LP start only with both vectors; primal values count as passed when COPT
solves a MIP (HasMIPItems()) or the model is nonlinear (MIP start, NL start).
CBC: MIP start for MIPs. BARON: models with integer variables get the start
from AddMIPStart(), which never wrote it before (IsMIP() is always false).
SCIP: primal values alone go as a partial solution via AddMIPStart(). CP-SAT:
no hints in AddPrimalDualStart(). Xpress: RowVectorMatches() drops only the
dual values. HiGHS: no zero row duals with its MIP start.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
New cases in fast/warmstart: primal values only (pstart_nl_01 with a
constraint, pstart_nl_02 without constraints, pstart_lp_01), dual values
only (dstart_lp_01), integer variables fixed by bounds (mipstart_fixed_01),
continuous variables in SOS1 (pstart_sos_01), an LP re-solve
(resolve_lp_01.run); per-driver expectations, warning checks via
solve_message, alg:startpartial=0 negative controls. The dual check of
warmstart_01 moves to a case for drivers that pass dual values.

The runner gives KnitroMPSolver and CbcMPSolver the warmstart tag. knitromp
gets no starting point at all (also with primal and dual values; to be fixed
separately), so it fails warmstart_01, pstart_nl_01 and pstart_lp_01.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…aration)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A fractional value of an integer variable was reported only when it
rounded to 0: the integrality test passed the rounded value as the
reference with an infinite relative tolerance, and Violation::Check
requires both tolerances to be exceeded. MOSEK 12 beta, for example,
returned "integer optimal" solutions with integer variables at 10.5
without any warning.

Now a value is reported if its distance from the nearest integer
exceeds sol:chk:inttol (default raised from 1e-5 to 1e-4, as in the
MIPLIB 2017 checker; solvers' defaults are 1e-5 or smaller) and
sol:chk:inttolrel times the integer's absolute value. The new relative
tolerance defaults to 0 (absolute test only); a positive value can
excuse floating-point errors of very large values.

Documentation: new subsection "Integrality of variables" in the
solution check guide. Unit tests SolCheckTest.*.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Messages that refer to variables or constraints by their generic names
(solution check report, contradictory variable bounds, errors in
algebraic constraints, SDP matrix errors) now suggest
"option <solver>_auxfiles rc;" when AMPL did not pass names. When it
did, the AMPL name follows _svar[i] or _scon[i], e.g. "_svar[1] (x)";
original variable names reach the converter for such messages before
name presolve.

BasicSolver records whether names were read (ampl_names_read()) and
gives the hint (AuxfilesHint()).

Warning titles "_svar bounds" and "_svar best-known bounds" become
"Contradictory variable bounds" and "Contradictory deduced bounds";
the text says "deduced" instead of "best-known".

Unit test SolCheckTest.Report__auxfilesHint__onlyWithoutNames.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@glebbelov
Copy link
Copy Markdown
Contributor Author

Primal or dual start values alone (f3a5304c3..cb26f75ad)

What changed

Before, a driver received a starting point only when AMPL sent both primal and dual values. A primal start alone (from let x := ... or var x := ...) was silently dropped. One case is Gurobi's NL barrier (alg:optimalitytarget=1), which then started cold.

  • Core (9bf09769f, include/mp/backend-mip.h):
    • For continuous models, primal values are now passed without dual values, and dual values without primal values. A continuous model here is one without unfixed integer variables, also after reformulation; the check uses HasUnfixedIntVars(), not IsMIP(), because Gurobi 13 reports IsMIP=1 for continuous NLPs with nonlinear general constraints. The same applies to drivers without MIP starts.
    • A vector that AMPL did not send stays empty. Before, it was zero-filled, so for example Gurobi received a zero DStart and went into crossover.
    • AddPrimalDualStart() now returns bits: 1 if the primal values were passed, 2 if the dual values were. The debug suffixes .test_ini_pri and .test_ini_dua follow these bits.
    • The core warns about incoming values that were not passed:
      • alg:start:primal for primal values;
      • alg:start:dual for dual values, only when no primal values were passed either, so that plain re-solves stay quiet.
    • With alg:start=2, the incoming basis is dropped also when the start is incomplete. This was a deliberate decision.
    • New option alg:startpartial (bits 1 and 2, default 3). alg:startpartial=0 restores the previous behavior.
    • The description of alg:start=0 now says that an incoming LP basis is still used, and that alg:basis=0 disables it.
  • Drivers: each passes only the vectors it received and returns the bits.
Driver What it does now
gurobi PStart and DStart are set separately
cplex CPXcopystart with NULL for a missing vector; returns 0 on error
xpress XPRSloadlpsol with NULL for a missing vector; a row-count mismatch drops only the duals
highs dual values alone go with a NULL column vector
mosek one call per vector; no duals for integer problems
copt LP start only when complete, because COPT_SetLpSolution rejects NULL; NL and MIP models get the primal values through the MIP start (HasMIPItems(), HasNLExpressions())
scipmp primal values alone are left to AddMIPStart(), so no second, zero-filled solution is added
baronmp continuous models through AddPrimalDualStart(); MINLP starts are written by AddMIPStart(), decided by HasUnfixedIntVars() (before, this code was never reached)
cbcmp, knitromp, cpsat, mp2nl bits only; mp2nl sets y0 only when dual values came
  • Changelogs (f1f2ddf48): MP, Gurobi, BARONMP.
  • Tests (dff692006, test/end2end/cases/categorized/fast/warmstart/):
    • pstart_nl_01, pstart_nl_02: NL barrier, primal values only, with and without constraints. Gurobi checks the log line "Loaded warm-start solution" and solve_result_num < 200.
    • pstart_lp_01, dstart_lp_01: primal-only and dual-only LP starts, with the expected warnings for drivers that cannot take them.
    • mipstart_fixed_01: all integer variables fixed. CP-SAT returned MODEL_INVALID here with an intermediate version of the change.
    • pstart_sos_01: native SOS.
    • resolve_lp_01.run: a re-solve gives no warning.
    • Negative controls with alg:startpartial=0 go through ANYSOLVER_options. Plain mp_options would also reach MP2NL's MP subsolver.
    • The runner now gives Knitro and CBC the warmstart tag.
  • knitromp (cb26f75ad): knitromputils.h compiles with clang; the extra qualification in a member declaration was removed.

Checked

  • End-to-end fast set on 12 drivers: gurobi 13.0.3, xpress, highs, cplex, baronmp, mp2nl, copt, mosek, scip, gcg, gecode, cpsat. Failing cases are the same as before the change. All new cases pass where they apply.
  • warmstart folder on the same drivers: only failures that also occur without the change (highs knap_40_pstart ×2, mp2nl warmstart_01 warmstart=2).
  • Gurobi 13.0.3 and 14.0.0: the primal start reaches the NL barrier. With Gurobi 14, staying near the start may need nlbar:initmu.
  • Review: two-round reviews of the diff by two models. Each confirmed finding was fixed and has a test.

Known open points

  • knitromp receives no starting point at all, also with both vectors (this was already so before the change). Because of the new warmstart tag, it fails warmstart_01 warmstart=2, pstart_nl_01 and pstart_lp_01 until this is fixed.
  • cbcmp was not run: the Cbc libraries for macOS are x86_64 only.
  • COPT warns alg:start:primal on a re-solve when all dual values were zero, because AMPL then sends no duals. This is documented.
  • HiGHS: not checked whether the dual values stay after the MIP-start call of Highs_setSolution. This would not be caused by this change.

🤖 Generated with Claude Code

@glebbelov
Copy link
Copy Markdown
Contributor Author

Solution check: integrality; names in messages (ad1b21c9a, 8a3751cc4)

Integrality violations reported again (ad1b21c9a)

Before, a fractional value of an integer variable was reported only when it rounded to 0. The test passed round(x) as the reference with relative tolerance INFINITY, and Violation::Check counts a violation only when both tolerances are exceeded. This has been so since 2023-09. A beta release of a solver returned "integer optimal" solutions with integer variables at 10.5, 8.4 and 6.142857, and the check stayed silent, also with chk:fail.

  • Rule (include/mp/flat/sol_check.h): a value is reported if |x - round(x)| exceeds sol:chk:inttol and also sol:chk:inttolrel × |round(x)|. This is the same AND rule as for bounds and constraints.
  • sol:chk:inttol: the default is raised from 1e-5 to 1e-4.
    • 1e-4 is the integrality tolerance of the MIPLIB 2017 solution checker (Gleixner et al., MPC 2021, sec. 4.7).
    • Solvers' own defaults are 1e-5 or smaller, so 1e-4 leaves a margin. With 1e-5, a value sitting exactly at a solver's 1e-5 tolerance was reported in most cases, because binary rounding puts the deviation just above it.
    • Trade-off: deviations in (1e-5, 1e-4] are no longer reported.
  • New sol:chk:inttolrel, default 0, which leaves only the absolute test.
    • All solvers checked use an absolute integrality test: Gurobi IntFeasTol, CPLEX EpInt, SCIP EPSISINT with feastol, HiGHS. So does the MIPLIB checker.
    • A positive value, for example 1e-14, excuses rounding errors of very large values. Above about 3e11, a few units in the last place can exceed 1e-4.
  • Docs: new subsection "Integrality of variables" in doc/source/modeling-tools.rst. It covers:
    • the rule and both options, and that sol:chk:inttol=0.5 turns the check off;
    • an example line;
    • that MaxAbs and MaxRel can name different variables;
    • "aux var integrality";
    • that values are taken before mip:round.
  • Unit tests SolCheckTest.* (test/converter-mip-test.cpp). With the old call, every test that expects a report fails. The tolerance-acceptance and alg:relax tests pass either way.

Messages: names and option auxfiles (8a3751cc4)

  • When AMPL did not pass names, messages that refer to variables or constraints end with For AMPL names in messages, use option <solver>_auxfiles rc;. These are:
    • the solution check report;
    • contradictory variable bounds;
    • errors in algebraic constraints;
    • SDP matrix errors.
  • When AMPL did pass names, the AMPL name follows the generic reference, e.g. _svar[1] (x).
    • BasicSolver::ampl_names_read() is set in ReadNames(); AuxfilesHint() gives the text.
    • Original variable names reach the converter before name presolve (SetOrigVarNamesForMessages).
  • Warning titles _svar bounds and _svar best-known bounds are now "Contradictory variable bounds" and "Contradictory deduced bounds". The text says "Deduced bounds" instead of "best-known".

Checked (macOS arm64)

  • Unit tests: converter-mip-test 76/76, converter-flat-test 11/11. A fresh build directory compiles the MOSEK driver.
  • End-to-end fast set on gurobi, highs, mosek, copt, cplex and scip. Failing cases and "Tolerance violations" counts are the same as before the change. cbc (x86_64 build) has no pre-change run to compare with; none of its failures involves the solution check. No integrality warnings at the defaults.
  • Strict check (chk:inttol=1e-9):
    • on fast (704 cases) and fast_random (4100 cases), about 32,000 solves: largest deviation 5e-6, auxiliary variables included;
    • on probe models with integer values up to 1e13: exact integers, except about 3 units in the last place at 3.2e7 from one solver.
  • Example of a real defect, the beta solver above. Before: no warning. Now:
    * variable integrality         5E-01 [q[3]]    5E-02 [q[4]]
    
    With chk:fail, the solve result is 150 ("solved?").
  • Review: four two-round reviews of the integrality change by two models. Each confirmed finding was fixed. The names change (8a3751cc4) had no separate review.

Open points

  • NaN or infinite values are never reported, neither for integrality nor for bounds. This was already so before.
  • Proposals to make the report more informative, not done:
    • print the number of violations per line;
    • leave out the "*: Using the solver's aux variable values." footnote for original variables;
    • show the tolerances used;
    • print the value next to the name.

🤖 Generated with Claude Code

glebbelov and others added 12 commits November 26, 2026 20:10
Problem: d2c371b meant MP2NL to keep cvt:pre:infeasvarbnd=1 by
removing its own default of 0 and following the converter's default,
which was 1 then. e4ae0db changed the converter's default to 0, so
MP2NL silently got 0 again: contradictory variable bounds (lower >
upper, also deduced by the converter) went to the NL subsolver.
Checked with infeasvarbnd_01.mod (bounds [3, 2] deduced from x >= 3,
x <= 2; presolve 0) through MP2NL: CONOPT failure 531, LINDO Global
failure 500, Xpress ASL failure 500 instead of infeasible; Knitro 205,
BARON 200. With 1 all report infeasible (200). The end2end cases did
not show it because they set cvt:pre:infeasvarbnd=1 explicitly.

Change: the default comes from the ModelAPI again, as the other
converter defaults that differ per driver (NLAssignLevelDefault,
NLReifLevelDefault):
- model_api_base.h: DeclareInfeasVarBndDefault() returns 0, so every
  other driver keeps 0.
- mp2nlmodelapi.h: returns 1, with the reason in a comment.
- converter.h: declareInfeasVarBnd_ is initialized from
  ModelAPI::DeclareInfeasVarBndDefault(); the option help prints the
  actual default ("Default {}") instead of a fixed "0*" and says why
  MP2NL uses 1 and when to set 0 (subsolver's relaxation or IIS).
- CHANGES.mp.md, CHANGES.mp2nl.md: MP2NL's default and the visible
  change (infeasible instead of a subsolver error).
- end2end iis_feasrelax: 'infeasvarbnd_01 MP2NL default' (no
  mp_options; conopt, lindoglobal, xpressaslmp2nl, knitro, baron:
  infeasible) and 'infeasvarbnd_01 MP2NL infeasvarbnd=0' (old behavior;
  knitro, baron: infeasible).

Tests (macOS, Release; MP2NL and libmp2nl-lib built from this branch,
ASL drivers from the root build):
- iis_feasrelax with conopt, lindoglobal, xpressaslmp2nl, knitro,
  baron: no failures; with the previous libmp2nl-lib the new default
  case fails for conopt, lindoglobal and xpressaslmp2nl, so it detects
  the defect.
- copt built from this branch: option help shows Default 0;
  iis_feasrelax passes (24 cases run, incl. the infeasvarbnd=0 cases).
- fast set with conopt through MP2NL, new vs previous library: same
  163 failing cases except the new case, which fails only with the
  previous library.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With cvt:pre:sort, the preprocessing of NumberofVarConstraint sorted all
its arguments, including the reference variable x of
`numberof x in (...)`, which must stay first. When x had a larger index
than the compared expressions (for example, when abs() elsewhere in
the model made AMPL write x after them in the NL file), the constraint
counted another value, which could give a wrong optimum. Now only the
compared arguments are sorted.

Tests: new e2e cases fast/logical numberof_ref_sort_01 and
numberof_ref_sort_02 (wrong optimum before the fix).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
numberof compares its arguments for equality, so either direction of
an argument's value can change the result. The context of the numberof
result was propagated to the arguments, so that an argument such as
max(), min(), abs() or another numberof was reformulated for one
direction only. This failed with "Part of expression redefinition
could be lost" or, with a nested numberof, gave a wrong optimum. The
arguments of NumberofConst and NumberofVar constraints now always get
the mixed context; the result's own context is unchanged.

Tests: new e2e cases fast/logical numberof_ctx_01 (nested numberof,
wrong optimum before) and numberof_ctx_02 (max() argument, error
before).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
BackendApp::Run() wrote an mp::Error's code to the .sol file whenever
it was at least 0. SCIP's NL reader links an older copy of MP whose
Error constructors default to code 1 (EXIT_FAILURE), so a model that
scipmp could not convert, such as one with `not alldiff(...)`, was
reported with solve result 1 (solved), and AMPL kept the previous
variable values as if they were a solution. An error code in the
solved range 0-99 is now reported as failure (500). The AMPLS C API
wrapper likewise returns -1 for such codes instead of the code.

specifications.md (AMPLS and mp::Error contracts), CHANGES.mp.md and
CHANGES.scipmp.md are updated.

Tests: new e2e case fast/logical not_alldiff_fail_01 (solve result
failure for HiGHS, Gurobi, SCIP, CPLEX, COPT); with this fix the
existing case knap_40 also passes on SCIP.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The converter's numeric decisions get their tolerances from one place,
the new class NumericTolerances (num_tolerances.h):
- integrality: new option cvt:pre:inteps (synonyms pre:inteps and the
  former cvt:pre:roundintbnd, roundintbnd), default 1e-6 (was 1e-9),
  effective value max(inteps, ulps margin); values from 0.5 are
  rejected; negative: the ulps margin only;
- floating-point margin of computed values: new option cvt:pre:ulps,
  default 16 units in the last place (was fixed at 16);
- comparison tolerance: cvt:pre:feastol (absolute).
The converter sets them once after option parsing (StartModelInput());
cvt:pre:all=0 makes all of them exact. RoundIntBound() and
PrepareVariables() (integrality of fixed values, before a fixed 1e-6)
use them. A no-op ModelAPI hook SetIntegralityTolerance() passes
cvt:pre:inteps to solver APIs that round bounds themselves (CP-SAT).
The help of cvt:pre:all, cvt:pre:feastol and cvt:pre:feastolrel
describes their present use. Shared constants (fixed continuous
variables) are never rounded.

Previous behavior: cvt:pre:inteps=1e-9 is the former default of
cvt:pre:roundintbnd.

Tests: unit tests RoundIntBoundUsesUlpTolerance (expectations for the
new default), NumericTolerancesIntegrality, DecisionMarginFromConstant,
SharedConstantsNeverRounded (converter-flat-test),
CmpTolTest.PreAll0__exactTolerances and CmpTolTest.IntEpsHalf__rejected
(converter-mip-test).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comparisons inside logical expressions are decided from the bounds of
their expressions with the margin d = max(cvt:pre:feastol, m), where
m is cvt:pre:ulps units in the last place of the compared constant
(DecideByBounds(), DecideEqualityByBounds()):
- a non-strict comparison holds within d: x >= 4 at x <= 3.9999995 is
  no longer decided false, and (x+1)/3 >= 2 at x <= 5 is no longer
  decided false by the computed bound 1.9999999999999998 (the returned
  solution violated the model);
- a strict comparison is false as the negation of the opposite
  non-strict one with the same d, and true only exactly, up to m; a
  strict comparison decided false only within the tolerances gives
  the warning strict_cmp_tol;
- where m exceeds a positive cvt:pre:feastol, comparisons of
  continuous expressions are not decided; integer-valued expressions
  with an integral right-hand side are decided with d = feastol.
For integer-valued expressions, a right-hand side within cvt:pre:inteps
of an integer is that integer (PreprocessRoundRHS(); equalities, also
after normalizing the coefficient: SnapIntegerEqualityRhs(), false
without such an integer): x <= 0.3/0.1 in a disjunction allows x = 3,
x == 0.3/0.1 is no longer false. An equality's right-hand side within
m of a bound of its expression becomes that bound (0.3*b == 0.1*3).
cvt:pre:ineq2bndeq rewrites comparisons of continuous expressions as
equality to a bound only within d of it (was cvt:mip:eps): x <= 5e-5
at x in [0, 1e-4] became x == 0, and not (1e-5*x > 5e-5) could make
a model infeasible.

Previous behavior: cvt:pre:feastol=0 gives exact decisions;
cvt:pre:feastol=0 cvt:pre:inteps=-1 cvt:pre:ulps=0 the previous
results, except the cvt:pre:ineq2bndeq fix, which no option restores;
cvt:pre:all=0 disables all rounding and tolerances.

The expected counters of the e2e case test_ineq_unify_02 change
(condlin lt/le/ge/gt 0/0/2/0 -> 2/2/4/2; objective -44 unchanged),
because comparisons cvt:mip:eps/k from a bound are no longer rewritten.

Tests: unit tests DecisionMarginCoversRoundingError,
DecideByBoundsSymmetric (converter-flat-test) and 11 CmpTolTest cases
(converter-mip-test); new e2e cases fast/logical cmp_bound_fp_01/02,
cmp_tol_le_cont_01, cmp_tol_ge_cont_01, cmp_tol_neg_scaled_01,
cmp_tol_int_rhs_01/02, cmp_tol_int_eq_01, cmp_tol_eq_scaled_01,
cmp_tol_decide_01, cmp_tol_bin_eq_01, cmp_tol_strict_true_01,
cmp_tol_eq_feastol_01, cmp_tol_big_bnd_01..03, cmp_tol_big_int_01,
cmp_tol_strict_false_01, with old-behavior variants (feastol=0,
exact, ulps=0, inteps=-1).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The result bounds of floor, ceil, round, trunc and div were obtained by
rounding the computed bounds of the argument. A computed bound can miss
the exact one by a rounding error, e.g., (2/3)*5 + (1/3)*2 =
3.9999999999999996 instead of 4, so floor() got the upper bound 3,
which cut off the optimum or made a feasible model infeasible. A
fractional argument bound is now first moved outward by the
floating-point margin, cvt:pre:ulps units in the last place
(RoundBoundOutward()), never by a feasibility tolerance: floor(x) at
x <= 3.9999995 is still at most 3. Integral bounds are taken as exact.

Previous behavior: cvt:pre:ulps=0.

Tests: unit test RoundBoundOutwardToleratesRoundingError
(converter-flat-test); new e2e cases fast/int_ops round_bnd_fp_01..05
(ceil, floor, nested ceil(min(floor)), div, round; wrong optimum or
infeasible before) and floor_data_bnd_01 (data bound within feastol of
an integer: unchanged result).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Comparisons x == const of an integer variable used a unary encoding
(one binary variable per value) for domains of up to 1e7 values, which
could exhaust memory, e.g., with x != 4 for x in 0..100000. New option
cvt:uenc:maxdom (default 10000) is the largest domain encoded; larger
domains use reified inequalities for each compared value. The limit is
checked again with the final bounds (DontNeedEqEncForVar()), whose
upper bound is now rounded down, not up. For integer variables, the
compared constants (encoding keys) within cvt:pre:inteps of an integer
are that integer (IsVarConstCmp()), so that one flag serves each value,
also with cvt:pre:eqresult=0; CreateUnaryEncoding() tests integrality
of the keys with the same tolerance.

Previous behavior: cvt:uenc:maxdom=10000001 (faster for alldiff and
similar expressions comparing many values of a larger domain).

Tests: unit tests UEncMaxDomain (converter-flat-test) and
CmpTolTest.UEncMaxDom__noEncodingForLargeDomain (converter-mip-test);
new e2e cases fast/logical cmp_tol_uenc_01 (domain of 1e5 values,
killed by the memory guard before) and alldiff_dom_01 with the
variant maxdom=10000001.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With cvt:pre:ineqrhs=0, the right-hand side of a comparison is not
rounded before the reformulation, and the offset 1 of a strict
comparison of an integer-valued expression was applied to the
fractional right-hand side: x < 3.5 became x <= 2.5 and excluded
x = 3. The output right-hand side is now the next integer
(IntStrictRhs(): body < c gives body <= ceil(c-t) - 1, body > c gives
body >= floor(c+t) + 1, t = cvt:pre:inteps); no change at the default
cvt:pre:ineqrhs=1.

New warning strict_cmp_eps when the gap cvt:mip:eps of a strict
comparison of a continuous expression is not smaller than the range
of the expression, so that its strict side can be empty (e.g.,
1e-6*x < 3e-6 for x in [0, 6]).

Tests: unit test CmpTolTest.IntStrictFractionalRhs__nextInteger
(converter-mip-test, also with cvt:pre:ineqrhs=0); new e2e cases
fast/logical cmp_tol_int_lt_01 (default and ineqrhs=0, which failed
before) and cmp_tol_strict_eps_01 (infeasible encoding with the
warning; with cvt:mip:eps=1e-7 solved).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The CP-SAT driver rounded bounds of integer-valued rows and variables
with its own rule (within 1e-9 of an integer, else inward) and compared
numberof values with a fixed 1e-6. It now receives the converter's
integrality tolerance cvt:pre:inteps through the ModelAPI hook
SetIntegralityTolerance() and takes such bounds and values within
max(own rule, inteps) of an integer as that integer (BoundTolerance(),
RoundBoundInward(), MakeDomain(), VarDomainToInt64()), as the MIP
drivers do: x <= 3 - 1e-7 allows x = 3. Coefficients and constants
keep the stricter rule. specifications.md and CHANGES.cpsat.md are
updated.

Previous behavior: cvt:pre:inteps=-1 (for bounds; numberof values then
use the 1e-9 rule).

Tests: new e2e case fast/logical cmp_tol_numberof_01 (numberof
0.3/0.1 in (...) counts integer variables at 3) with the variant
exact (cvt:pre:inteps=-1 cvt:pre:ulps=0: infeasible, MIP solvers
only). It is in this commit because CP-SAT passes numberof natively;
it also exercises the converter changes for the MIP drivers. The
cmp_tol_* cases of the previous commits pass on CP-SAT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- With recomputed values (sol:chk:mode bits 32-512), the solver's
  value of a functional expression is compared with the recomputed
  one only on the side its context requires
  (ContextSignedDifference()), as in the check with the solver's
  values. Bits 64 and 128 reported false violations, e.g., of a count
  required to be at least 2 whose solver value was below its true
  value.
- The unary-encoding link constraint has no violation of its own (its
  placeholder reported 1000), which gave false warnings with bits 4
  and 128.
- New option sol:chk:logtol (synonym chk:logtol), default 1e-5: the
  tolerance of truth values inside logical expressions in the check
  (non-strict comparisons, integrality in floor, ceil and round,
  numberof), which used sol:chk:feastol before. sol:chk:feastol and
  feastolrel now measure violations only. Strict comparisons are
  evaluated exactly, because MP encodes them with the gap cvt:mip:eps.
  With the solver's values, a conditional comparison whose result
  differs from its truth is a violation of 1 (was the gap). 0: exact
  evaluation, as in AMPL.

Previous behavior: sol:chk:logtol=1e-6 (the default sol:chk:feastol)
restores the former truth tolerance; the context comparison, the
unary-encoding check and the violation of 1 are fixes without an
option.

Tests: unit tests SolCheckTest.ContextSignedDifference and
SolCheckTest.ConditionalTruthWithinLogTol (converter-flat-test); new
e2e cases fast/logical chk_ctx_count_01, chk_ctx_max_01 (also with
sol:chk:mode=128), chk_logtol_01 (also with logtol=0), chk_uenc_01
(sol:chk:mode=128 and 4).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Where the floating-point margin m (cvt:pre:ulps units in the last
place of the compared constant c) exceeded cvt:pre:feastol, i.e., from
|c| of about 5.4e8 at the defaults, NumericTolerances::DecisionMargin()
returned "do not decide", and such comparisons went to the solver
(review findings W1F-01, W1F-06, W1F-07):
- b <==> x <= U, b <==> x > U and y = 0 ==> x > U at x <= U = 1e13
  gave wrong results, because the solver's gap cvt:mip:eps is below
  the spacing of doubles at U;
- comparisons whose bounds miss a large right-hand side by far were
  passed on, and Gurobi reported a feasible model infeasible or a
  wrong optimum (random models with coefficients of 2.5e8 to 1e11);
- the rule was not monotone in cvt:pre:feastol: x >= 1000 at x <= 10
  was decided at the default and at 0, but not at 1e-12.
The decision margin is now d = max(cvt:pre:feastol, m), as with
cvt:pre:feastol=0 where m is larger. Integer-valued expressions with an
integral right-hand side keep d = cvt:pre:feastol (exact bounds; from
|c| of about 2.8e14, m >= 1 would decide x >= c true at x <= c-1). The
branches for a negative margin in DecideByBounds(),
DecideEqualityByBounds() and IfPreprocess2BndEq() are removed. Help of
cvt:pre:ulps, specifications.md and CHANGES.mp.md are updated.

Tests: unit tests DecisionMarginFromConstant (updated),
DecisionMarginAboveFeastol (converter-flat-test),
CmpTolTest.BigRhs__decidedWithFPMargin,
CmpTolTest.FarFromRhs__decidedAtSmallFeastol and
CmpTolTest.HugeIntegerRhs__notDecidedByFPMargin (converter-mip-test);
the first four fail on the previous commit. New e2e cases fast/logical
cmp_tol_big_rhs_le_01, cmp_tol_big_rhs_gt_01, cmp_tol_big_rhs_impl_01,
cmp_tol_far_01 (also with cvt:pre:feastol=1e-12, checking that no
conditional comparison is passed) and cmp_tol_big_coef_01 (Gurobi
infeasible before; CP-SAT excluded: fractional coefficients).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@glebbelov
Copy link
Copy Markdown
Contributor Author

Tolerances of the converter's decisions; numberof and error-status fixes (4edaa4f38..6d8097f04)

Twelve commits from a review of the conversion of logical and MIP constructs. They fix wrong results at default options found by random testing against enumeration, and make the converter's numeric decisions use stated, consistent tolerances.

Wrong results fixed

  • numberof x in (...) (012b293fd): cvt:pre:sort sorted the reference variable together with the other arguments, so another variable became the counted value. Silent wrong optimum on every driver (for example -2 instead of -1), since 2025-08. Only the arguments after the reference are sorted now.
  • numberof arguments (6aece72a8): the result's context was passed to the compared arguments; they get the mixed context now. Fixes "Part of expression redefinition could be lost" for numberof over max/min/abs, and a wrong optimum for a numberof nested in a numberof.
  • Bounds of rounding-function results (c45d48d55): floor/ceil/round/trunc/div result bounds were rounded from floating-point argument bounds without tolerance, e.g. (2*x3 - x2)/3 with computed upper bound 3.9999999999999996 gave floor <= 3 (false "infeasible"), and ceil((-x-1)/3) lost its optimum. A fractional computed bound is now moved outward by the floating-point margin before rounding; an integral bound is exact.
  • Comparisons decided from bounds (6274be40e, 6d8097f04): e.g. (x+1)/3 >= 2 with x <= 5 was decided false because the computed bound is 1.9999999999999998.

Rules (6d28ae88f, 6274be40e, 6d8097f04)

  • Integrality: new option cvt:pre:inteps (default 1e-6, like AMPL's presolve_inteps; synonyms pre:inteps, cvt:pre:roundintbnd, roundintbnd; values >= 0.5 are rejected). Used for bounds of integer variables, right-hand sides of comparisons with integer bodies, integrality of constants in ==/numberof, unary-encoding values and CP-SAT bounds.
  • Floating-point margin: new option cvt:pre:ulps (default 16): m = ulps * ulp(|c|) of the compared constant c.
  • Conditional comparisons are decided by the converter with d = max(absolute cvt:pre:feastol, m): body >= c TRUE if L >= c - d, FALSE if U < c - d (similarly <=, ==); strict comparisons FALSE with d, TRUE only up to m; otherwise left to the solver. Integer bodies with an integral rhs use d = cvt:pre:feastol.
  • Right-hand sides of comparisons with integer bodies are rounded with cvt:pre:inteps (x <= 0.3/0.1 is x <= 3, before x <= 2); an equality's rhs within m of a bound is set to the bound.
  • ineq2bndeq no longer applies cvt:mip:eps to non-strict comparisons of continuous bodies (wrong optima and false infeasibility before).
  • Warnings strict_cmp_tol and strict_cmp_eps when a strict comparison is decided only within the tolerances, or when cvt:mip:eps is not smaller than the body's range.
  • Defaults of the tolerances are defined in one place (include/mp/flat/num_tolerances.h).
  • Exact behavior: cvt:pre:feastol=0 cvt:pre:inteps=-1 cvt:pre:ulps=0 (see CHANGES.mp.md for what this does and does not restore); cvt:pre:all=0 also switches the presolve steps off.

Other changes

  • Unary encoding (863805181): new option cvt:uenc:maxdom (default 10000) replaces the hard-coded limit 1e7, which allowed memory blow-ups; cvt:uenc:maxdom=10000001 restores it. Values near integers share one flag.
  • Strict integer comparisons with fractional rhs (5e599a6e8): x < 3.5 with cvt:pre:ineqrhs=0 gave x <= 2; now x <= 3.
  • CP-SAT (43518cd62): bounds of rows and variables and numberof values use cvt:pre:inteps; coefficients keep their exact rule.
  • Error status (32e1addff): an error never reports a "solved" status (0-99) to AMPL or through AMPLS; seen with the SCIP driver on a conversion error.
  • Solution check (44b6392f8): recomputed (idealistic) checks, sol:chk:mode bits 32-512, use the expression's context, removing false warnings (e.g. a count value below the recomputed one in positive context); unary-encoding constraints no longer report a placeholder violation (bits 4, 128); new option sol:chk:logtol (default 1e-5): absolute tolerance for truth values inside logical expressions (non-strict comparisons, floor/ceil/round, numberof), separate from the violation tolerances sol:chk:feastol/feastolrel.
  • MP2NL (4edaa4f38): cvt:pre:infeasvarbnd defaults to 1 again in MP2NL 8 , so tha 10BC8 t NL subsolvers that stop with an error on contradictory bounds (lower > upper) report the model infeasible instead.

Tests and validation

  • Unit tests in test/converter-flat-test.cpp and test/converter-mip-test.cpp for each rule; each new test was checked to fail with its rule disabled.
  • 43 new end2end models (37 in fast/logical, 6 in fast/int_ops, existing folders), many with an old-behavior variant.
  • Up to commit 10 (same code except the change of 6d8097f04): unit tests pass; the new cases pass with HiGHS, Gurobi, CPLEX, SCIP, COPT and CP-SAT and fail on 8a3751cc4; fast and fast_random (4100 random logical models) unchanged against 8a3751cc4 on six solvers except one case at the 5 s limit (timing); MP2NL with CONOPT on fast/iis_feasrelax clean.
  • Commit 6d8097f04 (decide with the margin m where it exceeds cvt:pre:feastol, fixing wrong results with constants above about 5e8) builds; its unit, end2end and per-commit checks are still running and will be reported here.

Known follow-ups (not in these commits): the band of sol:chk:logtol is one-sided when cvt:mip:eps is below it (false check warnings with non-default cvt:mip:eps); scale-aware gap for strict comparisons; strict comparisons tightened by rhs rounding without a warning (x < 3.0000001, integer x).

🤖 Generated with Claude Code

glebbelov and others added 2 commits November 27, 2026 17:38
The two cases (commit 6274be4) contain the fractional coefficient 1/3,
which the CP-SAT driver rejects ("failure"), independently of the
comparison decided from bounds that the cases test. Exclude CP-SAT with
"solvers_exclude" so that other solvers still run them.

Checked: CP-SAT skips both cases; HiGHS passes both.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep bound snapping for continuous expression bodies. Check the exact residual in a HiGHS and Gurobi regression where the wrong point otherwise has the right objective.
@glebbelov
Copy link
Copy Markdown
Contributor Author

TASK-050: preserve an exact integer equality RHS

85217475c limits RHS-to-bound snapping to noninteger expression bodies, after the existing integer RHS normalization. The new regression checks x-k=0. The wrong solution had the correct objective, so the objective alone could not detect it.

  • The new test fails on unpatched HiGHS with residual 1 and passes on patched Release HiGHS and Gurobi. Both existing floating-point bound controls pass on patched HiGHS.
  • Patched Release fast/logical: HiGHS 189 configurations with 28 skips and Gurobi 190 with 3 skips, zero failed comparisons. Patched fast/int_ops: 29 configurations each, with 15 HiGHS skips and 14 Gurobi skips, zero failed comparisons. Per-case limit: five seconds.
  • Remaining separately: a small configured MIP gap can cause a false check failure with default sol:chk:logtol. Recomputed auxiliary bounds can also be masked by a permitted-side discrepancy in the checker; an end-to-end impact has yet to be established. The focused change preserves continuous RHS snapping. Its effect on the original model data is a separate review question.

Review attribution — OpenAI Codex, with two independent review rounds including a separate GPT-6.1-sol reviewer.

@mapgccv
mapgccv commented Dec 3, 2026 •
Copy link
Copy Markdown
Contributor

Closing: MP is now maintained inside AMPL's integration repository, and these changes (together with the follow-up fixes on task-050/stage2-fixes, head 9be04c6) continue in private 115.

@mapgccv mapgccv closed this Dec 3, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

0