From f06e909d34215e353c53d5735915887e1395a5a4 Mon Sep 17 00:00:00 2001 From: Gleb Belov Date: Thu, 27 Jul 2023 16:04:58 +1000 Subject: [PATCH] #218 Task 2: Hint to use 'writesol' --- include/mp/backend-std.h | 24 ++++++++++++++++++++++-- solvers/gurobi/CHANGES.gurobi.md | 4 ++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/include/mp/backend-std.h b/include/mp/backend-std.h index 752e43b6a..513482d5e 100644 --- a/include/mp/backend-std.h +++ b/include/mp/backend-std.h @@ -211,7 +211,7 @@ class StdBackend : SetupTimerAndInterrupter(); if (exportFileMode() > 0) - DoWriteProblem(export_file_name()); + ExportModel(export_file_name()); // exportFileMode == 2 -> do not solve, just export if (exportFileMode() != 2) @@ -766,7 +766,10 @@ class StdBackend : return 0; } std::string export_file_name() const { - std::string name = storedOptions_.export_file_.empty() ? storedOptions_.just_export_file_ : storedOptions_.export_file_; + std::string name + = storedOptions_.export_file_.empty() + ? storedOptions_.just_export_file_ + : storedOptions_.export_file_; if (((name.front() == '"') && (name.back() == '"')) || ((name.front() == '\'') && (name.back() == '\''))) return name.substr(1, name.length() - 2); @@ -944,6 +947,23 @@ class StdBackend : DoWriteSolution(storedOptions_.export_sol_); } + /// Write model + virtual void ExportModel(const std::string& filename) { + try { + DoWriteProblem(filename); + } catch (const std::exception& exc) { + auto msg + = std::string("Model export failed:\n") + + exc.what(); + if (IMPL_HAS_STD_FEATURE(WRITE_SOLUTION)) + msg += + "\n Note: to export solutions and results\n" + " in the solver's native formats,\n" + " use option 'tech:writesolution'"; + MP_RAISE(msg); + } + } + /// Virtual destructor virtual ~StdBackend() { } }; diff --git a/solvers/gurobi/CHANGES.gurobi.md b/solvers/gurobi/CHANGES.gurobi.md index d215c0c29..0704bb4bf 100644 --- a/solvers/gurobi/CHANGES.gurobi.md +++ b/solvers/gurobi/CHANGES.gurobi.md @@ -1,6 +1,10 @@ Summary of recent updates to gurobi for AMPL ============================================ +## unreleased +- Hint when 'writeprob' fails: use 'writesol' + + ## 20230726 - Fixed inequalities of integer expressions with non-integer constants, see test_int_non_int.mod.