Skip to content

Commit

Permalink
#218 Task 2: Hint to use 'writesol'
Browse files Browse the repository at this point in the history
  • Loading branch information
glebbelov committed Jul 27, 2023
1 parent 9a403ae commit f06e909
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
24 changes: 22 additions & 2 deletions include/mp/backend-std.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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() { }
};
Expand Down
4 changes: 4 additions & 0 deletions solvers/gurobi/CHANGES.gurobi.md
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit f06e909

Please sign in to comment.