8000 Task 043: Row/column vector fixes, cone fixes, bounds of exp/log results, driver fixes by glebbelov · Pull Request #290 · ampl/mp · GitHub
[go: up one dir, main page]

Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
0addf86
end2end: 5-second default limit for fast cases; run MP drivers as MP2…
glebbelov Nov 15, 2026
e4e24d5
cones: fix QP-objective cones and two silent cone defects
glebbelov Nov 15, 2026
e9b23c7
multiobj emulator: relax the nonlinear part of a pass objective in th…
glebbelov Nov 15, 2026
c318bb9
preprocessing: bound the results of exp, expA, log and logA by their …
glebbelov Nov 15, 2026
de77bff
baronmp: duals, skipped constraints, scratch directory ownership, '==…
glebbelov Nov 15, 2026
ef3446d
gcgmp, mosek, cbcmp, mp2nl, cuoptmp, scipmp: small fixes found by the…
glebbelov Nov 15, 2026
6bbb171
xpress, cplex, gurobi, copt: constraint groups, fixed-model duals, na…
glebbelov Nov 15, 2026
2361387
Tests: exp result lower bound in BoundsBestExprTest follows the exp b…
glebbelov Nov 16, 2026
17138ee
gurobi, xpress, copt: the native multi-objective error names cvt:quad…
glebbelov Nov 16, 2026
7ff0dee
Changelogs: one unreleased section in mosek and gcgmp; same spelling …
glebbelov Nov 16, 2026
01ddfaf
Multi-objective message and changelogs: no option synonyms; Xpress 10…
glebbelov Nov 16, 2026
99eca00
qcones2qc: a cone head fixed at a negative value stays infeasible
glebbelov Nov 16, 2026
d703b2a
PL approximation: integer domain ends rounded with a tolerance
glebbelov Nov 16, 2026
684bf3c
end2end: multiobj_QP_02 moves the objective with both cvt:quadobj=0 a…
glebbelov Nov 16, 2026
2453768
Merge remote-tracking branch 'origin/master' into task-043/start-vect…
mapgccv Nov 19, 2026
222373c
Merge remote-tracking branch 'origin/master' into task-043/start-vect…
mapgccv Nov 19, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
- Preserve unrelated local changes and generated artifacts. Follow existing conventions and keep changes scoped to the task.
- Consider model semantics, numerical behavior, solver capabilities, options, suffixes, and result mapping when changing solver interfaces or transformations.
- Use this repository's build and test configuration. Run relevant unit, regression, and end-to-end checks for the affected behavior; a consuming project's build does not establish that component tests passed.
- Run the `fast` end-to-end test set (`test/end2end/cases/categorized/fast`) with a 5-second per-instance limit; `test/end2end/run.py` applies it by default to a `fast` folder, and `--timeout` overrides it. Keep every case in `fast` solvable within that limit; report a case that exceeds it as a timeout, not as a wrong result. Use longer limits only for other test sets.
- Add regression coverage for substantive correctness changes when practical. Do not assume that all solver SDKs or licenses are available.
- Report what changed, what was checked, and any validation limitations.
- Keep credentials, confidential models, and private consumer details out of documentation and test fixtures.
27 changes: 27 additions & 0 deletions CHANGES.mp.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,37 @@ Summary of recent updates to the AMPL MP Library

## Unreleased

- Fixed wrong results of the multi-objective emulator with nonlinear
objectives (for example `exp(x)`) when the first objective has a negative
`.objweight`: the pass objective's nonlinear part was relaxed in the wrong
direction, so a solver could report an unbounded or a wrong optimal
solution. Solvers that take nonlinear objectives natively were affected
with `cvt:nlobj=0` or when the objective was reformulated.
- Fixed a wrong objective in models with a convex quadratic objective whose
squared terms have a coefficient other than 1 (for example `maximize
3*x - 0.8*x^2`) when the model also has quadratic constraints recognized
as second-order cones: the objective's cone used the coefficient instead of
its square root, so the objective term was off (0.8 became 0.64).
Observed with BARON through MP.
- Fixed second-order cones whose first variable is fixed by its bounds,
for solvers that receive the cone as a quadratic constraint (for example
Gurobi, Xpress, CPLEX, BARON): `sqrt(x^2 + y^2) <= t` with `t` fixed at 3
became `x^2 + y^2 <= 3` instead of `<= 9`. A negative fixed value keeps
the constraint infeasible.
- Fixed a regression in 20261029: with variable names passed to the solver
(for example `option highs_auxfiles rc;`), HiGHS failed some logical
models with "Error -1 for call ... Highs_passColName". Columns that MP
adds for constant values now get generated names (`_svar<n>_`).
- Result bounds of `exp`, `a^x`, `log` and `log10`/`log_a` now follow
from the bounds of their argument (they were only `>= 0` for the
exponentials and unbounded for the logarithms). Logical and indicator
constraints that contain such a function with a bounded argument, for
example `b == 0 ==> exp(x) <= 2` with `x <= 5`, no longer stop with
"Set bounds on variables participating in logical expressions" when the
solver needs big-M (`acc:ind...=0`, or no native indicators). New option
*cvt:pre:funcbndtol* (default 1e-12) is the relative margin added to the
computed bounds against rounding; a negative value restores the previous
behavior.

## 20261029

Expand Down
66 changes: 55 additions & 11 deletions include/mp/flat/constr_prepro.h
Original file line number Diff line number Diff line change
Expand Up @@ -955,38 +955,82 @@ class ConstraintPreprocessors {
}

////////////////////// NONLINEAR FUNCTIONS //////////////////////
/// Result range of a monotone function f over the argument bounds
/// [lb, ub], widened by the relative margin cvt:pre:funcbndtol.
/// Infinite ends stay infinite.
/// @return {lb, ub}, or {-Infty, Infty} if f is undefined (NaN)
/// or if the margin is negative (the old behavior, no such bounds)
template <class F>
std::pair<double, double> MonotoneRange(F f, double lb, double ub) {
const double tol = MPCD( FuncBoundTol() );
const double r0 = f(lb), r1 = f(ub);
if (tol < 0.0 || std::isnan(r0) || std::isnan(r1))
return { MPD( MinusInfty() ), MPD( Infty() ) };
const double rl = std::min(r0, r1), ru = std::max(r0, r1);
const auto widen = [tol](double r, double dir) { // 0*inf is NaN
return (0.0 == tol || std::isinf(r)) ? r : r + dir * tol * std::fabs(r);
};
return { widen(rl, -1.0), widen(ru, 1.0) };
}

/// Bounds of the argument; the lower bound of a logarithm's argument
/// is at least 0
std::pair<double, double> LogArgBounds(int x) {
return { std::max(0.0, MPD( lb(x) )), MPD( ub(x) ) };
}

/// Bound the result of exp(x): positive, and by the argument's bounds
template <class PreprocessInfo>
void PreprocessConstraint(
ExpConstraint& , PreprocessInfo& prepro) {
prepro.narrow_result_bounds(0.0, MPD( Infty() ));
ExpConstraint& c, PreprocessInfo& prepro) {
const auto x = c.GetArguments()[0];
const auto r = MonotoneRange(
[](double v) { return std::exp(v); }, MPD( lb(x) ), MPD( ub(x) ));
prepro.narrow_result_bounds(std::max(0.0, r.first), r.second);
}

/// Bound the result of a^x, a>0: positive, and by the argument's bounds
template <class PreprocessInfo>
void PreprocessConstraint(
ExpAConstraint& , PreprocessInfo& prepro) {
prepro.narrow_result_bounds(0.0, MPD( Infty() ));
ExpAConstraint& c, PreprocessInfo& prepro) {
const auto x = c.GetArguments()[0];
const double a = c.GetParameters()[0];
const auto r = MonotoneRange(
[a](double v) { return std::pow(a, v); }, MPD( lb(x) ), MPD( ub(x) ));
prepro.narrow_result_bounds(std::max(0.0, r.first), r.second);
}

/// Narrow the argument of a logarithm to nonnegative (see
/// cvt:pre:boundlogarg), and bound the result by the argument's bounds
template <class PreprocessInfo>
void PreprocessConstraint(
LogConstraint& c, PreprocessInfo& ) {
auto x = c.GetArguments()[0]; // if no positive lb,
LogConstraint& c, PreprocessInfo& prepro) {
const auto x = c.GetArguments()[0]; // if no positive lb,
if (MPCD( IfBoundLogArg() )) {
MPD( NarrowVarBounds(x, 0.0, MPD( Infty() )) );
} else {
MPD( NarrowVarBestBounds(x, 0.0, MPD( Infty() )) );
}
const auto xb = LogArgBounds(x);
const auto r = MonotoneRange(
[](double v) { return std::log(v); }, xb.first, xb.second);
prepro.narrow_result_bounds(r.first, r.second);
}

/// As for Log, with base a>0
template <class PreprocessInfo>
void PreprocessConstraint(
LogAConstraint& c, PreprocessInfo& ) {
LogAConstraint& c, PreprocessInfo& prepro) {
const auto x = c.GetArguments()[0];
if (MPCD( IfBoundLogArg() ))
MPD( NarrowVarBounds(
c.GetArguments()[0], 0.0, MPD( Infty() )) );
MPD( NarrowVarBounds(x, 0.0, MPD( Infty() )) );
else
MPD( NarrowVarBestBounds(
c.GetArguments()[0], 0.0, MPD( Infty() )) );
MPD( NarrowVarBestBounds(x, 0.0, MPD( Infty() )) );
const auto xb = LogArgBounds(x);
const double la = std::log(c.GetParameters()[0]);
const auto r = MonotoneRange(
[la](double v) { return std::log(v) / la; }, xb.first, xb.second);
prepro.narrow_result_bounds(r.first, r.second);
}

template <class PreprocessInfo>
Expand Down
15 changes: 15 additions & 0 deletions include/mp/flat/converter.h
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,7 @@ class FlatConverter :
int preproUnnest_ = 31;
int preproSortUnify_ = 1;
int boundLogArg_ = 0;
double funcBndTol_ = 1e-12;

int propCtxIneq_ = 1;
int propCtxBndEq_ = 1;
Expand Down Expand Up @@ -1868,6 +1869,8 @@ class FlatConverter :
int IfPropCtxCountNumberof() const { return options_.propCtxCountNumberof_; }
/// Bound argument of logarithm?
bool IfBoundLogArg() const { return options_.boundLogArg_; }
/// Relative margin for result bounds of exp/log functions
double FuncBoundTol() const { return options_.funcBndTol_; }

/// Model checking options
double model_feas_tol() const { return options_.modelfeastol_; }
Expand Down Expand Up @@ -2092,6 +2095,18 @@ class FlatConverter :
"0*/1: Bound logarithm arguments to nonnegative.",
options_.boundLogArg_, 0, 1);

GetEnv().AddOption("cvt:pre:funcbndtol funcbndtol",
"Relative margin by which the result bounds of "
"exp, expA, log and logA, computed from the "
"bounds of their argument, are widened, "
"to absorb rounding. 0: no margin (a computed "
"bound can then be tighter than the true one "
"by a rounding error). "
"Negative: do not bound the results this way "
"(old behavior: exp, expA >= 0, no bounds for log). "
"Default 1e-12.",
options_.funcBndTol_, -1.0, 1.0);

GetEnv().AddOption("cvt:quadobj passquadobj",
ModelAPIAcceptsQuadObj() ?
"0/1*: Pass quadratic objective terms to the solver. "
Expand Down
6 changes: 5 additions & 1 deletion include/mp/flat/converter_multiobj.h
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,11 @@ class MOManager : public BasicObjOptionSetter {
passes_reverse_.at(i0_vec.front()) = i_pass;
obj_new_.push_back(obj_orig_1st);
obj_new_.back().set_sense(obj_orig.front().obj_sense()); // "Legacy" obj:multi:weight
obj_new_.back().set_sense_true(obj_orig.front().obj_sense_true());
// The pass is solved in its sense; its coefficients already carry the
// (signed) legacy weights. The first objective's own sense_true was
// flipped by a negative weight and must not be copied, or the
// expression contexts (relaxation direction) point the wrong way.
obj_new_.back().set_sense_true(obj_new_.back().obj_sense());
obj_new_.back().GetLinTerms() *= objwgt_1st; // Use weight
obj_new_.back().GetQPTerms() *= objwgt_1st;
obj_new_tola_.push_back(objtola.at(i0_vec.front()));
Expand Down
13 changes: 7 additions & 6 deletions include/mp/flat/redef/conic/cones.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,11 +120,12 @@ class ConicConverter : public MCKeeper<MCType> {
int z = (int)MC().AddVar(0.0, MC().Infty());
int z1 = (int)MC().MakeFixedVar(1.0);
// Add cone
// The cone is sum_i (c_i x_i)^2 <= 2 (c_0 z) (c_1 z1), i.e.,
// sum_i q_i x_i^2 <= z with c_i = sqrt(q_i), where q_i = |coef|
// (their signs were checked above): coefficients enter squared.
std::vector<double> c = {{1.0, 0.5}};
c.insert(c.end(), qp.coefs().begin(), qp.coefs().end());
if (objsns > 0) // negate coefs if maximizing
for (size_t i=2; i<c.size(); ++i)
c[i] = -c[i];
for (auto q: qp.coefs())
c.push_back(std::sqrt(std::fabs(q)));
std::vector<int> x = {{z, z1}};
x.insert(x.end(), qp.vars1().begin(), qp.vars1().end());
MC().AddConstraint(
Expand Down Expand Up @@ -800,8 +801,8 @@ class Convert1ExpC : public MCKeeper<MCType> {
} else if (auto pConLin = MC().template
GetInitExpressionOfType<LinearFunctionalConstraint>(y0)) {
const auto& ae = pConLin->GetAffineExpr();
if (0.0 == std::fabs(ae.constant_term() &&
1==ae.GetBody().size())) {
if (0.0 == ae.constant_term() &&
1==ae.GetBody().size()) {
const auto& body = ae.GetBody(); // tested by expcones_06.mod
if (y == body.var(0)) { // v2 = z / (c1*y)
result.coefs_ = {b, b/body.coef(0)};
Expand Down
8 changes: 7 additions & 1 deletion include/mp/flat/redef/conic/qcones2qc.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#ifndef QCONES2QC_H
#define QCONES2QC_H

#include <cmath>

#include "mp/flat/redef/redef_base.h"
#include "mp/flat/constr_std.h"

Expand Down Expand Up @@ -41,7 +43,11 @@ class QConeConverter :
GetMC().AddConstraint(std::move(qc));
} else {
// Reproduce fixed RHS, better for Mosek & COPT. conic/socp_10
auto rhs = -c[0] * GetMC().fixed_value(x[0]);
// c[0] is -c0^2 here: the fixed value enters squared, (c0*v)^2.
// The cone also needs v >= 0: a negative v gives a negative
// right-hand side, (c0^2)*v*|v|, so the row is infeasible.
const double v0 = GetMC().fixed_value(x[0]);
auto rhs = -c[0] * v0 * std::fabs(v0);
c.erase(c.begin());
auto x0 = x;
x0.erase(x0.begin());
Expand Down
7 changes: 7 additions & 0 deletions solvers/baronmp/CHANGES.baronmp.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
Summary of recent updates to BARONMP for AMPL
=============================================

## unreleased
- Fix: solution pool solutions (*numsol*) were reported with the
variables in BARON's order instead of AMPL's.
- Fix: with *alg:wantdual=1*, the dual values were always zero: the
constraint prices were not read from BARON's result file.


## 20261029
- New options for documented BARON settings: *alg:feastol*
(AbsConFeasTol), *mip:intfeastol* (AbsIntFeasTol), *alg:boxtol*,
Expand Down
43 changes: 34 additions & 9 deletions solvers/baronmp/baronmpbackend.cc
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
#include <algorithm>
#include <vector>
#include <climits>
#include <cfloat>
Expand Down Expand Up @@ -87,7 +88,7 @@ void BaronmpBackend::CloseSolver() {
else
{
deinitBaronFile();
recrmdir(baronDir);
removeBaronDir();

}
}
Expand Down Expand Up @@ -121,20 +122,43 @@ bool BaronmpBackend::IsMaximize() const {
}

ArrayRef<double> BaronmpBackend::PrimalSolution() {
auto vec = resFileData_.PrimalSolution(IsMaximize());
int num_vars = vec.size();
std::vector<double> x(num_vars);
for (int i = 0; i < num_vars; i++)
x[lp()->baronToAMPLIndices[i]] = vec[i];
return ToAMPLOrder(resFileData_.PrimalSolution(IsMaximize()));
}

std::vector<double> BaronmpBackend::ToAMPLOrder(
const std::vector<double>& vec) const {
const auto& idx = lp()->baronToAMPLIndices;
if (vec.size() != idx.size()) // e.g., a truncated result file
return {};
std::vector<double> x(vec.size());
for (size_t i = 0; i < vec.size(); i++)
x[idx[i]] = vec[i];
return x;
}

pre::ValueMapDbl BaronmpBackend::DualSolution() {
return {{ { CG_Linear, DualSolution_LP() } }};
return {{ { CG_Algebraic, DualSolution_LP() } }};
}

ArrayRef<double> BaronmpBackend::DualSolution_LP() {
return resFileData_.DualSolution();
auto duals = resFileData_.DualSolution();
// Constraints without terms are not in BARON's model: duals of zero
const auto& skipped = lp()->skippedConsPositions;
if (!skipped.empty() && !duals.empty()) {
std::vector<double> full;
full.reserve(duals.size() + skipped.size());
size_t next = 0; // next BARON equation
for (size_t pos = 0; next < duals.size() || pos <= (size_t)skipped.back(); ++pos) {
if (std::find(skipped.begin(), skipped.end(), (int)pos) != skipped.end())
full.push_back(0.0);
else if (next < duals.size())
full.push_back(duals[next++]);
else
break;
}
return full;
}
return duals;
}

double BaronmpBackend::ObjectiveValue() const {
Expand Down Expand Up @@ -206,7 +230,8 @@ void BaronmpBackend::ReportBARONMPPool() {
const auto& solutions = resFileData_.PrimalSolutions();
const auto& objectives = resFileData_.Objectives();
for (size_t i = 0; i < solutions.size() && i < objectives.size(); ++i)
ReportIntermediateSolution({ solutions[i], {}, { objectives[i] } });
ReportIntermediateSolution( // BARON's variable order -> AMPL's
{ ToAMPLOrder(solutions[i]), {}, { objectives[i] } });
}

void BaronmpBackend::AddBARONMPMessages() {
Expand Down
2 changes: 2 additions & 0 deletions solvers/baronmp/baronmpbackend.h
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,8 @@ class BaronmpBackend :
/// PrimalSolution() for flat backends.
/// @return empty vector if no primal solution.
ArrayRef<double> PrimalSolution() override;
/// A primal vector in BARON's variable order -> AMPL's order.
std::vector<double> ToAMPLOrder(const std::vector<double>& vec) const;
/// DualSolution() for flat backends.
/// @return empty map if no dual solution.
pre::ValueMapDbl DualSolution() override;
Expand Down
23 changes: 22 additions & 1 deletion solvers/baronmp/baronmpcommon.cc
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,7 @@ void BaronmpCommon::initDirectories(const std::string& stub,
break;
}
baronDir = scratch_path.string();
baronDirOwned = false; // the user's directory: keep unrelated files
}
}
if (!fs::exists(scratch_path)) {
Expand Down Expand Up @@ -339,6 +340,20 @@ void BaronmpCommon::initDirectories(const std::string& stub,

changeDirectory(baronDir);
}
void BaronmpCommon::removeBaronDir() {
if (baronDirOwned) {
recrmdir(baronDir);
return;
}
for (const auto& f : { BARON_TIM, BARON_RES, std::string("sum.lst"),
FILENAME_BAR + ".bar", FILENAME_AMPL + ".bar",
FILENAME_DIC + ".txt" })
deleteFilesIfExists(baronDir, f);
for (int i = 1; deleteFilesIfExists(baronDir,
fmt::format("{}_{}.bar", FILENAME_BAR, i)); ++i)
;
}

int BaronmpCommon::recrmdir(const std::string& dname) {
if (fs::is_directory(dname)) {
std::error_code ec;
Expand Down Expand Up @@ -852,7 +867,13 @@ bool ResFileData::readSolution(std::ifstream& barRes) {
case 1:
return true;
case 2:
getline(barRes, line); // Constraint no. Price
// The dual section is "Corresponding dual solution vector is:",
// "Variable no. Marginal" + the variable marginals, then
// "Constraint no. Price" + the constraint prices (the duals):
getline(barRes, line); // Corresponding dual solution vector is:
getline(barRes, line); // Variable no. Marginal
readVector(barRes); // variable marginals; also consumes the header
// line "Constraint no. Price" that ends them
dual_solutions.push_back(readVector(barRes));
// Or, if we read the duals, try to find the next header
res = waitFor(barRes, baron_objective, "", true);
Expand Down
Loading
Loading
0