Skip to content

Task 045/logical conversion fixes - #291

Closed
glebbelov wants to merge 39 commits into
masterfrom
task-045/logical-conversion-fixes
Closed

glebbelov wants to merge 39 commits into
masterfrom
task-045/logical-conversion-fixes

Conversation

@glebbelov

Copy link
Copy Markdown
Contributor

No description provided.

glebbelov and others added 9 commits November 17, 2026 17:42
…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>
…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>
glebbelov and others added 18 commits November 18, 2026 18:08
…ables, with fill limits

Linear and quadratic subexpressions are now also inlined into the bodies of
linear and quadratic functional constraints, e.g., the linearization of NOT
(1-b) inside that of an equivalence (a-b). With expressions passed to the
solver (MP2NL, acc:_expr=1), such nested linear terms were written as
nonlinear assignments: CPLEX and Xpress through MP2NL rejected the model as
"not convex quadratic", and nonlinear solvers got linear parts as nonlinear.

- cvt:pre:unnest bit 32 (default now 63): walk LinearFunctionalConstraint
  and QuadraticFunctionalConstraint bodies with the existing
  AlgebraicExpressionInliner (CollectAlgSubExpr, RedefineVariable); a final
  pass in ConvertDelayedItems() revisits all items, as subexpressions can
  be created after their parents. A body cancelling to a constant fixes
  the result (Xpress rejected a formula without variables).
- cvt:pre:linfill (default 10) and cvt:pre:quadfill (default -1, no limit)
  limit the fill of inlining a shared subexpression by the upper bound
  (u-1)(k-1)-2 (k terms, quadratic terms only for quadfill; u uses). A
  linear subexpression not inlined stays a variable with its linear
  definition and the bounds implied by it, also with NL output.
- "See also" cross-references between cvt:pre:unnest, cvt:pre:linfill,
  cvt:pre:quadfill, cvt:dvelim and cvt:expr:nlassign.

cvt:pre:unnest=31 cvt:pre:linfill=-1 restores the old behavior.
Tests: end2end logical/inline_lin_*, inline_quad_* (incl. no cycles with
quadratic indicators/constraints disallowed) and nonlinear/inline_*
(bounds stronger or not, cvt:pre:boundsbest, quadratic in linear,
constant bodies, fill chain).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A function result relaxed by context to one inequality (NLAssignLE/GE,
e.g., v <= exp(.) inside log(1 + v^2)) loses the side of its best-known
bounds that the definition implied (v >= 0). Contexts of other items may
rely on it (v^2 is increasing for v >= 0), so it is now submitted as a hard
bound. Gurobi 14 (expressions passed) returned an infeasible point.

Test: end2end nonlinear/exp_square_ctx_01 (generated, optimum by brute force).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
alg:rays (default 3) set InfUnbdInfo=1 for every model. Rays are returned
for continuous models only, and on a MIP with general constraints Gurobi
13 and 14 then returned a wrong "optimal" solution (root relaxation
unbounded): -6.29987 instead of -10.3, reproduced with gurobi_cl 14 on the
exported MPS file with InfUnbdInfo=1 only.

Test: end2end nonlinear/ite_nested_quad_01 (generated).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Accepted (description HIDDEN: not listed) for a common interface with the
other MP drivers, so that cases can pass mip:round in mp_options; integer
variables of these CP solvers are integral anyway.
end2end logical/int_ne_05_ctx_redef: mip:round=1, as a solver can return
x = 5 + 1e-15, which AMPL then evaluates as x <= 5 false.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- cvt:pre:roundintbnd: the tolerance is relative, tol*max(1,|b|), at most
  0.5. With the absolute 1e-9, a computed bound like 16800000.7/0.1 =
  168000006.99999997 lost a unit: a feasible model was declared
  infeasible, or the optimum was cut off by a big-M.
- cvt:pre:infeasvarbnd: contradictory bounds are passed on when
  alg:feasrelax or iis:find is requested (options looked up by name), and
  by MP2NL by default (DeclareInfeasVarBndDefault()), so that the solver
  can relax the model or compute an IIS.
- The fill limits apply to the expressions written for solvers accepting
  them only with bit 32 of cvt:pre:unnest, so cvt:pre:all=0 gives the
  previous model; cvt:pre:quadfill is checked there as well, and a kept
  quadratic subexpression gets its implied bounds.
- end2end: roundint_bnd_01/02, infeasvarbnd_01 (4 modes), quadfill_nl_01,
  linfill_gate_01, inline_lin_nested_not_01 'unnest=31 linfill=-1' and
  'preall0', counters for fixed_indicator_flag_01_preall0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- MP2NL's default cvt:pre:infeasvarbnd=0 (c492589) passed contradictory
  bounds to ASL subsolvers (CONOPT, LINDO Global, Xpress ASL), which then
  failed instead of reporting infeasibility. Back to 1; the option text
  says to set 0 for a subsolver's relaxation or IIS through MP2NL.
- roundint_bnd_01/02: Knitro, BARON and ilogcp return 168000006 also
  without rounding (their precision), CP solvers do not take such
  domains, MOSEK reports the unrounded model infeasible: the cases list
  the MIP solvers that pass (MOSEK only with the default rounding).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
- CPLEX: FeasOpt modes MIN_* (alg:feasrelax 1-3) end with
  *_FEASIBLE_RELAXED_* when the minimal relaxation is found; reported as
  solved ("minimal relaxation found") instead of 400.
- MOSEK: status key MSK_SK_INF of an infeasibility certificate maps to
  basis status none instead of stopping the driver.
- Xpress: when no IIS was identified (e.g., a bound conflict), .iis is
  'non' everywhere with warning IIS_NONE instead of error 721.
- end2end: infeasvarbnd_01 'infeasvarbnd=0' also on MOSEK; tag
  'continuous' for infeasvarbnd_01.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…; rounding tolerance

Review of c492589:
- Passing contradictory deduced bounds on when alg:feasrelax or iis:find
  is requested made the solver relax or explain the converter's bounds
  instead of the user's constraints (relaxation 2 instead of 1, IIS of x's
  bounds instead of the two constraints), brought back error 500 for
  indicator binaries (Xpress, SCIP, COPT), and ignored an explicit
  cvt:pre:infeasvarbnd=1. The converter declares infeasibility again
  unless cvt:pre:infeasvarbnd=0; the message and the option text say so.
  DeclareInfeasVarBndDefault() removed (no longer overridden).
- cvt:pre:roundintbnd: tolerance max(tol, 1e-13*|b|), at most 0.5. The
  relative 1e-9 rounded fractional data bounds like 599999999.5 to the
  nearest integer from about 5e8 on (an infeasible model solved by Xpress).
- The fill limits in expression output apply with bit 32 of
  cvt:pre:unnest only together with bit 2 or 4, as documented.
- end2end: infeasvarbnd_01 with feasrelax/iisfind expect infeasible;
  roundint_bnd_03 (fractional bound, infeasible), roundint_bnd_04
  (2000000000.0000002 must round to 2000000000).

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

- cvt:pre:infeasvarbnd: the infeasibility message no longer suggests 0
  for iis:find/alg:feasrelax; the option text warns that with 0 an IIS or
  a relaxation concerns the deduced bounds and that HiGHS can return a
  wrong relaxation.
- cvt:pre:roundintbnd: the text warns that no rounding (negative) can
  give wrong results.
- Fill limits in expression output: quadratic subexpressions need bit 4
  of cvt:pre:unnest (with 32); linear ones bit 2 or 4.
- Xpress: no IIS_NONE warning when XPRSiisfirst() itself failed (its
  error is reported as IIS_COMPUTE).

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

- cvt:pre:infeasvarbnd: default 0 (behavior before the option): a warning,
  which now names the option, and the contradictory bounds are passed on
  to the solver. With 1 the converter declares infeasibility.
- MOSEK: a certificate (infeasibility or ill-posedness) has no basis:
  GetBasis() returns none instead of taking the certificate's status keys
  (MSK_SK_INF) for one. Solve result 200 as before.
- HiGHS alg:feasrelax: HiGHS 1.15 does not relax a column or row with
  lower > upper and returns Ok with a point of violation cost 0. The
  driver computes the least cost such bounds imply and fails if HiGHS
  reports less, so a HiGHS that relaxes them is accepted.
- end2end: the cases on the converter's infeasibility set
  cvt:pre:infeasvarbnd=1 via mp_options; infeasvarbnd_01 cases for 0:
  feasrelax on Gurobi/CPLEX/COPT, failure on HiGHS, IIS incl. Xpress.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…y unary domain

- Results of floor, ceil, round, trunc, div, mod get their preprocessed
  bounds as hard bounds (IfHardResultBounds): MP2NL subsolvers with big-M
  conversions failed with "Set bounds on variables participating in
  logical expressions", and SCIP 10.0.2 reported 22 instead of 10 on a
  conditional div.
- x div y: |rem| <= |y| - eps by the sign of y (indicators on a sign
  binary) instead of reusing abs(y), which can be converted one-sided
  ("Part of expression redefinition could be lost").
- Unary encoding of a variable with an empty domain (x == 1 and x == -1,
  contradictory bounds passed on): infeasible instead of "vector".
- cvt:pre:unnest help: 31 together with linfill=-1 gives the old behavior.
- end2end: int_ops_03..05, eq_contradict_01.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…timizer errors, HiGHS/COPT feasrelax, CP-SAT)

- Xpress (legacy pool) and COPT: the default pool gaps (1e100) mean no
  limit; a best objective of 0 made the relative gap 0.
- CPLEX: alg:feasopt/feasoptobj out of range rejected (feasoptobj indexed
  an array: SIGSEGV); mip:bestnode from BestDualBound() (garbage after a
  fixed-model solve); optimizer call failures thrown (CPLEX_CALL_THROW)
  instead of an unknown result -1.
- HiGHS: after alg:feasrelax, MIP gap 0 and bound = relaxation objective
  instead of the values of the solve before the relaxation.
- COPT: alg:feasrelax 4-6 with an infinite relaxation objective reported
  as unbounded (300), not solved.
- CP-SAT: variables fixed at non-integer values (MP's constants) enter the
  objective's offset; hints cleared before a MIP start (AddPrimalDualStart
  forwarded the start a second time: duplicate hints).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The relative pool gap is poolgap * |best objective| in all these
drivers, as in Gurobi and CPLEX, so with the best objective near 0
only the best solutions remain. The help now points to sol:poolgapabs;
SCIP's help also states the rule.

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

- Variables and linear constraints added by the conversion (abs, max,
  logical expressions, ...) got penalty 0 (Gurobi, COPT, CPLEX) or the
  global penalty (HiGHS), so a relaxation could violate the original
  constraint they represent at no cost and still report "solved"
  (abs(x-5) <= 1 relaxed to x = 0). FlatBackend::FeasrelaxPenaltiesInSolver
  maps the penalties to solver coordinates and marks added elements, and
  infinite penalties, with the solver's not-relaxable value. A constraint
  is "added" if it receives 0 when a vector of ones is presolved.
- CPLEX: CPXfeasopt takes preferences (cost = violation / preference,
  0 = not relaxable), but got the penalties; now 1/penalty.
- end2end: feasrelax_aux_01, feasrelax_pen_01/02.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
With sol:poolmode 1/2 the solution counting stops after sol:poollimit
solutions in no particular order, so the pool could miss the optimum
(poollimit=2 reported objectives 1 and 0 for an optimum of 21). The best
solution of the solve is added unless counted, replacing the worst at
the limit. The help no longer shows "default" for value 0 (default 2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The conversion (and solvers with native division) treat the divisor as
nonzero in the whole model, also where a guard means the division is
not evaluated. The warning divisor_domain_0 says so; options for a
context-aware treatment are left for a later decision.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SCIP names an indicator's slack variable and linear row after the
constraint. Without names (the usual case) all were "indslack_" and
"indlin_", so a CIP export re-read gave a different, infeasible model.
Unnamed indicators get "ind<n>"; the halves of an equality "_le"/"_ge".

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The tolerance max(roundintbnd, 1e-13*|b|) reached 1e-4 at |b| = 1e9, so
a bound 1e9 + 5e-5 was rounded to 1e9. Rounding errors of computed
bounds are a few ulp; the tolerance is now max(roundintbnd, 16 ulp(b)),
at most 0.5 (2e-6 at 1e9). Unit test RoundIntBoundUsesUlpTolerance
(fails with the old tolerance).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
glebbelov and others added 12 commits November 19, 2026 18:02
- MOSEK: the global interrupt flag was never reset, so after a Ctrl-C
  every later solve in the process (AMPLS) stopped at the first callback.
- Xpress: a MINLP's main status said "no duals" next to "Fixed MIP for
  mip:basis: ... with duals"; the main message omits the duals note
  for MIP, whose duals come from the fixed model.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
WrapLines() breaks long lines at the last space that fits; continuation
lines keep the indentation. Explicit line breaks, lines with two spaces
inside (tables such as the solution check) and words longer than the
width (paths, URLs) are kept. Applied to each warning and to the error
message in ReportError(); the solver's own log and the solve message
are not changed. Unit test UtilTest.WrapLines.

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

- HiGHS feasrelax: a relaxed point that violates a non-relaxable element
  (negative penalty) was reported "solved"; the driver checks the point
  and reports infeasible (as Gurobi and CPLEX). feasrelaxDone_ and the
  new flag are reset per solve (repeated AMPLSSolve).
- tech:msgwidth (default 60; 0: no wrapping, the old output).
- WrapLines: no trailing spaces or empty indented line when a wrapped
  line ends with spaces; trailing spaces do not make a line a table.
- int_ops_04: 10 is MP's optimum with the divisor treated as nonzero
  (known limitation; 3 under AMPL's semantics); feasrelax_pen_02 checks
  x+y <= 1 instead of one point of a tie; new feasrelax_pen_03.
- Changelogs: hard result bounds in user terms, feasrelax limitations
  (logical constraints, presolve using relaxable constraints;
  cvt:pre:all=0), old rounding tolerance, CPLEX migration note, Xpress
  MINLP message wording, HiGHS fix.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… divisor warning, CP-SAT fixed fraction

- feasrelax_ubpen_01/02 (Gurobi, HiGHS, CPLEX, COPT): .ubpen below and
  above c's .rhspen decides whether the bound or the constraint is
  relaxed (CPLEX inverted it before).
- infeas_int_01 feasopt=3: rejected by CPLEX (crashed before).
- div_warn_01: warning divisor_domain_0 in the solve message.
- cpsat_fixed_frac_01: a variable fixed at 2.5 passed to CP-SAT.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…r gecode/ilogcp

The unsupported multi-objective message was formatted to 78 columns and then
wrapped again at 60 by ReportError(), giving ragged lines. The tests that set
cvt:pre:infeasvarbnd=1 are excluded for gecode and ilogcp, which do not have
the option.

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

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

Warning texts with explicit line breaks were wrapped line by line at
tech:msgwidth and came out ragged. The header line ("WARNING:  ...") is kept
as is; the text below it is wrapped with its indentation. Unit test.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…pt tests; div_warn_01 solved

The feasrelax limitation named cvt:pre:all=0 as a remedy, which does not
avoid deduced bounds; it now describes the limitation and AMPL's presolve.
The two roundintbnd entries are merged. CPLEX: feasopt=3 and feasoptobj=4
are rejected with a message (msgwidth=0 in the check). div_warn_01 uses an
integer div, so all listed solvers solve it, and checks the optimum.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
SOS2 from AMPL's linearization of nonconvex piecewise-linear terms plus
logical constraints; optimum 0. The fixed LP solved for duals has no
SOS constraints, and its optimum -3.3 is that of the convex relaxation.
A generic case with mip:basis=1 and a cplexasl case with mipbasis=1
(the MIP solution is kept and the message says why).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
4100 small integer models in 13 generated rounds (glog, glog2, gctx),
with expected results from enumerating the bounded integer domain, as
generated. Not run by default; README.md describes the rounds and how
to run them.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
At most 80 characters per line, long statements broken before the
operator of lowest precedence, blank lines between declarations,
objectives and constraints, coefficients without parentheses. The NL
file of every model, written with presolve off and on, is unchanged.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
logical_models.py generates the rounds of fast_random (glog, glog2,
gctx) with their expected results by enumeration; seeded by the round,
it reproduces all 13 committed rounds byte for byte, laid out and with
--raw as first committed. amplfmt.py lays the models out, nlcheck.py
checks that a layout change leaves the NL files unchanged. README.md
gives the generators, seeds and commands.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@glebbelov

Copy link
Copy Markdown
Contributor Author

Moved the changes to the integrated PR #293.

@glebbelov glebbelov closed this Nov 20, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant